Skip to content
5 changes: 5 additions & 0 deletions .github/workflows/qwen-autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4423,6 +4423,11 @@ jobs:
# raised, with no ::warning:: anywhere in that loop. 60000 rejects
# every minutes-shaped value (1..999) and every 0/000, which the
# bare regex admitted while the message claimed positivity.
# Hand-maintained sibling of the triage-budget sanitize step in
# qwen-triage.yml's authorize job; the failure modes deliberately
# differ (this one clamps garbage to the ceiling, that one falls
# back to the default), so a boundary-bug fix in one must be
# re-derived in the other.
BUDGET_CAP_MS=7200000
BUDGET_FLOOR_MS=60000
if [[ ! "${QWEN_TIMEOUT_MS}" =~ ^[0-9]{1,8}$ ]] ||
Expand Down
77 changes: 76 additions & 1 deletion .github/workflows/qwen-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,66 @@ jobs:
# maintainer's /verify comment approves the code that exists now, not
# whatever the author pushes while the job queues.
verify_head_oid: '${{ steps.perm.outputs.verify_head_oid }}'
# The triage job's timeout-minutes, SANITIZED: that field is evaluated
# before any step of the consuming job runs, so a malformed repository
# variable would kill triage at expression time — no steps, no
# always() finalize, no status comment: a silent stop. And the knob
# exists to be changed WITHOUT a PR, so no reviewer ever sees a bad
# value. This job can run bash, so it validates and clamps instead.
triage_timeout_minutes: '${{ steps.budget.outputs.triage_timeout_minutes }}'
steps:
- name: 'Sanitize the triage budget'
id: 'budget'
env:
RAW: '${{ vars.QWEN_TRIAGE_TIMEOUT_MINUTES }}'
run: |-
set -euo pipefail
# Bare positive integer minutes only — no units, quotes or
# decimals. Floor 10: below that the agent cannot finish even a
# trivial pass and every run becomes an instant kill. Ceiling 600:
# a runaway value would hold a scarce ECS runner and the per-PR
# concurrency group for days — though only the self-hosted pool
# can actually reach it: GitHub-hosted runners hard-cap any job
# at 360 minutes, so runs routed to ubuntu-latest die there
# whatever this validates. Anything unparsable warns, names the
# variable (the run log otherwise blames fromJSON), and falls
# back to the 60-minute default.
# Hand-maintained sibling of the QWEN_TIMEOUT_MS clamp in
# qwen-autofix.yml's review-address step; the failure modes
# deliberately differ (that one clamps garbage to its ceiling,
# this one falls back to the default), so a boundary-bug fix in
# one must be re-derived in the other.
MINUTES=60
if [[ -n "${RAW}" ]]; then
if [[ "${RAW}" =~ ^[0-9]+$ ]]; then
# Strip leading zeros so the width test counts SIGNIFICANT
# digits: 000000000000000000060 is 60, not a ceiling
# violation, and an all-zero value is 0.
TRIMMED="${RAW#"${RAW%%[!0]*}"}"
TRIMMED="${TRIMMED:-0}"
# Over 18 significant digits, bash's 64-bit arithmetic
# wraps, and the residue can land inside [10,600], silently
# skipping both clamps. Any such value is above the ceiling
# by construction.
if (( ${#TRIMMED} > 18 )); then
echo "::warning::QWEN_TRIAGE_TIMEOUT_MINUTES=${RAW} exceeds the 600-minute ceiling; clamping to 600."
MINUTES=600
else
MINUTES=$((10#${TRIMMED}))
if (( MINUTES < 10 )); then
echo "::warning::QWEN_TRIAGE_TIMEOUT_MINUTES=${RAW} is below the 10-minute floor; clamping to 10."
MINUTES=10
elif (( MINUTES > 600 )); then
echo "::warning::QWEN_TRIAGE_TIMEOUT_MINUTES=${RAW} exceeds the 600-minute ceiling; clamping to 600."
MINUTES=600
fi
fi
else
echo "::warning::QWEN_TRIAGE_TIMEOUT_MINUTES='${RAW}' is not a bare positive integer of minutes; using the 60-minute default."
fi
fi
echo "triage_timeout_minutes=${MINUTES}" >> "${GITHUB_OUTPUT}"

- name: 'Check principal write permission'
id: 'perm'
env:
Expand Down Expand Up @@ -370,7 +429,23 @@ jobs:

triage:
needs: ['authorize']
timeout-minutes: 30
# TUNABLE WITHOUT A CODE CHANGE: set the repository variable in
# Settings → Variables. Why the fallback is 60: the fixed 30 was
# measurably clipping the distribution — 22 successful triage jobs
# sampled on 2026-08-09 ran median 5.8m / p90 22.3m / max 29.5m, and
# five substantial PRs (8723, 8726, 8731, 8764, 8801) died at exactly
# the cap, each discarding a full agent run. Triage is advisory, so
# the worst case a longer budget risks is one held runner; a killed
# run wastes the same runner AND the work. The value arrives via the
# authorize job's sanitize step (validated, clamped 10..600 — but
# GitHub-hosted runners hard-cap any job at 360 minutes, so values
# above 360 only take effect on the self-hosted pool): a
# malformed variable in a raw fromJSON(vars.X) would kill this job at
# expression time with no status comment. The || 60 covers the events
# where authorize is skipped (issues, plain-number dispatch) and its
# outputs are empty. Expression-valued timeout-minutes is
# probe-verified on a live runner (see #8731).
timeout-minutes: '${{ fromJSON(needs.authorize.outputs.triage_timeout_minutes || 60) }}'
concurrency:
# GitHub evaluates concurrency before the job `if`, but after `needs`.
# Keep non-runnable PR/comment triggers out of the shared per-number
Expand Down
130 changes: 129 additions & 1 deletion scripts/tests/qwen-triage-workflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { spawn, spawnSync } from 'node:child_process';
import { execFileSync, spawn, spawnSync } from 'node:child_process';
import {
existsSync,
mkdirSync,
Expand All @@ -17,6 +17,7 @@ import {
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';
import { parse } from 'yaml';

const workflow = readFileSync('.github/workflows/qwen-triage.yml', 'utf8');
const cacheProducerWorkflow = readFileSync(
Expand Down Expand Up @@ -5847,3 +5848,130 @@ describe('qwen-triage build-process guard', () => {
}
}, 30000);
});

describe('triage job budget', () => {
Comment thread
doudouOUC marked this conversation as resolved.
Resolved
// The fixed 30-minute cap was measurably clipping the distribution: 22
// successful triage jobs sampled on 2026-08-09 ran median 5.8m / p90
// 22.3m / max 29.5m, and five substantial PRs died at exactly the cap,
// each discarding a full agent run for nothing — triage is advisory, so
// a killed run wastes the runner AND the work it was about to publish.
// The budget is a repository variable so the next resize needs no PR;
// the fallback keeps an unconfigured repo bounded. Both halves pinned so
// neither the knob nor its default can silently vanish.
it('is operator-tunable through the sanitized authorize output', () => {
// Active lines only: a commented-out timeout line would satisfy a raw
// substring check while the job silently inherits GitHub's 360-minute
// default — the probe-verified evasion of the first version of this pin.
const active = (text) =>
text
.split('\n')
.filter((l) => !l.trimStart().startsWith('#'))
.join('\n');
expect(active(job('triage'))).toContain(
"timeout-minutes: '${{ fromJSON(needs.authorize.outputs.triage_timeout_minutes || 60) }}'",
);
expect(active(job('authorize'))).toContain(
"triage_timeout_minutes: '${{ steps.budget.outputs.triage_timeout_minutes }}'",
);
});

it('sanitizes the budget: integers clamp, garbage falls back with a warning', () => {
// The REAL sanitize step, replayed: timeout-minutes is evaluated before
// any step of the consuming job runs, so this bash is the only place a
// bad repository variable can be caught — and the knob's whole point is
// changing it without a PR, so nothing else reviews the value.
const doc = parse(workflow);
const budget = doc.jobs.authorize.steps.find((s) => s.id === 'budget');
expect(budget).toBeTruthy();
// The replay injects RAW itself, so pin the seams it cannot see: which
// repository variable feeds RAW (a typo'd name expands to '' and hits
// the silent default), and that the step is unconditional (a scoped
// step skips on comment events and '' || 60 kills the knob there).
expect(budget.env.RAW).toBe('${{ vars.QWEN_TRIAGE_TIMEOUT_MINUTES }}');
expect(budget.if).toBeUndefined();
const runBudget = (raw) => {
const dir = mkdtempSync(join(tmpdir(), 'budget-'));
try {
const outFile = join(dir, 'out');
writeFileSync(outFile, '');
const res = execFileSync('bash', ['-c', budget.run], {
encoding: 'utf8',
env: { ...process.env, RAW: raw, GITHUB_OUTPUT: outFile },
});
return {
out: readFileSync(outFile, 'utf8').trim(),
warned: res.includes('::warning::'),
log: res,
};
} finally {
rmSync(dir, { recursive: true, force: true });
}
};
// unset → default, silently
expect(runBudget('')).toMatchObject({
out: 'triage_timeout_minutes=60',
warned: false,
});
// a sane value passes through untouched
expect(runBudget('90')).toMatchObject({
out: 'triage_timeout_minutes=90',
warned: false,
});
// a padded value must stay decimal — without 10#, bash parses 060 as
// octal (48)
expect(runBudget('060')).toMatchObject({
out: 'triage_timeout_minutes=60',
warned: false,
});
// exactly at the boundaries: no clamp, no warning
expect(runBudget('10')).toMatchObject({
out: 'triage_timeout_minutes=10',
warned: false,
});
expect(runBudget('600')).toMatchObject({
out: 'triage_timeout_minutes=600',
warned: false,
});
// 0 would be an instantly-cancelled job — clamped to the floor
expect(runBudget('0')).toMatchObject({
out: 'triage_timeout_minutes=10',
warned: true,
});
// a runaway value would hold the runner for days — ceiling
expect(runBudget('3600')).toMatchObject({
out: 'triage_timeout_minutes=600',
warned: true,
});
// over 18 digits bash's 64-bit math wraps — 92233720368547758180
// lands on 100, silently in range — so the length guard must clamp
// to the ceiling with a warning instead
expect(runBudget('92233720368547758180')).toMatchObject({
out: 'triage_timeout_minutes=600',
warned: true,
});
// The guard counts SIGNIFICANT digits: leading zeros are decoration,
// so a padded 60 passes through untouched instead of tripping the
// ceiling branch, and an all-zero value is still 0 → floor
expect(runBudget('000000000000000000060')).toMatchObject({
out: 'triage_timeout_minutes=60',
warned: false,
});
expect(runBudget('0'.repeat(22))).toMatchObject({
out: 'triage_timeout_minutes=10',
warned: true,
});
// ...and padding must not defeat the wrap guard either: 19
// significant digits still clamp to the ceiling
expect(runBudget('000' + '9'.repeat(19))).toMatchObject({
out: 'triage_timeout_minutes=600',
warned: true,
});
// every malformed shape the review enumerated falls back and NAMES the
// variable, so the operator's run log points at the knob, not fromJSON
for (const bad of ['60 minutes', '1h', '6O', '60.5', '"60"']) {
const r = runBudget(bad);
expect(r.out, bad).toBe('triage_timeout_minutes=60');
expect(r.log, bad).toContain('QWEN_TRIAGE_TIMEOUT_MINUTES');
}
});
});
Loading