Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
83 changes: 77 additions & 6 deletions .github/scripts/autofix-push-and-report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,52 @@ fi
# replies — silence in still-open threads was a no-op-only gap.
resolve_and_reply_threads() {
CAN_RESOLVE_THREADS='false'
# Round-report observability (#10106): a guard refusing round after
# round reads, on the PR, exactly like resolution working — 0/90 on
# #9729 stayed invisible for days. Each refusing guard records its
# name, and the counters feed one host-authored line in the round
# report; the ::warning:: lines below reach only the run log.
RESOLUTION_GUARD=''
RESOLUTION_SELECTED_N=0
CONFIRMED_RESOLVED_N=0
if [[ -s "${WORKDIR}/resolved-comments.txt" ]]; then
# Same id grammar as the resolve loop below: optional rc: prefix,
# optional trailing CR, digits only.
RESOLUTION_SELECTED_N="$(sed 's/\r$//; s/^rc://' "${WORKDIR}/resolved-comments.txt" | grep -cE '^[0-9]+$' || true)"
LOCAL_PUSHED_HEAD="$(git rev-parse HEAD)"
if [[ "${PUSH_RACE_MERGED}" == 'true' ]]; then
RESOLUTION_GUARD='salvage merge'
echo "::warning::skipping review-thread resolution because the pushed head includes commits merged after deterministic verification"
elif [[ -z "${VERIFIED_HEAD}" || "${LOCAL_PUSHED_HEAD}" != "${VERIFIED_HEAD}" ]]; then
elif [[ -z "${VERIFIED_HEAD}" ]]; then
RESOLUTION_GUARD='missing verified_head'
echo "::warning::skipping review-thread resolution because this round recorded no deterministically verified commit"
elif [[ "${LOCAL_PUSHED_HEAD}" != "${VERIFIED_HEAD}" ]]; then
RESOLUTION_GUARD='verified_head mismatch'
echo "::warning::skipping review-thread resolution because the pushed head is not the exact deterministically verified commit"
elif LIVE_PR_HEAD="$(gh pr view "${PR}" --repo "${REPO}" --json headRefOid --jq '.headRefOid // ""' 2> /dev/null)" &&
[[ -n "${LIVE_PR_HEAD}" && "${LIVE_PR_HEAD}" == "${VERIFIED_HEAD}" ]]; then
CAN_RESOLVE_THREADS='true'
else
echo "::warning::skipping review-thread resolution because the live PR head could not be proven equal to the deterministically verified commit"
# The PR read model is eventually consistent: a headRefOid read
# seconds after this round's OWN push routinely still returns the
# previous head — on #9729 every pushed round tripped this guard
# that way, silently, for days (#10106). Give propagation a
# bounded window before declaring drift; the per-mutation guards
# below stay single-shot, because once the head was observed
# equal a later mismatch means it actually moved.
# The delay knob exists for tests; anything but a single digit
# (e.g. a GITHUB_ENV plant stalling this PAT-bearing step) falls
# back to the default.
[[ "${LIVE_HEAD_RETRY_DELAY:-}" =~ ^[0-9]$ ]] || LIVE_HEAD_RETRY_DELAY=5
for live_head_attempt in 1 2 3 4 5; do
LIVE_PR_HEAD="$(gh pr view "${PR}" --repo "${REPO}" --json headRefOid --jq '.headRefOid // ""' 2> /dev/null)" || LIVE_PR_HEAD=''
if [[ -n "${LIVE_PR_HEAD}" && "${LIVE_PR_HEAD}" == "${VERIFIED_HEAD}" ]]; then
CAN_RESOLVE_THREADS='true'
break
fi
[[ "${live_head_attempt}" == 5 ]] || sleep "${LIVE_HEAD_RETRY_DELAY}"
done
if [[ "${CAN_RESOLVE_THREADS}" != 'true' ]]; then
RESOLUTION_GUARD='live-head drift'
echo "::warning::skipping review-thread resolution because the live PR head could not be proven equal to the deterministically verified commit"
fi
fi
fi
# Resolve the review threads whose findings the agent actually
Expand Down Expand Up @@ -170,7 +205,6 @@ resolve_and_reply_threads() {
fi
fi
if [[ "${CAN_RESOLVE_THREADS}" == 'true' ]]; then
CONFIRMED_RESOLVED_N=0
read_thread_guard() {
gh api graphql -f owner="${REPO%%/*}" -f name="${REPO##*/}" -F pr="${PR}" -f threadId="${1}" -f query='
query($owner:String!,$name:String!,$pr:Int!,$threadId:ID!){
Expand All @@ -192,12 +226,14 @@ resolve_and_reply_threads() {
fi
if ! IFS=$'\t' read -r LIVE_PR_HEAD THREAD_IS_RESOLVED < <(read_thread_guard "${thread_id}" 2> /dev/null) ||
[[ -z "${LIVE_PR_HEAD}" || "${LIVE_PR_HEAD}" != "${VERIFIED_HEAD}" ]]; then
RESOLUTION_GUARD='live-head drift'
echo "::warning::stopping review-thread resolution because the live PR head moved before resolving comment ${rc_id}"
break
elif [[ "${THREAD_IS_RESOLVED}" == 'true' ]]; then
echo "::warning::comment ${rc_id} was resolved by another actor before this round could resolve it"
continue
elif [[ "${THREAD_IS_RESOLVED}" != 'false' ]]; then
RESOLUTION_GUARD='thread state unproven'
echo "::warning::stopping review-thread resolution because the state of comment ${rc_id} could not be proven"
break
fi
Expand All @@ -220,12 +256,39 @@ resolve_and_reply_threads() {
elif [[ "${POST_GUARD_OK}" == 'true' && "${LIVE_PR_HEAD}" == "${VERIFIED_HEAD}" && "${THREAD_IS_RESOLVED}" == 'false' && "${RESOLVE_SUCCEEDED}" == 'false' ]]; then
echo "::warning::could not resolve the review thread for comment ${rc_id}"
else
RESOLUTION_GUARD='mutation post-check ambiguous'
echo "::warning::the live PR head or thread state could not be proven after resolving comment ${rc_id}; stopping review-thread resolution"
break
fi
done < "${WORKDIR}/resolved-comments.txt"
echo "🧵 confirmed ${CONFIRMED_RESOLVED_N} selected review thread(s) resolved while the verified head remained live"
fi
# One host-authored line for the round report (#10106): name the
# refusing guard and count the threads left behind. All text is fixed
# host strings plus counts — nothing agent-controlled.
RESOLUTION_NOTE=''
if [[ "${RESOLUTION_SELECTED_N}" -gt 0 ]]; then
RESOLUTION_LEFT_N=$(( RESOLUTION_SELECTED_N - CONFIRMED_RESOLVED_N ))
if [[ -n "${RESOLUTION_GUARD}" ]]; then
RESOLUTION_PHASE='skipped'
RESOLUTION_PHASE_ZH='被跳过'
if [[ "${CAN_RESOLVE_THREADS}" == 'true' ]]; then
RESOLUTION_PHASE='stopped early'
RESOLUTION_PHASE_ZH='提前中止'
fi
RESOLUTION_NOTE="⚠️ Review-thread resolution ${RESOLUTION_PHASE} — guard: \`${RESOLUTION_GUARD}\`; resolved ${CONFIRMED_RESOLVED_N} of ${RESOLUTION_SELECTED_N} selected thread(s), ${RESOLUTION_LEFT_N} left for a later round. · 评审线程关闭${RESOLUTION_PHASE_ZH}——守卫:\`${RESOLUTION_GUARD}\`;选中 ${RESOLUTION_SELECTED_N} 条,本轮关闭 ${CONFIRMED_RESOLVED_N} 条,其余 ${RESOLUTION_LEFT_N} 条留待后续轮次。"
elif [[ "${RESOLUTION_LEFT_N}" -gt 0 ]]; then
RESOLUTION_DETAIL='details in the run log'
RESOLUTION_DETAIL_ZH='详见运行日志'
if [[ "${THREADS_FETCH_OK:-true}" != 'true' ]]; then
RESOLUTION_DETAIL='thread fetch incomplete; details in the run log'
RESOLUTION_DETAIL_ZH='线程拉取不完整,详见运行日志'
fi
RESOLUTION_NOTE="🧵 Resolved ${CONFIRMED_RESOLVED_N} of ${RESOLUTION_SELECTED_N} selected review thread(s); ${RESOLUTION_LEFT_N} not resolved by this round (${RESOLUTION_DETAIL}). · 选中评审线程 ${RESOLUTION_SELECTED_N} 条,已关闭 ${CONFIRMED_RESOLVED_N} 条;其余 ${RESOLUTION_LEFT_N} 条本轮未关闭(${RESOLUTION_DETAIL_ZH})。"
else
RESOLUTION_NOTE="🧵 Resolved all ${RESOLUTION_SELECTED_N} selected review thread(s). · 已关闭全部选中的 ${RESOLUTION_SELECTED_N} 条评审线程。"
fi
fi
# The mirror of the resolve above: a finding the agent did NOT
# resolve keeps its thread open, and this answers it IN that thread.
# Full rationale → qwen-autofix.md#af-132
Expand Down Expand Up @@ -484,6 +547,10 @@ if [[ "${OUTCOME}" == "fixed" ]]; then
echo
echo "⚠️ The branch received new commits while this round ran; they were merged into this push, but this round's verification predates that merge — re-check anything that landed mid-run. · 本轮运行期间分支收到了新的提交;本次推送已将其合并,但本轮验证在合并之前完成——请复查运行期间落地的改动。"
fi
if [[ -n "${RESOLUTION_NOTE}" ]]; then
echo
echo "${RESOLUTION_NOTE}"
fi
echo
echo "Re-review when you have a moment. After round ${MAX_ROUNDS} this bot stops and leaves the PR for a human. · 有空请复审;第 ${MAX_ROUNDS} 轮后本 bot 停止并将 PR 交给人工。"
echo
Expand Down Expand Up @@ -524,6 +591,10 @@ else
fi
echo
echo "Base-conflict check · 基分支冲突检查: $([[ "${CONFLICT}" == "true" ]] && echo 'conflicts with main (no review fix needed, but a rebase/merge is required before merge). · 与 main 有冲突(无需评审修复,但合并前需 rebase/merge)。' || echo 'no conflict with main. · 与 main 无冲突。')"
if [[ -n "${RESOLUTION_NOTE}" ]]; then
echo
echo "${RESOLUTION_NOTE}"
fi
echo
echo "---"
echo "🧠 Handled by **Qwen Code** · model/模型 \`${MODEL_DISPLAY}\`"
Expand Down
5 changes: 5 additions & 0 deletions docs/design/autofix-resolve-fixed-review-threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ If a pre-mutation condition is unknown or false, or a post-mutation condition is

The verified code push and normal round report still succeed. Replies for findings deliberately left open may continue after a successful push because they do not assert that a thread is fixed.

### Round-report observability

Fail closed must not mean fail silent (issue #10106: 0 of 90 threads resolved on PR #9729 across ~16 rounds, with every refusal visible only as run-log warnings). Every guard that refuses records a stable name — `salvage merge`, `missing verified_head`, `verified_head mismatch`, `live-head drift` for the up-front skips; `live-head drift`, `thread state unproven`, `mutation post-check ambiguous` for a mid-list stop — and the round report posted on the PR carries one host-authored line naming that guard and counting the selected, resolved, and left-behind threads. Rounds with no refusing guard report the positive count (including per-thread misses and an incomplete thread fetch), so a healthy mechanism is visible by the same line whose numbers go wrong when it dies. The line is composed exclusively from fixed host strings and counters; no agent-authored content enters it.

## Design decisions

- **Fail closed for resolution:** an unresolved thread is recoverable; an incorrectly resolved thread can hide a real defect.
- **Skip resolution after race merge:** rerunning the full deterministic gate inside the PAT-bearing publish step would duplicate expensive logic and run branch-controlled scripts with credentials in scope. A later review round can safely resolve the thread.
- **Query live PR state immediately before mutation:** workflow concurrency cannot prevent direct contributor pushes.
- **Bounded wait for the initial live-head equality:** the PR read model is eventually consistent, and a `headRefOid` read seconds after this round's own push routinely still returns the previous head — on PR #9729 every pushed round declared drift on that single stale read and silently skipped (issue #10106). The initial equality check retries briefly before declaring drift. The per-mutation guards stay single-shot: once the head has been observed equal, a later mismatch means it actually moved.
- **Keep the existing model disposition contract:** semantic judgment remains with the agent, while exact commit identity is enforced deterministically by the host.
- **Do not add general CLI/core code:** this is Autofix workflow orchestration, not a reusable Qwen Code runtime feature.

Expand Down
133 changes: 133 additions & 0 deletions scripts/tests/qwen-autofix-workflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17562,6 +17562,7 @@ exit 1
VERIFIED_HEAD: localHead,
LIVE_HEAD: localHead,
PUSH_RACE_MERGED: 'false',
LIVE_HEAD_RETRY_DELAY: '0',
...env,
},
encoding: 'utf8',
Expand Down Expand Up @@ -17620,6 +17621,33 @@ exit 1
'confirmed 1 selected review thread(s) resolved while the verified head remained live',
);

// #10106 root cause on #9729: the PR read model is eventually
// consistent, so a headRefOid read seconds after this round's OWN push
// routinely still returns the previous head — every pushed round
// declared drift on that one stale read and silently skipped. The
// initial equality check waits out propagation instead…
const lagThenConverge = runResolve({
LIVE_HEAD_SEQUENCE: `stale-pre-push-head,${localHead}`,
});
expect(lagThenConverge.status).toBe(0);
expect(lagThenConverge.resolved).toEqual(['resolve:T_open_1']);
expect(lagThenConverge.out).not.toContain(
'skipping review-thread resolution',
);
// …and a head that never converges still skips, after exhausting the
// whole window rather than a single read.
const neverConverges = runResolve({ LIVE_HEAD: 'stale-pre-push-head' });
expect(neverConverges.status).toBe(0);
expect(neverConverges.resolved).toEqual([]);
expect(neverConverges.out).toContain('skipping review-thread resolution');
expect(readFileSync(headReadCount, 'utf8')).toBe('5');
// The retry delay is a test knob on a PAT-bearing step: anything but
// a single digit (a GITHUB_ENV plant stalling the step to the job
// timeout) must fall back to the default.
expect(block).toContain(
'[[ "${LIVE_HEAD_RETRY_DELAY:-}" =~ ^[0-9]$ ]] || LIVE_HEAD_RETRY_DELAY=5',
);

const movedBeforeMutation = runResolve({
LIVE_HEAD_SEQUENCE: `${localHead},new-contributor-head`,
});
Expand Down Expand Up @@ -17919,6 +17947,111 @@ exit 1
'confirmed 1 selected review thread(s) resolved',
);
}

// #10106: the ::warning:: lines above reach only the run log — on the
// PR, a guard refusing round after round reads exactly like resolution
// working (0/90 threads on #9729, silent for days). The block composes
// one host-authored RESOLUTION_NOTE naming the refusing guard and
// counting the threads left behind, and BOTH report arms (pushed and
// no-op) embed it in the round report.
expect(
pushAndReportScript.match(/echo "\$\{RESOLUTION_NOTE\}"/g) ?? [],
).toHaveLength(2);
const noteEnd = lines.findIndex((l) =>
l.includes('The mirror of the resolve above'),
);
expect(noteEnd).toBeGreaterThan(j);
const noteBlock = [
...lines.slice(i, noteEnd),
'printf "NOTE<%s>" "${RESOLUTION_NOTE}"',
].join('\n');
const runNote = (env = {}) => {
writeFileSync(resolvedLog, '');
writeFileSync(headReadCount, '0');
writeFileSync(threadStateFile, '');
const result = spawnSync(
'bash',
['-c', `set -euo pipefail\n${noteBlock}`],
{
env: {
...process.env,
PATH: `${bin}:${process.env.PATH}`,
WORKDIR: dir,
REPO: 'QwenLM/qwen-code',
PR: '7308',
RESOLVED_LOG: resolvedLog,
HEAD_READ_COUNT: headReadCount,
THREAD_STATE_FILE: threadStateFile,
THREADS_RAW_STUB: threadsRaw,
VERIFIED_HEAD: localHead,
LIVE_HEAD: localHead,
PUSH_RACE_MERGED: 'false',
LIVE_HEAD_RETRY_DELAY: '0',
...env,
},
encoding: 'utf8',
},
);
expect(result.status).toBe(0);
return /NOTE<([\s\S]*)>$/.exec(result.stdout)?.[1] ?? '';
};
// Every up-front guard names itself, and a full skip counts all three
// selected ids as left behind.
for (const [env, guard] of [
[{ PUSH_RACE_MERGED: 'true' }, 'salvage merge'],
[{ VERIFIED_HEAD: '' }, 'missing verified_head'],
[{ VERIFIED_HEAD: 'different-verified-head' }, 'verified_head mismatch'],
[{ LIVE_HEAD: 'new-contributor-head' }, 'live-head drift'],
[{ LIVE_HEAD_EXIT: '1' }, 'live-head drift'],
]) {
const note = runNote(env);
expect(note).toContain('Review-thread resolution skipped');
expect(note).toContain(`guard: \`${guard}\``);
expect(note).toContain(
'resolved 0 of 3 selected thread(s), 3 left for a later round',
);
}
// A mid-list abort names its guard too, and carries the partial count.
writeFileSync(join(dir, 'resolved-comments.txt'), 'rc:111\nrc:444\n');
const stoppedNote = runNote({
LIVE_HEAD_SEQUENCE: `${localHead},${localHead},${localHead},new-contributor-head`,
});
expect(stoppedNote).toContain('Review-thread resolution stopped early');
expect(stoppedNote).toContain('guard: `live-head drift`');
expect(stoppedNote).toContain(
'resolved 1 of 2 selected thread(s), 1 left for a later round',
);
const unprovenNote = runNote({ UNKNOWN_THREAD_STATE: 'T_open_1' });
expect(unprovenNote).toContain('guard: `thread state unproven`');
expect(unprovenNote).toContain('resolved 0 of 2');
const ambiguousNote = runNote({
RESOLVE_APPLIES: 'false',
RESOLVE_EXIT: '0',
});
expect(ambiguousNote).toContain('guard: `mutation post-check ambiguous`');
expect(ambiguousNote).toContain('resolved 0 of 2');
// Healthy rounds report a positive count and never name a guard.
writeFileSync(join(dir, 'resolved-comments.txt'), 'rc:111\n');
const healthyNote = runNote();
expect(healthyNote).toContain('Resolved all 1 selected review thread(s)');
expect(healthyNote).not.toContain('guard:');
// Per-thread misses without a stopping guard still show up as a count,
// and an incomplete thread fetch is called out as the likely cause.
writeFileSync(join(dir, 'resolved-comments.txt'), 'rc:111\r\n333\n999\n');
const partialNote = runNote();
expect(partialNote).toContain(
'Resolved 1 of 3 selected review thread(s); 2 not resolved by this round',
);
expect(partialNote).toContain('details in the run log');
expect(partialNote).not.toContain('guard:');
const fetchNote = runNote({ THREADS_FETCH_EXIT: '1' });
expect(fetchNote).toContain('thread fetch incomplete');
// No ids selected → no note: the line appears only when the agent
// asked for resolution.
writeFileSync(join(dir, 'resolved-comments.txt'), '');
expect(runNote()).toBe('');
writeFileSync(join(dir, 'resolved-comments.txt'), 'rc:111\r\n333\n999\n');

// The SKILL keys resolution on the FINDING being fixed, not on "did I edit
// a file this round" — an earlier commit's fix that still holds resolves
// too, or a fixed Critical sits open and reads as unaddressed (#7731).
Expand Down
Loading