diff --git a/.github/workflows/qwen-autofix.yml b/.github/workflows/qwen-autofix.yml index 344bd4c46da..79ce66866b3 100644 --- a/.github/workflows/qwen-autofix.yml +++ b/.github/workflows/qwen-autofix.yml @@ -119,6 +119,17 @@ env: # changes, failed checks, and base conflicts may drive code changes; # lower-severity feedback is recorded and left open. CRITICAL_ONLY_AFTER_ROUND: '5' + # Per-author tail budget inside Critical-only mode. An account is an + # ACCOUNTABILITY unit, not a throttle: a human login can host an automated + # reviewer loop with the exact regeneration property the review bot has + # (feedback re-generated after every push, at zero marginal cost). So the + # brake keys on measured regeneration, not identity: every source gets a + # bounded number of untagged feedback batches per counting window once + # Critical-only engages — the review bot's budget is zero (all deferred), + # a human's is this many CONSUMED batches. Past it, continuing requires + # one conscious act (**[Critical]**, a Request changes review, or /retry), + # which is precisely what separates intent from automation. + CRITICAL_ONLY_HUMAN_BATCHES: '2' # An auth/access model error (401/402/403, "no access"/"does not exist") # never self-heals - only a maintainer can fix the key - and every retry # costs an agent run AND a PR comment. Cap those attempts far below @@ -2928,6 +2939,70 @@ jobs: if [[ "${ROUND}" -ge "${CRITICAL_ONLY_AFTER_ROUND}" ]]; then CRITICAL_ONLY='true' fi + # Which trusted humans have exhausted their per-window regular + # feedback budget (see CRITICAL_ONLY_HUMAN_BATCHES). A batch is + # COUNTED only when a Critical-only round actually consumed it: + # feedback items are bucketed into the (prev marker ts, marker ts] + # span that evaluated them, spans are kept only for markers that + # ran in Critical-only territory (acted rounds numbered past the + # threshold, no-change rounds at it), and an author needs >= K + # distinct consumed spans to land here. Fresh, not-yet-evaluated + # feedback never counts against its own author, and everything is + # window-scoped so a /retry resets the budget with the window. + # Only feedback the deferred renderer below would actually defer is + # counted: Critical-tagged items, Request changes / APPROVED reviews, + # and inline comments rooted at a Critical comment or attached to a + # Request changes review are never deferrable, so they must not burn + # an author's budget — the item filter mirrors those predicates. + OVER_BUDGET_AUTHORS='[]' + if [[ "${CRITICAL_ONLY}" == "true" ]]; then + OVER_BUDGET_AUTHORS="$(jq -n \ + --arg key "${LIVE_REARM_KEY}" --arg ab "${AUTOFIX_BOT}" --arg rb "${REVIEW_BOT}" \ + --argjson trust "${TRUSTED_ASSOC}" \ + --argjson r5 "${CRITICAL_ONLY_AFTER_ROUND}" \ + --argjson k "${CRITICAL_ONLY_HUMAN_BATCHES}" \ + --slurpfile rv "${WORKDIR}/rv.json" --slurpfile rc "${WORKDIR}/rc.json" --slurpfile ic "${WORKDIR}/ic.json" ' + ([ ($ic | add)[] | select((.user.login // "") == $ab) | . as $c | ($c.body // "") + | [ scan("") ] | .[] + | {ts: .[0], acted: .[1], round: (.[2] | tonumber), win: (.[3] // "none"), at: ($c.created_at // "")} ] + | map(select(.win == $key) | select(.ts != "9999-12-31T23:59:59Z")) + | sort_by(.at)) as $ms + | ([ range(0; ($ms | length)) as $i + | ($ms[$i] + | select((.acted == "true" and .round > $r5) or (.acted == "false" and .round >= $r5)) + | {lo: (if $i == 0 then "" else ($ms[$i - 1].ts) end), hi: .ts}) ]) as $spans + | ($rv | add) as $reviews + | ($rc | add) as $comments + | ([ $reviews[] + | select((.state // "") == "COMMENTED") + | select(((.body // "") | contains("**[Critical]**")) | not) + | {at: (.submitted_at // ""), login: (.user.login // ""), assoc: (.author_association // "")} ] + + [ $comments[] + | select(( + ((.body // "") | contains("**[Critical]**")) + or ((.in_reply_to_id // null) as $root + | $root != null + and any($comments[]; .id == $root and ((.body // "") | contains("**[Critical]**")))) + or ((.pull_request_review_id // null) as $review + | $review != null + and any($reviews[]; .id == $review and ((.state // "") == "CHANGES_REQUESTED"))) + ) | not) + | {at: (.created_at // ""), login: (.user.login // ""), assoc: (.author_association // "")} ] + + [ ($ic | add)[] + | select((.body // "") | test("`, + }); + const humanC = (login, at, assoc = 'MEMBER', body = 'feedback') => ({ + user: { login }, + created_at: at, + author_association: assoc, + body, + }); + const budgetDir = mkdtempSync(join(tmpdir(), 'over-budget-')); + try { + writeFileSync( + join(budgetDir, 'ic.json'), + JSON.stringify([ + markerC('2026-07-02T00:00:00Z', 'true', 5, '2026-07-02T01:00:00Z'), + markerC('2026-07-03T00:00:00Z', 'true', 6, '2026-07-03T01:00:00Z'), + markerC('2026-07-04T00:00:00Z', 'false', 6, '2026-07-04T01:00:00Z'), + // Stale-window marker: qualifies for a span but win != WKEY. + markerC( + '2026-06-15T00:00:00Z', + 'true', + 6, + '2026-06-15T01:00:00Z', + '2026-06-01T00:00:00Z', + ), + // Sentinel-ts marker: filtered out, so it opens no span. Dropping + // the guard would open a (2026-07-04, 9999] span that absorbs + // sentinelvictim's second batch below and surface them. + markerC('9999-12-31T23:59:59Z', 'true', 6, '2026-07-04T02:00:00Z'), + humanC('looper', '2026-07-02T12:00:00Z'), + humanC('looper', '2026-07-03T12:00:00Z'), + humanC('onetime', '2026-07-03T13:00:00Z'), + // Stale-window human inside the stale span; must not count. + humanC('onetime', '2026-06-14T12:00:00Z'), + humanC('looper', '2026-07-01T12:00:00Z'), + humanC('looper', '2026-07-05T00:00:00Z'), + humanC('rando', '2026-07-02T13:00:00Z', 'NONE'), + humanC( + 'looper', + '2026-07-02T13:00:00Z', + 'MEMBER', + '@qwen-code /review', + ), + // Command-only author: both items are /commands, so with the + // command-exclusion filter they count 0 consumed spans and stay + // absent; dropping the filter would surface them and fail the + // assertion, which is what makes the guard observable. + humanC( + 'commander', + '2026-07-02T14:00:00Z', + 'MEMBER', + '@qwen-code /review', + ), + humanC( + 'commander', + '2026-07-03T14:00:00Z', + 'MEMBER', + '@qwen-code /retry', + ), + // Critical-only author: both batches are **[Critical]**-tagged, so + // they are never deferrable and must not count (absent). Dropping the + // Critical exclusion would surface them. + humanC( + 'crit', + '2026-07-02T15:00:00Z', + 'MEMBER', + '**[Critical]** fix X', + ), + humanC( + 'crit', + '2026-07-03T15:00:00Z', + 'MEMBER', + '**[Critical]** still broken', + ), + // Review bot, even carrying a trusted association, is excluded by + // login (its budget is zero). Dropping `.login != $rb` surfaces it. + humanC( + 'qwen-code-ci-bot', + '2026-07-02T18:00:00Z', + 'MEMBER', + 'bot suggestion', + ), + humanC( + 'qwen-code-ci-bot', + '2026-07-03T18:00:00Z', + 'MEMBER', + 'bot suggestion 2', + ), + // Sentinel-span probe: the first batch lands in span B; the second + // falls after span B and only counts if the sentinel marker above + // wrongly opens a span. With the guard, stays at one batch (absent). + humanC('sentinelvictim', '2026-07-03T12:30:00Z'), + humanC('sentinelvictim', '2026-07-04T12:00:00Z'), + ]), + ); + // A second author whose two consumed batches arrive through the review + // (.submitted_at) and inline-comment (.created_at) branches, not ic.json: + // both are untagged, so they count under either census semantic. + writeFileSync( + join(budgetDir, 'rv.json'), + JSON.stringify([ + { + user: { login: 'reviewer2' }, + author_association: 'MEMBER', + state: 'COMMENTED', + submitted_at: '2026-07-02T12:30:00Z', + body: 'feedback delivered through a review', + }, + // Request changes / APPROVED reviews are never deferrable, so two + // consumed-span batches of each must not count (both authors absent): + // the census mirrors the deferred renderer's `state == "COMMENTED"`. + { + user: { login: 'cr' }, + author_association: 'MEMBER', + state: 'CHANGES_REQUESTED', + submitted_at: '2026-07-02T16:00:00Z', + body: 'changes requested', + }, + { + user: { login: 'cr' }, + author_association: 'MEMBER', + state: 'CHANGES_REQUESTED', + submitted_at: '2026-07-03T16:00:00Z', + body: 'changes requested again', + }, + { + user: { login: 'appr' }, + author_association: 'MEMBER', + state: 'APPROVED', + submitted_at: '2026-07-02T17:00:00Z', + body: 'lgtm', + }, + { + user: { login: 'appr' }, + author_association: 'MEMBER', + state: 'APPROVED', + submitted_at: '2026-07-03T17:00:00Z', + body: 'lgtm again', + }, + // Request changes review container (id 801) that the crinline + // comments below attach to; itself never deferrable. + { + id: 801, + user: { login: 'crreviewer' }, + author_association: 'MEMBER', + state: 'CHANGES_REQUESTED', + submitted_at: '2026-07-02T10:00:00Z', + body: 'requesting changes', + }, + ]), + ); + writeFileSync( + join(budgetDir, 'rc.json'), + JSON.stringify([ + { + user: { login: 'reviewer2' }, + author_association: 'MEMBER', + created_at: '2026-07-03T13:30:00Z', + body: 'feedback delivered through an inline comment', + }, + // Critical root comment (id 901) that replyguy's replies attach to. + { + id: 901, + user: { login: 'somecrit' }, + author_association: 'MEMBER', + created_at: '2026-07-02T11:00:00Z', + body: '**[Critical]** root finding', + }, + // Inline replies rooted at a Critical comment are never deferrable, + // so two consumed-span replies must not count (replyguy absent). + { + user: { login: 'replyguy' }, + author_association: 'MEMBER', + in_reply_to_id: 901, + created_at: '2026-07-02T12:45:00Z', + body: 'me too', + }, + { + user: { login: 'replyguy' }, + author_association: 'MEMBER', + in_reply_to_id: 901, + created_at: '2026-07-03T12:45:00Z', + body: 'me too again', + }, + // Inline comments under a Request changes review are never + // deferrable, so two consumed-span comments must not count + // (crinline absent). + { + user: { login: 'crinline' }, + author_association: 'MEMBER', + pull_request_review_id: 801, + created_at: '2026-07-02T13:45:00Z', + body: 'inline under CR review', + }, + { + user: { login: 'crinline' }, + author_association: 'MEMBER', + pull_request_review_id: 801, + created_at: '2026-07-03T13:45:00Z', + body: 'inline under CR review 2', + }, + ]), + ); + const overOut = execFileSync( + 'bash', + [ + '-c', + [ + 'set -uo pipefail', + `WORKDIR='${budgetDir}'`, + `LIVE_REARM_KEY='${WKEY}'`, + "AUTOFIX_BOT='qwen-code-dev-bot'", + "REVIEW_BOT='qwen-code-ci-bot'", + `TRUSTED_ASSOC='["OWNER","MEMBER","COLLABORATOR"]'`, + 'CRITICAL_ONLY_AFTER_ROUND=5', + 'CRITICAL_ONLY_HUMAN_BATCHES=2', + censusBlock.replace(/\n {10}/g, '\n'), + 'printf %s "${OVER_BUDGET_AUTHORS}"', + ].join('\n'), + ], + { encoding: 'utf8' }, + ); + // Only the two looped authors land here; every protected author above + // (crit/cr/appr/replyguy/crinline/qwen-code-ci-bot/sentinelvictim) has + // two consumed-span batches yet stays absent — dropping any one of the + // census's deferral-mirroring exclusions surfaces one of them and fails. + expect(JSON.parse(overOut)).toEqual(['looper', 'reviewer2']); + } finally { + rmSync(budgetDir, { recursive: true, force: true }); + } + // The deferral note names over-budget authors with the escapes. + expect(prepareBranchAndFeedbackStep).toContain('is at this window'); + expect(prepareBranchAndFeedbackStep).toContain('regular-feedback budget'); expect(inlineFilter).toContain('pull_request_review_id'); // Scan still selects fresh suggestions so a no-op report can advance the