Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
52 changes: 50 additions & 2 deletions .github/workflows/qwen-autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3495,10 +3495,54 @@ jobs:
# Push back to the FORK branch via allow-edits (PAT has push
# rights on the upstream, which GitHub extends to the fork's
# PR branch when the author ticked the box).
git push --no-verify "https://x-access-token:${GITHUB_TOKEN}@github.com/${HEAD_REPO}.git" HEAD:"${BRANCH}"
PUSH_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${HEAD_REPO}.git"
else
git push --no-verify origin "${BRANCH}"
PUSH_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${REPO}.git"
fi
# Salvage a race-lost push instead of discarding the run. The
# per-PR head-write concurrency group serialises THIS repo's
# workflows, but it cannot stop the PR author (or anything on the
# fork side) pushing during the agent's ~50-minute window —
# observed twice in one day (#7983, #7985): a one-shot push died
# `fetch first` and a full verified agent run was thrown away.
# On rejection, fetch the moved head and MERGE it into the local
# line (merge, not rebase: the agent's own conflict-resolution
# rounds create merge commits, and a rebase would flatten them
# and can silently re-introduce the conflicts it resolved). The
# merge result descends from the remote head, so the retried push
# is a fast-forward. A genuine content conflict aborts and falls
# through to the existing failure path — same as today.
PUSH_RACE_MERGED='false'
for push_attempt in 1 2 3; do
if git push --no-verify "${PUSH_URL}" HEAD:"${BRANCH}"; then
break
fi
if [[ "${push_attempt}" == 3 ]]; then
echo "::error::push rejected ${push_attempt} times; giving up"
exit 1
fi
echo "⚠️ push rejected (attempt ${push_attempt}) — branch moved during the run; merging the new head and retrying"
if ! git fetch "${PUSH_URL}" "refs/heads/${BRANCH}"; then
echo "::error::could not fetch the moved head (attempt ${push_attempt}) — cannot salvage this push"
exit 1
fi
# The disclosure flag keys on HEAD actually advancing: a push
# can fail transiently (upload timeout, 503) with the branch
# unmoved, and the merge then no-ops "Already up to date" —
# flagging that would tell the reviewer to re-check mid-run
# commits that never existed.
PRE_MERGE_HEAD="$(git rev-parse HEAD)"
if ! git -c user.name="${AUTOFIX_BOT}" \
-c user.email="${AUTOFIX_BOT}@users.noreply.github.com" \
merge --no-edit FETCH_HEAD; then
git merge --abort || true
echo "::error::the commits pushed during the run conflict with this fix — handing off instead of overwriting either side"
exit 1
fi
if [[ "$(git rev-parse HEAD)" != "${PRE_MERGE_HEAD}" ]]; then
PUSH_RACE_MERGED='true'
fi
done
# Resolve the review threads whose findings the agent actually
# IMPLEMENTED, so a human re-reviewing sees only what is still open
# instead of re-reading every thread to work out what was handled.
Expand Down Expand Up @@ -3614,6 +3658,10 @@ jobs:
fi
echo
echo "Base-conflict check · 基分支冲突检查: $([[ "${CONFLICT}" == "true" ]] && echo 'conflicted with main — resolved in this push. · 与 main 有冲突——已在本次推送中解决。' || echo 'no conflict with main. · 与 main 无冲突。')"
if [[ "${PUSH_RACE_MERGED}" == 'true' ]]; 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
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
93 changes: 91 additions & 2 deletions scripts/tests/qwen-autofix-workflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,10 @@ describe('qwen-autofix workflow', () => {
'git fetch "https://github.com/${HEAD_REPO}.git" "refs/heads/${BRANCH}"',
);
expect(workflow).toContain(
'git push --no-verify "https://x-access-token:${GITHUB_TOKEN}@github.com/${HEAD_REPO}.git" HEAD:"${BRANCH}"',
'PUSH_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${HEAD_REPO}.git"',
);
expect(workflow).toContain(
'git push --no-verify "${PUSH_URL}" HEAD:"${BRANCH}"',
);
// The allow-edits grant rides the classic-PAT path only — prepare must
// prove push access BEFORE an agent round is spent, discarding
Expand Down Expand Up @@ -5222,6 +5225,92 @@ describe('qwen-autofix workflow', () => {
expect(pushAndReportStep).toContain('milestone digest failed to post');
});

it('salvages a race-lost push by merging the moved head instead of discarding the run', () => {
// A one-shot push dies `fetch first` whenever anything pushes to the PR
// head during the agent's ~50-minute window (observed twice in one day,
// #7983/#7985 — a full verified agent run thrown away each time). The
// per-PR head-write concurrency group cannot prevent this: it only
// serialises THIS repo's workflows, not the PR author or the fork side.
// On rejection the report step fetches the moved head, MERGES it into
// the local line, and retries a bounded number of times; the merge
// result descends from the remote head so the retry is a fast-forward.
expect(pushAndReportStep).toContain('for push_attempt in 1 2 3; do');
Comment thread
qwen-code-dev-bot marked this conversation as resolved.
Resolved
// A successful push breaks out of the loop immediately — without this
// pin, deleting the break survives: the loop range and give-up message
// are still asserted as strings, but a successful push then re-runs
// git push twice more and the salvage legs execute against a branch
// that was already pushed.
expect(pushAndReportStep).toMatch(
/if git push --no-verify "\$\{PUSH_URL\}" HEAD:"\$\{BRANCH\}"; then\n\s+break/,
);
// BOTH push-URL constructions stay pinned — the fork one is pinned by
// the fork-plumbing test, and the same-repo one lost its old
// `origin "${BRANCH}"` pin in this rework: a mutation swapping ${REPO}
// for ${HEAD_REPO} (empty in the same-repo case → a malformed
// `github.com/.git` remote) must not survive.
expect(pushAndReportStep).toContain(
'PUSH_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${REPO}.git"',
);
expect(pushAndReportStep).toContain(
'git fetch "${PUSH_URL}" "refs/heads/${BRANCH}"',
);
// Every failure path in the salvage loop is ::error::-annotated — a
// deleted fork branch (or transient network error) must not kill the
// step with an unannotated exit 128 under bash -e.
expect(pushAndReportStep).toContain(
'could not fetch the moved head (attempt ${push_attempt})',
);
// The disclosure flag keys on HEAD actually advancing: a transient
// push failure on an unmoved branch no-ops the merge ("Already up to
// date") and must NOT tell the reviewer to re-check commits that
// never existed.
expect(pushAndReportStep).toContain(
'PRE_MERGE_HEAD="$(git rev-parse HEAD)"',
);
expect(pushAndReportStep).toMatch(
/if \[\[ "\$\(git rev-parse HEAD\)" != "\$\{PRE_MERGE_HEAD\}" \]\]; then\n\s+PUSH_RACE_MERGED='true'/,
);
// Merge, never rebase: the agent's own conflict-resolution rounds create
// merge commits, and a rebase would flatten them and can silently
// re-introduce the conflicts they resolved.
expect(pushAndReportStep).toContain('merge --no-edit FETCH_HEAD');
expect(pushAndReportStep).not.toContain('git rebase');
// The merge commit needs an explicit identity on a bare runner.
expect(pushAndReportStep).toContain('-c user.name="${AUTOFIX_BOT}"');
expect(pushAndReportStep).toContain(
'-c user.email="${AUTOFIX_BOT}@users.noreply.github.com"',
);
// A genuine content conflict aborts cleanly and falls through to the
// existing failure path — the salvage must never overwrite either side.
expect(pushAndReportStep).toContain('git merge --abort || true');
expect(pushAndReportStep).toContain(
'the commits pushed during the run conflict with this fix',
);
// The salvage is disclosed in the round report: the round's verification
// ran before the merge, so mid-run commits deserve a re-check. The
// structure pin keeps the warning conditional — making it unconditional
// (printed every round) passes presence-only checks but is the exact
// false-disclosure this head's own fix commit closes from the other side.
expect(pushAndReportStep).toMatch(
/if \[\[ "\$\{PUSH_RACE_MERGED\}" == .true. \]\]; then\n\s+echo\n\s+echo "⚠️ The branch received new commits/,
);
expect(pushAndReportStep).toContain('PUSH_RACE_MERGED');
expect(pushAndReportStep).toContain('verification predates that merge');
// Bounded: the loop gives up after the last attempt instead of spinning.
// The structural pin connects the guard value to the error exit — a
// mutation of == 3 to == 4 survives presence-only checks: the loop
// range string is unchanged and the error message still exists as dead
// code, but execution falls through to the report section after 3
// failed attempts and posts a round-complete comment as if the push
// succeeded.
expect(pushAndReportStep).toMatch(
/if \[\[ "\$\{push_attempt\}" == 3 \]\]; then\n\s+echo "::error::push rejected/,
);
expect(pushAndReportStep).toContain(
'push rejected ${push_attempt} times; giving up',
);
Comment thread
qwen-code-dev-bot marked this conversation as resolved.
Resolved
});

it('pushes autofix branches without rewriting remote history', () => {
expect(workflow).not.toMatch(/\bgit push\b[^\n]*--force(?:-with-lease)?/);
// No bare -f / +refspec force forms either. (--no-verify is NOT a force
Expand All @@ -5233,7 +5322,7 @@ describe('qwen-autofix workflow', () => {
expect(workflow).not.toMatch(/\bgit push\b[^\n]* \+\S/);
expect(publishPrStep).toContain('git push --no-verify origin "${BRANCH}"');
expect(pushAndReportStep).toContain(
'git push --no-verify origin "${BRANCH}"',
'git push --no-verify "${PUSH_URL}" HEAD:"${BRANCH}"',
);
Comment thread
wenshao marked this conversation as resolved.
Resolved
// Five sites now: both PAT pushes, the PAT-bearing prepare checkout,
// AND both no-secret verification checkouts (convention: every host
Expand Down
Loading