Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
289 changes: 289 additions & 0 deletions .github/scripts/run-autofix-review-verification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,148 @@ if [[ ! -s "${WORKDIR}/address-summary.md" ]]; then
exit 1
fi

# --- Content-based validity checks -------------------------------------------
# Feedback validity is judged by CONTENT, never by AUTHOR: a maintainer's
# comment, the review bot's finding, and a model-drafted suggestion pasted by
# a human all drive the agent the same way, so the gate checks what the round
# DID, not who asked for it. Two deterministic checks below (sensitive-area
# footprint here, the bite check after the package tests) plus one advisory
# (test deletion). All three read only git state and run before/around the
# existing deterministic re-checks.

# Sensitive-area footprint: a review round must not EXPAND into CI or
# verification machinery the PR itself was never about — a single review
# comment (any author) must not be able to alter the loop's own guardrails.
# Judged by AREA CLASS, not file: a PR whose own pre-round diff already
# touches a class (an infra PR under takeover) keeps full freedom there;
# a round reaching into a class the PR never touched is rejected. Retryable:
# the repair pass can revert the offending files in a follow-up commit.
# `scripts` sections of workspace manifests are their own class because the
# gate's every command resolves through them (`npm run build/typecheck/
# lint/test`) — a scripts edit can hollow out the gate while every check
# "passes". Only root and first-level `packages/*/package.json` count:
# fixture manifests deeper in a src tree are ordinary test data.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2787cb9: the block comment now matches the resolver-backed code (root + declared workspaces, nested included).


🤖 via Claude Code · model claude-fable-5

sensitive_class_of() {
# Prints the class name for a path, or nothing. Kept as one function so
# the round scan and the PR-footprint scan cannot drift. Classes are
# NARROW on purpose: a PR that only edits issue templates must not
# thereby license rounds to rewrite workflows, so executable CI surface,
# repo scripts, and passive .github metadata are separate capabilities.
# scripts/tests/** is ordinary test code, not gate machinery — the gate
# never executes it, and tooling PRs routinely grow tests there.
local f="${1}"
case "${f}" in
.github/workflows/* | .github/actions/*) echo 'ci-workflows' ;;
.github/scripts/*) echo 'ci-scripts' ;;
Comment thread
wenshao marked this conversation as resolved.
Resolved
.github/*) echo 'gh-metadata' ;;
.husky/*) echo 'git-hooks' ;;
Comment thread
wenshao marked this conversation as resolved.
Resolved
scripts/tests/*) ;;
# The transitive executable surface of the gate's own commands:
# `npm run build/lint/…` resolve through manifests INTO these files,
# and .npmrc steers what npm itself executes.
scripts/*) echo 'repo-scripts' ;;
.npmrc | .nvmrc) echo 'toolchain-config' ;;
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
*) case "${f##*/}" in
Comment thread
wenshao marked this conversation as resolved.
Resolved
eslint.config.*) echo 'lint-config' ;;
vitest.config.*) echo 'test-config' ;;
tsconfig.json | tsconfig.*.json) echo 'ts-config' ;;
Comment thread
wenshao marked this conversation as resolved.
Resolved
esac ;;
esac
}
manifest_scripts_changed() {
# True when the scripts section of a root/workspace manifest differs
# between the two refs. Missing file on either side reads as {}.
Comment thread
wenshao marked this conversation as resolved.
Resolved
local f="${1}" from="${2}" to="${3}" a b
a="$(git show "${from}:${f}" 2> /dev/null | jq -cS '.scripts // {}' 2> /dev/null)" || a='{}'
b="$(git show "${to}:${f}" 2> /dev/null | jq -cS '.scripts // {}' 2> /dev/null)" || b='{}'
[[ "${a}" != "${b}" ]]
}
ROUND_RANGE="origin/${BRANCH}...${BRANCH}"
PR_RANGE="origin/main...origin/${BRANCH}"
Comment thread
wenshao marked this conversation as resolved.
Resolved
ROUND_CLASSES=''
while IFS= read -r f; do
[[ -n "${f}" ]] || continue
c="$(sensitive_class_of "${f}")"
if [[ -z "${c}" ]]; then
case "${f}" in
package.json | packages/*/package.json)
[[ "${f}" == packages/*/*/* ]] && continue
Comment thread
wenshao marked this conversation as resolved.
Resolved
# A manifest the round ADDED (a new workspace) is the round's own
# new surface, not a rewrite of commands the gate already ran —
# only scripts edits to a manifest that existed pre-round count.
git cat-file -e "origin/${BRANCH}:${f}" 2> /dev/null || continue
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment on lines +535 to +536

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined with reasoning: the scenario requires the PR's own footprint to already license manifest-scripts-root — the accountability boundary working as designed (the PR itself put the root dispatcher in play). Resolving workspace membership against the pre-round tree is the clean closure and is queued with the census follow-up rather than racing it here.


🤖 via Claude Code · model claude-fable-5

manifest_scripts_changed "${f}" "origin/${BRANCH}" "${BRANCH}" &&
c='manifest-scripts' ;;
esac
fi
[[ -n "${c}" ]] && ROUND_CLASSES+="${c} ${f}"$'\n'
# -z --no-renames: NUL-delimited raw paths (a specially named file is not
# core.quotePath-mangled past the case patterns), and a rename decomposes
# into A+D so the VACATED sensitive path is classified too — moving a
# workflow out of .github/ is a removal of verification machinery.
done < <(git diff --name-only -z --no-renames "${ROUND_RANGE}" | tr '\0' '\n')
if [[ -n "${ROUND_CLASSES}" ]]; then
PR_CLASSES=''
while IFS= read -r f; do
[[ -n "${f}" ]] || continue
c="$(sensitive_class_of "${f}")"
if [[ -z "${c}" ]]; then
case "${f}" in
package.json | packages/*/package.json)
[[ "${f}" == packages/*/*/* ]] && continue
manifest_scripts_changed "${f}" 'origin/main' "origin/${BRANCH}" &&
c='manifest-scripts' ;;
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
esac
fi
[[ -n "${c}" ]] && PR_CLASSES+="${c}"$'\n'
done < <(git diff --name-only -z --no-renames "${PR_RANGE}" | tr '\0' '\n')
Comment thread
wenshao marked this conversation as resolved.
Resolved
VIOLATIONS="$(while IFS= read -r line; do
[[ -n "${line}" ]] || continue
cls="${line%% *}"
grep -qx "${cls}" <<< "${PR_CLASSES}" || printf '%s\n' "${line}"
Comment thread
wenshao marked this conversation as resolved.
Resolved
done <<< "${ROUND_CLASSES}")"
if [[ -n "${VIOLATIONS}" ]]; then
{
echo 'This round modified CI/verification machinery in area(s) the PR itself never touched:'
printf '%s\n' "${VIOLATIONS}"
Comment thread
wenshao marked this conversation as resolved.
Resolved
echo 'Review feedback alone — from ANY author — cannot authorize changes to the loop'"'"'s own guardrails. Revert these files; if the feedback genuinely requires them, escalate it to a maintainer as an open question instead of implementing it.'
} >> "${GATE_LOG}"
reject_fix 'round expands into CI/verification machinery outside the PR footprint'
fi
fi

# Test-deletion advisory: deleting or shrinking tests is sometimes right
# (the pinned behavior was wrong, or coverage is duplicated) and the agent
# is required to justify it in its summary — but the SURFACING must not be
# the agent's own prose. The gate writes its own advisory into the round
# report so a maintainer always sees exactly which tests disappeared,
# whoever suggested it.
TEST_PATHSPEC=(':(glob)**/*.test.*' ':(glob)**/*.spec.*' ':(glob)**/__snapshots__/**' ':(glob)integration-tests/**')
Comment thread
wenshao marked this conversation as resolved.
Resolved
DELETED_TESTS="$(git diff --name-only --diff-filter=D "${ROUND_RANGE}" -- "${TEST_PATHSPEC[@]}")"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2787cb9: both advisory measurements pass --no-renames (a rename out of runner discovery is a shrink) and deleted names are collected NUL-safe.


🤖 via Claude Code · model claude-fable-5

NET_TEST_LINES="$(git diff --numstat "${ROUND_RANGE}" -- "${TEST_PATHSPEC[@]}" |
Comment thread
wenshao marked this conversation as resolved.
Resolved
awk '{ if ($1 != "-") a += $1; if ($2 != "-") d += $2 } END { print a - d + 0 }')"
rm -f "${WORKDIR}/gate-advisories.md"
if [[ -n "${DELETED_TESTS}" || "${NET_TEST_LINES}" -le -25 ]]; then
{
echo '⚖️ **Gate advisory — test coverage shrank this round** (machine-measured, not agent-authored): '"net ${NET_TEST_LINES} test lines."
if [[ -n "${DELETED_TESTS}" ]]; then
echo
echo 'Deleted test files:'
# Filenames are branch-controlled bytes rendered inside a gate-authored
# (trusted-voice) document: a backtick in a legal git filename would
# close the code span and let the name forge "machine-measured" text.
# Render through a conservative safe-character set; anything else
# (backticks, newlines, control bytes) becomes '?'.
while IFS= read -r f; do
[[ -n "${f}" ]] && echo "- \`${f//[^A-Za-z0-9._\/ -]/?}\`"
done <<< "${DELETED_TESTS}"
fi
echo
echo 'The justification must be in the round summary above; a deletion is only sound when the pinned behavior itself was wrong (evidence shown) or the coverage demonstrably survives elsewhere. · 本轮测试覆盖净减少(门自动测量,非 agent 文本);删除是否成立请对照上方轮次摘要中的理由——仅当被钉住的行为本身有误(需给出证据)或覆盖确有替代时才合理。'
} > "${WORKDIR}/gate-advisories.md"
echo '⚖️ test coverage shrank this round — advisory written for the report' | tee -a "${GATE_LOG}"
fi

echo '🔬 Re-running deterministic checks (independent of the agent)...'
run_check 'build failed on the agent-committed fix' npm run build
# Typecheck consumes core's dist (sdk-typescript resolves
Expand Down Expand Up @@ -377,6 +519,153 @@ else
npm run test --workspace "${p}" --if-present -- --changed origin/main --passWithNoTests
done
fi

# Bite check: run this round's changed tests against the PRE-ROUND tree
# (origin/<branch> sources + the round's test files). If EVERY changed test
# also passes there, the tests demonstrate nothing — the classic shape of a
# plausible-but-false finding implemented as a "fix" whose regression test
# was green all along.
#
# INTENT decides the consequence, and intent is read from the round's own
# machine-readable artifacts, not inferred from the diff shape: a round is
# a DEFECT-CLAIM round only when resolved-comments.txt marks a finding
# resolved-in-code whose thread is Critical-tagged or belongs to a
# CHANGES_REQUESTED review (matched in rc.json/rv.json). Those rounds get a
# non-retryable rejection on all-green — the 18-minute repair pass cannot
# make a nonexistent defect reproduce; the next full round re-reads the
# feedback with the evidence in LAST_REJECTION and can decline or escalate
# instead. Every OTHER src+test round (a refactor pinning existing
# behavior, an optional cleanup adding coverage) legitimately produces
# all-green pre-round tests, so all-green there is a gate-authored ADVISORY
# in the report, never a rejection.
# Scope guards (all fail OPEN — only the clean "ran and all passed" verdict
# has consequences):
# - Runnable unit tests only: *.test.* / *.spec.* files. Snapshots and
# integration-tests/ are not directly runnable here.
# - Single-package rounds only: on the detached pre-round tree, gitignored
# dist/ still carries the ROUND's build, so a cross-package fix leaks
# into the baseline through dist-resolved imports and would read as
# "no bite" — the same dist confound that A/B-exempts typecheck above.
# Same-package imports resolve through vitest src aliases and relative
# paths, which the detach does revert.
Comment thread
wenshao marked this conversation as resolved.
Resolved
# - A test that fails on the pre-round tree for ANY reason (assertion,
# collection, import of a round-added symbol) counts as biting; the
# check's power is the all-green case, which no honest defect fix
# produces. KNOWN LIMIT, deliberate: the verdict is existential over
# the batch, so in a mixed Critical round one genuinely biting test
# vouches for the batch — binding each behavior to its own probe needs
# per-test result parsing and is out of scope here.
BITE_RUNNER="${BITE_RUNNER:-bite_runner_default}"
bite_runner_default() {
# $1 = workspace dir, rest = test paths relative to the workspace.
Comment thread
wenshao marked this conversation as resolved.
Resolved
local ws="${1}"
shift
npm run test --workspace "${ws}" --if-present -- "$@"
Comment thread
wenshao marked this conversation as resolved.
Resolved
}
mapfile -t BITE_FILES < <(git diff --name-only --diff-filter=AM "${ROUND_RANGE}" \
-- ':(glob)**/*.test.*' ':(glob)**/*.spec.*' | grep -v '__snapshots__' || true)
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
# No blanket *.md exclusion: .qwen/skills/**/*.md is EXECUTABLE agent
# behavior (and scripts/tests pins it), so markdown counts as source; the
# consequence gating above keeps doc-only rounds from ever being rejected.
BITE_SRC="$(git diff --name-only "${ROUND_RANGE}" \
-- ':(exclude,glob)**/*.test.*' ':(exclude,glob)**/*.spec.*' \
':(exclude,glob)**/__snapshots__/**' ':(exclude,glob)**/test-utils/**' \
':(exclude,glob)integration-tests/**')"
Comment thread
wenshao marked this conversation as resolved.
Resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
# Does this round RESOLVE a Critical-tagged or CHANGES_REQUESTED finding in
# code? resolved-comments.txt is the agent's own machine-readable claim of
# what it fixed; rc.json/rv.json carry the thread bodies and review states
# the scan already fetched. Absent/empty inputs read as "no defect claim".
BITE_ENFORCE='false'
if [[ -s "${WORKDIR}/resolved-comments.txt" && -s "${WORKDIR}/rc.json" ]]; then
BITE_ENFORCE="$(jq -rs --rawfile ids "${WORKDIR}/resolved-comments.txt" \
--slurpfile reviews "${WORKDIR}/rv.json" '
(add // []) as $comments
| ($reviews | add // []) as $reviews
| ($ids | split("\n") | map(select(test("^[0-9]+$")) | tonumber)) as $resolved
Comment thread
wenshao marked this conversation as resolved.
Resolved
| any($comments[];
(.id as $id | $resolved | index($id) != null)
and (
((.body // "") | contains("**[Critical]**"))
Comment thread
wenshao marked this conversation as resolved.
Resolved
or ((.pull_request_review_id // null) as $review
| $review != null
and any($reviews[]; .id == $review and ((.state // "") == "CHANGES_REQUESTED")))
))' "${WORKDIR}/rc.json" 2> /dev/null)" || BITE_ENFORCE='false'
[[ "${BITE_ENFORCE}" == 'true' ]] || BITE_ENFORCE='false'
fi
if [[ "${#BITE_FILES[@]}" -gt 0 && -n "${BITE_SRC}" ]]; 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
BITE_PKGS="$(printf '%s\n' "${BITE_FILES[@]}" "${BITE_SRC}" |
bash "${RUNNER_TEMP}/resolve-owning-packages.sh")"
if [[ "$(wc -l <<< "${BITE_PKGS}")" -ne 1 || -z "${BITE_PKGS}" ]]; then
Comment thread
wenshao marked this conversation as resolved.
Resolved
echo "🦷 bite check skipped: round spans multiple/no workspaces (dist confound)" \
| tee -a "${GATE_LOG}"
else
echo "🦷 bite check: running this round's changed tests on the pre-round tree" \
| tee -a "${GATE_LOG}"
git restore -- . 2>> "${GATE_LOG}" || true
if git checkout --quiet --detach "origin/${BRANCH}" 2>> "${GATE_LOG}"; then
BITE_BIT='false'
BITE_RAN='false'
if git checkout --quiet "${BRANCH}" -- "${BITE_FILES[@]}" 2>> "${GATE_LOG}"; then
Comment thread
wenshao marked this conversation as resolved.
Resolved
BITE_ARGS=()
for f in "${BITE_FILES[@]}"; do
BITE_ARGS+=("${f#"${BITE_PKGS}"/}")
done
BITE_RAN='true'
if ! "${BITE_RUNNER}" "${BITE_PKGS}" "${BITE_ARGS[@]}" \
> "${GATE_LOG}.bite" 2>&1; then
Comment thread
wenshao marked this conversation as resolved.
Resolved
BITE_BIT='true'
Comment thread
wenshao marked this conversation as resolved.
Resolved
fi
else
echo "🦷 bite check skipped: could not overlay the round's tests" \
| tee -a "${GATE_LOG}"
fi
git checkout --quiet --force "${BRANCH}" 2>> "${GATE_LOG}" || {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still deferred with the shared-fixture follow-up (same decline as R4-8996): the contract is a verbatim copy of the tested baseline-A/B block and assert_verification_tree backstops fall-through; a parameterized test driving both copies is the right shape and is on the backlog.


🤖 via Claude Code · model claude-fable-5

# Same crash contract as the baseline A/B: the tree is no longer the
# one under verification, and a plain outcome=failed would advance
# the watermark on a verdict the gate never reached. Leave outcome
# unset so the next scan retries on a fresh checkout.
echo "❌ could not restore the verification tree after the bite check"
Comment thread
wenshao marked this conversation as resolved.
Resolved
{
echo '**could not restore the verification tree after the bite check**'
echo
echo '````'
tail -c 3000 "${GATE_LOG}" 2> /dev/null
echo '````'
} > "${WORKDIR}/gate-rejection.md" || true
exit 1
}
git reset --quiet 2>> "${GATE_LOG}" || true
if [[ "${BITE_RAN}" == 'true' && "${BITE_BIT}" == 'false' && "${BITE_ENFORCE}" == 'true' ]]; then
{
echo 'Every test this round added or changed ALSO PASSES on the pre-round tree (the branch as pushed, with only your test files overlaid). This round resolves a Critical / Request-changes finding in code, and a defect fix must come with a test that fails before the fix and passes after it — an all-green result here means the claimed defect does not reproduce, no matter who reported it.'
echo
echo 'If the finding does not reproduce, do not implement it: decline it (for a disproved finding) or escalate it as an open question, attaching this measurement as the evidence.'
echo
echo 'Changed tests measured:'
printf -- '- %s\n' "${BITE_FILES[@]}"
echo '````'
tail -c 1200 "${GATE_LOG}.bite" 2> /dev/null
Comment thread
wenshao marked this conversation as resolved.
Resolved
echo '````'
} >> "${GATE_LOG}"
reject_fix 'bite check: changed tests pass on the pre-round tree (claimed defect does not reproduce)' 'false' 'false'
Comment thread
wenshao marked this conversation as resolved.
Resolved
elif [[ "${BITE_RAN}" == 'true' && "${BITE_BIT}" == 'false' ]]; then
# Not a defect-claim round: all-green pre-round tests are legitimate
# for a refactor or coverage addition — surface, never reject.
{
echo '🦷 **Gate advisory — this round'"'"'s changed tests all pass on the pre-round tree** (machine-measured, not agent-authored). Expected for a refactor or coverage addition; if this round was meant to FIX a defect, that defect did not reproduce. · 本轮改动的测试在轮前树上全部通过(门自动测量,非 agent 文本)。对重构或补充覆盖属正常;若本轮意在修复缺陷,则该缺陷未能复现。'
} >> "${WORKDIR}/gate-advisories.md"
echo "🦷 changed tests all pass on the pre-round tree — advisory written (no defect claim in this round)" \

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2787cb9: demoted rounds get their own advisory text — all-green named as the expected shape of a test-side claim, not a failed reproduction.


🤖 via Claude Code · model claude-fable-5

| tee -a "${GATE_LOG}"
elif [[ "${BITE_BIT}" == 'true' ]]; then
echo "🦷 bite confirmed: at least one changed test fails on the pre-round tree" \
| tee -a "${GATE_LOG}"
fi
else
echo "🦷 bite check skipped: could not detach to the pre-round tree" \
| tee -a "${GATE_LOG}"
fi
fi
fi
assert_verification_tree
echo "verified_head=${VERIFICATION_HEAD}" >> "${GITHUB_OUTPUT}"
echo "outcome=fixed" >> "${GITHUB_OUTPUT}"
12 changes: 11 additions & 1 deletion .github/workflows/qwen-autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4685,7 +4685,7 @@ jobs:
if git rev-parse --verify "${BRANCH}" > /dev/null 2>&1; then
git diff "origin/main...${BRANCH}" > "${WORKDIR}/pr.diff" || true
fi
for f in feedback.md address-summary.md no-action.md failure.md handoff.md gate-rejection.md agent-api-error agent-api-error-kind agent-timeout resolved-comments.txt comment-replies.json pr.diff; do
for f in feedback.md address-summary.md no-action.md failure.md handoff.md gate-rejection.md gate-advisories.md agent-api-error agent-api-error-kind agent-timeout resolved-comments.txt comment-replies.json pr.diff; do
if [[ -f "${WORKDIR}/${f}" ]]; then
echo "=============== ${f} ==============="
cat "${WORKDIR}/${f}"
Expand Down Expand Up @@ -4969,6 +4969,16 @@ jobs:
# line, and jq scan() matches across newlines. The backslashes
# render away in markdown, so the visible text is unchanged.
sed 's/<!--/<!\\-\\-/g' "${WORKDIR}/address-summary.md"
# Gate-authored advisories (e.g. "test coverage shrank") render
# AFTER the agent's summary: the summary carries the agent's
# justification, the advisory carries the machine measurement a
# maintainer checks it against. Escaped like every other
# embedded file — the advisory quotes file paths from the
# branch, which are model-influenced content.
if [[ -s "${WORKDIR}/gate-advisories.md" ]]; then
echo
sed 's/<!--/<!\\-\\-/g' "${WORKDIR}/gate-advisories.md"
fi
Comment on lines +5726 to +5729

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Queued as follow-up per the convergence note: rendering advisories in failure/handoff paths touches the report plumbing shared with #8981's retry loop; noted on the backlog with the census work.


🤖 via Claude Code · model claude-fable-5

if [[ -s "${WORKDIR}/deferred-feedback.md" ]]; then
echo
sed 's/<!--/<!\\-\\-/g' "${WORKDIR}/deferred-feedback.md"
Expand Down
Loading
Loading