Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions agents/review.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ NOTE: the Agent tool MUST ONLY be invoked with prompts read from
id. A closed id does not excuse the current code: a defect that is back is
a new finding with no id. Every other prior id is open and needs an
answer; a `reclassified` answer also re-emits the finding with the same id
at its new severity. The post-script verifies `dismissed_by_human` against
a resolved review thread from an eligible reviewer and records anything
else as open. Copy an open id onto the same finding; do not mint a new one
and do not derive one from the path or the text.
at its new severity. Before sandbox ingress, the host marks eligible
write-or-higher human-resolved threads `dismissed_by_human` only when a
trusted review-bot comment contains the exact finding-id stamp; raw thread
comments are not copied into the sandbox. The post-script independently
verifies any `dismissed_by_human` status produced during this run and
records anything else as open. Copy an open id onto the same finding; do
not mint a new one and do not derive one from the path or the text.
The file is empty on first review or when provenance, projection, category,
or path validation fails.

Expand Down
5 changes: 3 additions & 2 deletions docs/review.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ See [Customizing with AGENTS.md](https://fullsend.sh/docs/guides/user/customizin
| Variable | Description | Default | Valid values |
|----------|-------------|---------|--------------|
| `FULLSEND_FORGE` | Forge platform. Set automatically by the harness `forge.<platform>.env` section. | (set by harness) | `"github"`, `"gitlab"` |
| `FULLSEND_APP_SET` | GitHub App identity prefix used by the host pre-script to recognize the configured `<prefix>-review[bot]` author when verifying finding-id stamps in resolved threads. The workflow maps the repository variable explicitly; when unset, the organization-specific and shared review-bot identities remain recognized. This identifies the trusted bot record but does not replace resolver-role verification. | _(unset)_ | A configured GitHub App set prefix |
| `REVIEW_FINDING_SEVERITY_THRESHOLD` | Minimum severity for findings to include in the review. Findings below this level are filtered out at two independent stages (agent output and post-review processing) as defense-in-depth. Default is set in `harness/review.yaml` (`env.runner` and `env.sandbox`). | `low` | `info`, `low`, `medium`, `high`, `critical` |
| `REVIEW_SKIP_AUTHORS` | Comma-separated list of forge usernames to skip review for. When a PR/MR is opened by a user in this list, the review dispatch exits early without running the agent. Set in `env.runner` in your harness YAML (consumed by the pre-script on the runner). | _(empty — all PRs/MRs are reviewed)_ | Comma-separated logins, e.g. `app/renovate,app/dependabot` |
| `REVIEW_PROTECTED_PATHS` | Comma-separated list of path prefixes the review agent treats as protected. PRs that modify files under these paths cannot be approved by the agent — only a human can grant approval. Default is set in `harness/review.yaml` (`env.runner` and `env.sandbox`); an unset value is a misconfiguration (fail-closed). Set to an empty string to deliberately disable protected-path enforcement entirely. When set to a value that parses to no valid paths (e.g. stray or consecutive commas), the script aborts (fail-closed) as a likely misconfiguration. | See [`harness/review.yaml`](https://github.com/fullsend-ai/agents/blob/main/harness/review.yaml) | Comma-separated path prefixes (e.g. `.github/,deploy/,manifests/`) |
Expand Down Expand Up @@ -151,12 +152,12 @@ fails closed when `CI_SERVER_HOST` is not set.

The review agent follows the same pre-script / sandbox / post-script pipeline as the other agents.

1. **Pre-script** validates inputs and fetches PR metadata.
1. **Pre-script** validates inputs and fetches PR metadata. On a re-review, it also fetches current review-thread state, applies verified human dismissals to the prior-finding ledger, and discards the raw thread content before sandbox creation.
2. **Sandbox** — the agent runs the `pr-review` orchestrator skill. The orchestrator runs a security-triage pre-pass for large PRs, then dispatches the specialized dimension sub-agents in parallel (plus the risk-assessment sub-agent when enabled), each covering a distinct review dimension (correctness, security, intent & coherence, style & conventions, docs currency, and optionally cross-repo contracts). Sub-agents run concurrently and return structured findings. The orchestrator collects, deduplicates, and synthesizes findings across dimensions, runs PR-level checks (scope authorization, protected paths), and produces a structured JSON review result. The agent cannot push files, edit code, or push — it is strictly read-only.
3. **Validation loop** — the output is checked against a schema. The review harness runs a single iteration (see [Time budget](#time-budget)).
4. **Post-script** posts the review on the PR. On GitHub, it also resolves still-open review threads whose only comments are outdated inline comments authored by the review agent, so stale comments do not remain in the PR's unresolved-review state.

On re-review, the sandbox receives a validated `fullsend:review-findings-v2` projection containing `action`, severity, category, file, optional line, id, optional `actionable`, and an `{id, status}` disposition per prior id—not prior descriptions, remediation text, rationales, or evidence. A legacy marker without ids is assigned one before sandbox ingress. Resolved and human-dismissed findings stay in the projection with their anchor so they are recognised and not raised again. A null file retains PR-level category context without serving as a path or severity anchor. The pre-script continues to accept v1 markers for existing comments. Only GitHub `app-verified` re-reviews use file-backed records for remediation-candidate matching.
On re-review, the sandbox receives a validated `fullsend:review-findings-v2` projection containing `action`, severity, category, file, optional line, id, optional `actionable`, and an `{id, status}` disposition per prior id—not prior descriptions, remediation text, rationales, evidence, or review-thread bodies. Immediately before sandbox creation, the host fetches current thread state and marks eligible findings dismissed only when a verified write-or-higher human other than the PR author resolved a thread containing a trusted review-bot comment with the exact finding-id stamp. Unstamped thread comments stay open; path and line are not used as a fallback. A legacy marker without ids is assigned one before sandbox ingress. Resolved and human-dismissed findings stay in the projection with their anchor so they are recognised and not raised again. A null file retains PR-level category context without serving as a path or severity anchor. The pre-script continues to accept v1 markers for existing comments. Only GitHub `app-verified` re-reviews use file-backed records for remediation-candidate matching.

## Time budget

Expand Down
3 changes: 3 additions & 0 deletions eval/scripts/run-fullsend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ install -m 0600 /dev/null "$ENV_FILE"
# the same value ("low") so eval cases that don't set this var don't
# fail closed in post-review.sh's severity-validation block.
if [[ "$AGENT" == "review" ]]; then
# The production workflow supplies this computed per-repo value. Eval
# bypasses that workflow, so mirror its default while preserving overrides.
emit_env "FULLSEND_APP_SET" "${FULLSEND_APP_SET:-fullsend-ai}"
emit_env "REVIEW_FINDING_SEVERITY_THRESHOLD" "${REVIEW_FINDING_SEVERITY_THRESHOLD:-low}"
emit_env "PRIOR_REVIEW_FILE" "${PRIOR_REVIEW_FILE:-}"
emit_env "PRIOR_REVIEW_SHA" "${PRIOR_REVIEW_SHA:-}"
Expand Down
1 change: 1 addition & 0 deletions harness/review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ forge:
PR_URL: "${GITHUB_PR_URL}"
GH_TOKEN: "${GH_TOKEN}"
FULLSEND_FORGE: github
FULLSEND_APP_SET: "${FULLSEND_APP_SET}"
Comment thread
ralphbean marked this conversation as resolved.
Resolved
REVIEW_RISK_ASSESSMENT_ENABLED: "true"
REVIEW_RISK_VERDICT_THRESHOLD: "4"
sandbox:
Expand Down
128 changes: 0 additions & 128 deletions scripts/lib/github-review-ops.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -347,134 +347,6 @@ forge_resolve_outdated_review_threads() {

# --- Human dismissals ---

# Print a JSON array of resolved review threads that can stand as a human
# dismissal of a prior finding: resolved by a user who is not the PR author
# and holds write, maintain, or admin on the repository. Bots and logins
# that cannot be checked are never eligible. Each entry carries the thread
# path and lines, whether the review agent itself commented in it, and any
# finding ids stamped in the agent's comments (`finding:f_…` markers), so
# the caller can match a thread to a ledger entry. Prints [] when nothing qualifies or any lookup fails: a dismissal
# the runner cannot verify stays open.
forge_get_human_dismissals() {
local owner name query cursor has_next page response page_nodes nodes_json
local pr_author login role candidates eligible
local -a gh_args

owner="${REPO%%/*}"
name="${REPO##*/}"
cursor=""
has_next="true"
page=0
nodes_json="[]"

# The author exclusion is only as good as the author lookup: without a
# known author nothing can be verified.
pr_author="$(forge_get_pr_author)"
if [[ -z "${pr_author}" ]]; then
echo "::warning::Could not determine the PR author — human dismissals cannot be verified" >&2
echo '[]'
return 0
fi

query='query($owner: String!, $name: String!, $number: Int!, $cursor: String) {
repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
reviewThreads(first: 100, after: $cursor) {
pageInfo { hasNextPage endCursor }
nodes {
isResolved
path
line
originalLine
resolvedBy { login }
comments(first: 100) {
pageInfo { hasNextPage }
nodes { body viewerDidAuthor }
}
}
}
}
}
}'

while [[ "${has_next}" == "true" ]]; do
page=$((page + 1))
if [[ "${page}" -gt 20 ]]; then
echo "::warning::Review thread pagination hit page cap — remaining threads not checked for dismissals" >&2
break
fi

gh_args=(api graphql
-f owner="${owner}"
-f name="${name}"
-F number="${PR_NUMBER}"
-f query="${query}")
if [[ -n "${cursor}" ]]; then
gh_args+=(-f cursor="${cursor}")
fi

if ! response=$(GH_TOKEN="${REVIEW_TOKEN}" gh "${gh_args[@]}" 2>/dev/null); then
echo "::warning::Failed to fetch review threads — human dismissals cannot be verified" >&2
echo '[]'
return 0
fi
if echo "${response}" | jq -e '.errors | type == "array" and length > 0' >/dev/null 2>&1; then
echo "::warning::Review thread query returned errors — human dismissals cannot be verified" >&2
echo '[]'
return 0
fi
page_nodes=$(echo "${response}" | jq -c '.data.repository.pullRequest.reviewThreads.nodes // []' 2>/dev/null) || {
echo '[]'
return 0
}
nodes_json=$(jq -c --argjson page "${page_nodes}" '. + $page' <<< "${nodes_json}" 2>/dev/null) || {
echo '[]'
return 0
}
has_next=$(echo "${response}" | jq -r '.data.repository.pullRequest.reviewThreads.pageInfo.hasNextPage // false' 2>/dev/null) || has_next="false"
cursor=$(echo "${response}" | jq -r '.data.repository.pullRequest.reviewThreads.pageInfo.endCursor // empty' 2>/dev/null) || cursor=""
if [[ "${has_next}" == "true" && -z "${cursor}" ]]; then
break
fi
done

# Resolved threads with a known resolver and complete comment pages. A
# finding id stamp counts only in a comment this token authored (the
# review agent's own), never in a reply anyone else wrote.
candidates=$(jq -c '
[ .[]
| select(type == "object")
| select(.isResolved == true)
| select((.resolvedBy.login // "") != "")
| select((.comments.pageInfo.hasNextPage // false) == false)
| {
path: .path,
line: .line,
original_line: .originalLine,
resolved_by: .resolvedBy.login,
agent_authored: ([ (.comments.nodes // [])[] | select(.viewerDidAuthor == true) ] | length > 0),
ids: ([ (.comments.nodes // [])[] | select(.viewerDidAuthor == true) | .body // "" | scan("finding:(f_[A-Za-z0-9]+)") | .[0] ] | unique)
}
]' <<< "${nodes_json}" 2>/dev/null) || candidates="[]"

# Eligibility: not the PR author, a plain user login, and write or above
# on the repository. One permission lookup per distinct resolver.
eligible="[]"
while IFS= read -r login; do
[[ -z "${login}" ]] && continue
[[ "${login,,}" == "${pr_author,,}" ]] && continue
[[ "${login}" =~ ^[A-Za-z0-9-]+$ ]] || continue
role=$(GH_TOKEN="${REVIEW_TOKEN}" gh api "repos/${REPO}/collaborators/${login}/permission" \
--jq '.role_name' 2>/dev/null) || role=""
case "${role}" in
admin|maintain|write) eligible=$(jq -c --arg l "${login}" '. + [$l]' <<< "${eligible}") ;;
*) ;;
esac
done < <(jq -r '[.[].resolved_by] | unique | .[]' <<< "${candidates}" 2>/dev/null)

jq -c --argjson eligible "${eligible}" '[ .[] | select(.resolved_by as $l | $eligible | index($l) != null) ]' <<< "${candidates}" 2>/dev/null || echo '[]'
}

# --- Labels ---

forge_add_label() {
Expand Down
7 changes: 0 additions & 7 deletions scripts/lib/gitlab-review-ops.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,6 @@ forge_resolve_outdated_review_threads() {

# --- Labels ---

# Human dismissals need a resolved thread from a reviewer the runner can
# vouch for. That check is not implemented for GitLab discussions, so no
# dismissal is verified here and a dismissed_by_human disposition stays open.
forge_get_human_dismissals() {
echo '[]'
}

forge_add_label() {
local label="$1"
if ! _gitlab_api PUT "/projects/${REPO_ENCODED}/merge_requests/${PR_NUMBER}" \
Expand Down
104 changes: 104 additions & 0 deletions scripts/lib/review-ops.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,107 @@ case "${FULLSEND_FORGE:-}" in
exit 1
;;
esac

# Fetch resolved review threads once per stage and return rich, verified
# records for both pre-review ledger updates and post-review result checks.
# Comment bodies never leave the host: only authors and exact finding-ID
# stamps are retained in the returned records.
forge_get_human_dismissals() {
local pr_author response trusted_reviewers
local -a fetch_args

pr_author="$(forge_get_pr_author)"
if [[ -z "${pr_author}" ]]; then
echo "::warning::Could not determine the PR author — human dismissals cannot be verified" >&2
echo '[]'
return 0
fi

case "${FULLSEND_FORGE}" in
github)
local org app_set
org="${REPO%%/*}"
app_set="${FULLSEND_APP_SET:-}"
trusted_reviewers="$(jq -nc \
--arg org "${org}" \
--arg app_set "${app_set}" '
[
($org + "-review"), ($org + "-review[bot]"),
"fullsend-ai-review", "fullsend-ai-review[bot]",
(if $app_set == "" then empty else ($app_set + "-review"), ($app_set + "-review[bot]") end)
] | unique
')"
;;
gitlab)
local review_actor
review_actor="$(_gitlab_api GET "/user" 2>/dev/null | jq -r '.username // empty' 2>/dev/null)" || review_actor=""
if [[ -z "${review_actor}" ]]; then
echo "::warning::Could not determine the GitLab review bot — human dismissals cannot be verified" >&2
echo '[]'
return 0
fi
trusted_reviewers="$(jq -nc --arg actor "${review_actor}" '[$actor]')"
;;
esac

fetch_args=(fetch-review-threads --forge "${FULLSEND_FORGE}" --repo "${REPO}" --pr "${PR_NUMBER}")
Comment thread
ralphbean marked this conversation as resolved.
Resolved
if [[ "${FULLSEND_FORGE}" == "gitlab" && -n "${CI_SERVER_URL:-}" ]]; then
fetch_args+=(--base-url "${CI_SERVER_URL}")
fi
if ! response="$(GH_TOKEN="${REVIEW_TOKEN:-${GH_TOKEN:-}}" \
GITLAB_TOKEN="${REVIEW_TOKEN:-${GITLAB_TOKEN:-}}" \
fullsend "${fetch_args[@]}" 2>/dev/null)"; then
echo "::warning::Failed to fetch review threads — human dismissals cannot be verified" >&2
echo '[]'
return 0
fi

if ! jq -e 'type == "object" and (.threads | type == "array") and (.truncated == false)' \
<<< "${response}" >/dev/null 2>&1; then
echo "::warning::Review thread fetch was invalid or truncated — human dismissals cannot be verified" >&2
echo '[]'
return 0
fi

jq -c --arg author "${pr_author}" --arg forge "${FULLSEND_FORGE}" --argjson trusted "${trusted_reviewers}" '
[ .threads[]
| select(type == "object")
| select(.is_resolved == true)
| select(.resolved_by_type == "User")
| select(.resolved_by_role_verified == true)
| select(.resolved_by_role | IN("write", "maintain", "admin"))
| select((.resolved_by | ascii_downcase) != ($author | ascii_downcase))
| select(.comments_truncated == false)
| . as $thread
| [ $thread.comments[]?
| {
author: (.author // ""),
author_type: (.author_type // ""),
finding_ids: [(.body // "" | scan("<!--[[:space:]]+finding:(f_[A-Za-z0-9]+)[[:space:]]+-->") | .[0])] | unique
Comment thread
ralphbean marked this conversation as resolved.
Resolved
}
] as $comments
| [ $comments[]
| select(
if $forge == "github" then
(.author_type == "Bot") and
(.author as $login | ($trusted | map(ascii_downcase) | index($login | ascii_downcase)) != null)
else
(.author as $login | ($trusted | map(ascii_downcase) | index($login | ascii_downcase)) != null)
end
)
] as $trusted_comments
| select(($trusted_comments | length) > 0)
| {
path: $thread.path,
line: $thread.line,
original_line: $thread.original_line,
resolved_by: $thread.resolved_by,
resolved_by_type: $thread.resolved_by_type,
resolved_by_role: $thread.resolved_by_role,
resolved_by_role_verified: $thread.resolved_by_role_verified,
comment_authors: ($comments | map({author, author_type})),
finding_ids: ([$trusted_comments[].finding_ids[]] | unique)
}
]
' <<< "${response}" 2>/dev/null || echo '[]'
}
Loading
Loading