Skip to content
13 changes: 13 additions & 0 deletions agents/review.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ findings equally. If filtering removes all findings from a
`comment`. The severity threshold is absolute — it applies to all
findings regardless of the `actionable` flag.

On a verified re-review with a prior findings ledger, newly reported
`info`/`low` findings must not produce a `request-changes` verdict or start the
fix agent. They may remain visible in the posted review. Prior high/critical
findings always remain blocking, regardless of the configured posting
threshold. A prior medium finding blocks when it was explicitly marked
actionable, or when its actionable state is absent and the prior review was
`request-changes`; an explicitly non-actionable medium remains advisory. A
legacy projection with unknown prior action is held for a human and is not
promoted into an automatic fix loop. Carried actionable findings at or above
the configured threshold remain blocking. A prior `reject` verdict is also
held for human review and is never automatically promoted. This does not
change the global severity threshold or treat a missing finding as resolved.

## Identity

You **either**:
Expand Down
15 changes: 14 additions & 1 deletion docs/review.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ verdict is downgraded to a comment (applying the `requires-manual-review` label)
The severity threshold is absolute — it applies to all findings regardless of
the `actionable` flag, respecting the user's configured threshold throughout.

On a verified re-review with a prior findings ledger, newly reported
`info`/`low` findings do not block the review or start a fix run. They may
remain visible in the posted review. Prior high/critical findings always
remain blocking, regardless of the configured posting threshold. A prior
medium finding blocks when it was explicitly marked actionable, or when its
actionable state is absent and the prior review was `request-changes`; an
explicitly non-actionable medium remains advisory. A legacy projection with
unknown prior action is held for a human and is not promoted into an
automatic fix loop. Carried actionable findings at or above the configured
threshold remain blocking. A prior `reject` verdict is also held for human
review and is never automatically promoted. This does not change the global
severity threshold or treat a missing finding as resolved.

### GitLab host validation

`gitlab-review-ops.lib.sh` validates `GITLAB_HOST` against `CI_SERVER_HOST`,
Expand All @@ -143,7 +156,7 @@ The review agent follows the same pre-script / sandbox / post-script pipeline as
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 severity, category, file, optional line, id, 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, 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.

## Time budget

Expand Down
95 changes: 95 additions & 0 deletions scripts/lib/github-review-ops.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,101 @@ forge_get_recent_redispatch_comments() {
| length'
}

# Return a JSON object mapping finding ids to the review-comment URL of the
# review agent's original inline comment. This is best-effort context for
# carried blockers; the ledger itself remains metadata-only. Only comments
# authored by the current viewer are considered, so a human cannot forge a
# finding link by mentioning an id in a reply.
forge_get_finding_comment_links() {
local owner name query cursor has_next page response page_nodes nodes_json links
local -a gh_args

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

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 {
comments(first: 100) {
pageInfo { hasNextPage }
nodes { body viewerDidAuthor url }
}
}
}
}
}
}'

while [[ "${has_next}" == "true" ]]; do
page=$((page + 1))
if [[ "${page}" -gt 20 ]]; then
echo "::warning::Review thread pagination hit page cap — finding links may be incomplete" >&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 — blocking finding links unavailable" >&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 — blocking finding links unavailable" >&2
echo '{}'
return 0
fi

page_nodes=$(echo "${response}" | jq -c '.data.repository.pullRequest.reviewThreads.nodes // []' 2>/dev/null) || {
echo "::warning::Failed to parse review threads — blocking finding links unavailable" >&2
echo '{}'
return 0
}
nodes_json=$(jq -c --argjson page "${page_nodes}" '. + $page' <<< "${nodes_json}" 2>/dev/null) || {
echo "::warning::Failed to merge review thread pages — blocking finding links unavailable" >&2
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
echo "::warning::Review thread page missing cursor — blocking finding links may be incomplete" >&2
break
fi
done

links=$(jq -c --arg base "${PR_URL}" '
[ .[]
| (.comments.nodes // [])[]
| select(.viewerDidAuthor == true)
| . as $comment
| (($comment.body // "") | scan("finding:(f_[A-Za-z0-9]+)") | .[0]) as $id
| select(($id | type) == "string")
| select(($comment.url // "") | startswith($base + "#discussion_r"))
| select(($comment.url // "") | test("#discussion_r[0-9]+$"))
| {id: $id, url: $comment.url}
]
| reduce .[] as $match ({}; .[$match.id] //= $match.url)
' <<< "${nodes_json}" 2>/dev/null) || links='{}'
jq -e 'type == "object"' <<< "${links}" >/dev/null 2>&1 || links='{}'
printf '%s\n' "${links}"
}

# --- Review threads ---

# Select GitHub review-thread node IDs that are safe to auto-resolve.
Expand Down
6 changes: 6 additions & 0 deletions scripts/lib/gitlab-review-ops.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ forge_get_recent_redispatch_comments() {
| length'
}

# GitLab notes do not expose the same GitHub review-comment URL shape. Keep
# the caller forge-neutral and let it fall back to the finding context.
forge_get_finding_comment_links() {
echo '{}'
}

# GitHub-only: GitLab discussions have no isOutdated equivalent in this
# issue's scope. No-op so post-review can call this unconditionally.
forge_resolve_outdated_review_threads() {
Expand Down
Loading
Loading