Skip to content
Merged
Show file tree
Hide file tree
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 Aug 14, 2026
a2d67f0
fix(autofix): rebuild the deferred-findings upsert per review round 1
wenshao Aug 14, 2026
82ac7c4
fix(autofix): harden deferred-findings upsert per review round 2
wenshao Aug 14, 2026
04e8d7d
fix(autofix): close bash/transport channel gaps and failure-path gate…
wenshao Aug 14, 2026
3eaf8ca
fix(autofix): isolate deferred-upsert in a clean env -i child, drop t…
wenshao Aug 15, 2026
e958668
fix(autofix): strip LD_* before the env -i upsert child; tighten id g…
wenshao Aug 15, 2026
ccc1f42
fix(autofix): defuse mentions in deferred bullets, verify child liven…
wenshao Aug 15, 2026
b1106cc
fix(autofix): defer findings from all three feedback sources; carry t…
wenshao Aug 15, 2026
77244eb
perf(autofix): bound the deferred-issue lookup and name gh failure ca…
wenshao Aug 15, 2026
70e6ca3
test(autofix): close the pin gaps the round-8 mutation sweep found
wenshao Aug 15, 2026
aa44954
fix(autofix): close the upsert TOCTOU and the per-id deferral collaps…
wenshao Aug 15, 2026
45b7ad0
fix(autofix): keep a poisoned carry from sinking the round; clear the…
wenshao Aug 15, 2026
359b396
test(autofix): widen the denylist-sweep guards past their word-bounda…
wenshao Aug 15, 2026
d9386fc
fix(autofix): two -e-fatal paths, an escape-order dedupe hole, and a …
wenshao Aug 15, 2026
c2a9f06
fix(autofix): make the deferral identity lossless; keep the unmerged …
wenshao Aug 16, 2026
8cd6b05
refactor(autofix): remove the agent-writable paths the upsert depende…
wenshao Aug 16, 2026
c52913e
fix(autofix): reject multi-document deferral files; survive a base wi…
wenshao Aug 16, 2026
d2034aa
docs(autofix): retire the last stale rationale comments (R13-1)
wenshao Aug 16, 2026
c05e799
fix(autofix): strip BSD wc padding; let wrapper warnings stay annotat…
wenshao Aug 16, 2026
2258cfb
fix(autofix): un-truncate the sibling identity; align the carry prece…
wenshao Aug 16, 2026
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
119 changes: 119 additions & 0 deletions .github/scripts/upsert-deferred-issue.sh
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(.[];
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
(.id | type == "number" and . == floor and . > 0) and (.reason | type == "string")
Comment thread
wenshao marked this conversation as resolved.
Resolved
and ((.path // "?") | type == "string"))' "${FINDINGS}" > /dev/null 2>&1; then
Comment thread
wenshao marked this conversation as resolved.
Resolved
echo "::warning::deferred-findings.json is malformed; skipping the follow-up upsert"
exit 0
Comment thread
wenshao marked this conversation as resolved.
Resolved
fi
Comment thread
wenshao marked this conversation as resolved.
Resolved

MARKER="<!-- autofix-deferred pr=${PR} -->"
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
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" \
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
--paginate 2> /dev/null |
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
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
Comment thread
wenshao marked this conversation as resolved.
Resolved
fi

KNOWN_FILE="$(mktemp)"
trap 'rm -f "${KNOWN_FILE}"' EXIT
Comment thread
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
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
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" \
Comment thread
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}"
Comment thread
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")"
Comment thread
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
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
| ($known | split("\n")) as $klines
| unique_by(.id)
Comment thread
wenshao marked this conversation as resolved.
Resolved
| map(.id as $id
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
| select(($done | index($id)) | not)
Comment thread
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])")
Comment thread
wenshao marked this conversation as resolved.
Resolved
| .[]' "${FINDINGS}" 2> /dev/null |
sed 's/<!--/<!\\-\\-/g')" || NEW_LINES=''
Comment thread
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)"
Comment thread
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)"
Comment thread
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"
Comment thread
wenshao marked this conversation as resolved.
Resolved
fi
else
if gh api "repos/${REPO}/issues/${ISSUE_NUM}/comments" \
Comment thread
wenshao marked this conversation as resolved.
Resolved
-f body="${NEW_LINES}" > /dev/null 2>&1; then
Comment thread
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
Loading
Loading