Repository navigation
feat(autofix): defer verified out-of-footprint findings to a surviving follow-up queue #9189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
51558b2
feat(autofix): route verified out-of-footprint findings to a survivin…
wenshao a2d67f0
fix(autofix): rebuild the deferred-findings upsert per review round 1
wenshao 82ac7c4
fix(autofix): harden deferred-findings upsert per review round 2
wenshao 04e8d7d
fix(autofix): close bash/transport channel gaps and failure-path gate…
wenshao 3eaf8ca
fix(autofix): isolate deferred-upsert in a clean env -i child, drop t…
wenshao e958668
fix(autofix): strip LD_* before the env -i upsert child; tighten id g…
wenshao ccc1f42
fix(autofix): defuse mentions in deferred bullets, verify child liven…
wenshao b1106cc
fix(autofix): defer findings from all three feedback sources; carry t…
wenshao 77244eb
perf(autofix): bound the deferred-issue lookup and name gh failure ca…
wenshao 70e6ca3
test(autofix): close the pin gaps the round-8 mutation sweep found
wenshao aa44954
fix(autofix): close the upsert TOCTOU and the per-id deferral collaps…
wenshao 45b7ad0
fix(autofix): keep a poisoned carry from sinking the round; clear the…
wenshao 359b396
test(autofix): widen the denylist-sweep guards past their word-bounda…
wenshao d9386fc
fix(autofix): two -e-fatal paths, an escape-order dedupe hole, and a …
wenshao c2a9f06
fix(autofix): make the deferral identity lossless; keep the unmerged …
wenshao 8cd6b05
refactor(autofix): remove the agent-writable paths the upsert depende…
wenshao c52913e
fix(autofix): reject multi-document deferral files; survive a base wi…
wenshao d2034aa
docs(autofix): retire the last stale rationale comments (R13-1)
wenshao c05e799
fix(autofix): strip BSD wc padding; let wrapper warnings stay annotat…
wenshao 2258cfb
fix(autofix): un-truncate the sibling identity; align the carry prece…
wenshao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| #!/usr/bin/env bash | ||
| set -uo pipefail | ||
|
|
||
| # Upserts the round's verified-but-out-of-footprint findings into one | ||
| # per-PR tracking issue. Invoked from the review-address report AND | ||
| # failure/handoff paths (a failed round must not lose verified findings), | ||
| # with WORKDIR/PR/REPO/AUTOFIX_BOT in env and the PAT on gh. Best-effort | ||
| # throughout: every failure path warns and exits 0 — persistence must | ||
| # never fail a round — but success is only LOGGED when the write call | ||
| # actually succeeded. | ||
| # | ||
| # Durability design: the tracking issue's BODY is written once at | ||
| # creation; every later round appends by POSTING A COMMENT — atomic and | ||
| # append-only, so no read-modify-write can race a maintainer's edits and | ||
| # a lost GET can never be mistaken for an empty history. Deduplication | ||
| # reads the body plus the bot's own comments, anchored to the bullet form | ||
| # "- rc:<id> " at line start (free-text mentions of an id do not count). | ||
|
|
||
| FINDINGS="${WORKDIR}/deferred-findings.json" | ||
| [[ -s "${FINDINGS}" ]] || exit 0 | ||
|
|
||
| # Shape gate: non-empty array; id numeric; reason string; path, when | ||
| # present, a string (one malformed sibling must not drop the batch — it | ||
| # fails the whole file loudly instead of being silently formatted away). | ||
| if ! jq -e 'type == "array" and length > 0 and all(.[]; | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| (.id | type == "number" and . == floor and . > 0) and (.reason | type == "string") | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| and ((.path // "?") | type == "string"))' "${FINDINGS}" > /dev/null 2>&1; then | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| echo "::warning::deferred-findings.json is malformed; skipping the follow-up upsert" | ||
| exit 0 | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| fi | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
|
|
||
| MARKER="<!-- autofix-deferred pr=${PR} -->" | ||
|
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
|
||
|
|
||
| # Locate the tracking issue with structured filtering: never a pull | ||
| # request, marker matched against the real body (no line-joining), first | ||
| # match wins. A lookup failure is a skip, not "no issue" — creating a | ||
| # duplicate is worse than deferring persistence one round. | ||
| if ! ISSUE_NUM="$(gh api "repos/${REPO}/issues?state=all&creator=${AUTOFIX_BOT}&per_page=100" \ | ||
|
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
|
||
| --paginate 2> /dev/null | | ||
|
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
|
||
| jq -rs --arg m "${MARKER}" ' | ||
| add // [] | map(select((.pull_request | not) | ||
| and ((.body // "") | contains($m)))) | (.[0].number // "") | tostring')"; then | ||
| echo "::warning::deferred-findings lookup failed; skipping the follow-up upsert this round" | ||
| exit 0 | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| fi | ||
|
|
||
| KNOWN_FILE="$(mktemp)" | ||
| trap 'rm -f "${KNOWN_FILE}"' EXIT | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| if [[ -n "${ISSUE_NUM}" && "${ISSUE_NUM}" != 'null' ]]; then | ||
| # Known-id corpus = issue body + every comment. Any fetch failure skips | ||
| # the round: treating it as empty would re-append history (or, under | ||
| # the old PATCH design, erase it). | ||
| if ! BODY_TEXT="$(gh api "repos/${REPO}/issues/${ISSUE_NUM}" --jq '.body // ""' 2> /dev/null)"; then | ||
|
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
|
||
| echo "::warning::could not read deferred-findings issue #${ISSUE_NUM}; skipping this round" | ||
| exit 0 | ||
| fi | ||
| # Bot-authored comments only: the tracking issue is public, and an | ||
| # arbitrary commenter posting a line-start "- rc:<id> " bullet must not | ||
| # be able to permanently suppress a deferred finding from the corpus. | ||
| if ! COMMENT_TEXT="$(gh api "repos/${REPO}/issues/${ISSUE_NUM}/comments?per_page=100" \ | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| --paginate 2> /dev/null | jq -rs --arg bot "${AUTOFIX_BOT}" \ | ||
| 'add // [] | map(select((.user.login // "") == $bot) | .body // "") | join("\n")')"; then | ||
| echo "::warning::could not read deferred-findings comments on #${ISSUE_NUM}; skipping this round" | ||
| exit 0 | ||
| fi | ||
| printf '%s\n%s' "${BODY_TEXT}" "${COMMENT_TEXT}" > "${KNOWN_FILE}" | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| fi | ||
|
|
||
| # Build this round's lines: intra-batch dedupe by id, drop ids the round | ||
| # RESOLVED in code (a finding cannot be both implemented and outstanding), | ||
| # drop ids already tracked (line-anchored), sanitize path and flatten | ||
| # reason (both agent/branch-influenced), cap the batch. The marker | ||
| # neutralization matches every other agent-derived publish site. | ||
| RESOLVED_RAW='' | ||
| [[ -f "${WORKDIR}/resolved-comments.txt" ]] && RESOLVED_RAW="$(cat "${WORKDIR}/resolved-comments.txt")" | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| # --rawfile, not --arg: a large corpus in one argv element hits Linux | ||
| # MAX_ARG_STRLEN and the exec failure would be swallowed into a silent | ||
| # "nothing new" exit. | ||
| NEW_LINES="$(jq -r --rawfile known "${KNOWN_FILE}" --arg resolved "${RESOLVED_RAW}" ' | ||
| ($resolved | split("\n") | ||
| | map(sub("^rc:"; "") | sub("\r$"; "") | ||
| | select(test("^[0-9]+$")) | tonumber)) as $done | ||
|
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
|
||
| | ($known | split("\n")) as $klines | ||
| | unique_by(.id) | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| | map(.id as $id | ||
|
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
|
||
| | select(($done | index($id)) | not) | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| | select(($klines | any(test("^- rc:" + ($id | tostring) + " "))) | not) | ||
| | "- rc:\($id) `\(.path // "?" | gsub("[^A-Za-z0-9._/ -]"; "?") | .[0:200])`: \(.reason | gsub("[\r\n]+"; " ") | .[0:500])") | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| | .[]' "${FINDINGS}" 2> /dev/null | | ||
| sed 's/<!--/<!\\-\\-/g')" || NEW_LINES='' | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| [[ -n "${NEW_LINES}" ]] || exit 0 | ||
| # Cap in bash, loudly: clipped items are never retried (the workdir is | ||
| # deleted at job end), so a silent clip would read as full persistence. | ||
| TOTAL_NEW="$(printf '%s\n' "${NEW_LINES}" | wc -l)" | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| if (( TOTAL_NEW > 20 )); then | ||
| NEW_LINES="$(printf '%s\n' "${NEW_LINES}" | head -n 20)" | ||
| echo "::warning::deferred-findings cap: persisting 20 of ${TOTAL_NEW} new findings; the remaining $(( TOTAL_NEW - 20 )) are NOT persisted (re-defer them in a later round)" | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| KEPT=20 | ||
| else | ||
| KEPT="${TOTAL_NEW}" | ||
| fi | ||
|
|
||
| if [[ -z "${ISSUE_NUM}" || "${ISSUE_NUM}" == 'null' ]]; then | ||
| BODY="${MARKER}"$'\n\n'"Verified review findings from PR #${PR} whose fixes lie outside that PR's footprint, deferred by the autofix loop for follow-up. A maintainer can turn any item into its own issue/PR (or apply the ready-for-agent flow) — nothing here is scheduled automatically."$'\n\n'"${NEW_LINES}" | ||
| if NUM="$(gh api "repos/${REPO}/issues" \ | ||
| -f title="Deferred review findings from PR #${PR}" \ | ||
| -f body="${BODY}" --jq '.number' 2> /dev/null)"; then | ||
| echo "🗂 deferred findings tracked in new issue #${NUM} (${KEPT} of ${TOTAL_NEW} new)" | ||
| else | ||
| echo "::warning::could not create the deferred-findings issue for PR #${PR}; findings NOT persisted this round" | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| fi | ||
| else | ||
| if gh api "repos/${REPO}/issues/${ISSUE_NUM}/comments" \ | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| -f body="${NEW_LINES}" > /dev/null 2>&1; then | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| echo "🗂 deferred findings appended to issue #${ISSUE_NUM} (${KEPT} of ${TOTAL_NEW} new)" | ||
| else | ||
| echo "::warning::could not append to deferred-findings issue #${ISSUE_NUM}; findings NOT persisted this round" | ||
| fi | ||
| fi | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.