Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8d134b6
ci(review): size the review runner pool by time of day and skip uncha…
Sep 14, 2026
2b9d053
ci(review): cut the runner schedule to three variables and split out …
Sep 14, 2026
a657ddb
ci(review): no deployment record per schedule tick; fix the fallback …
Sep 14, 2026
a139230
ci(review): default the review pool to 17:00-05:00 and none by day
Sep 14, 2026
99a7b4b
ci(review): read the schedule only from repository variables
Sep 14, 2026
25abcc9
ci(review): default the schedule to 17:00-05:00 in the workflow
Sep 14, 2026
52e6ad4
fix(ci): fix review schedule lint and clarify equal-hour behavior
yiliang114 Sep 14, 2026
f4f8c1d
ci(review): switch the entire runner pool twice daily
yiliang114 Sep 14, 2026
7885757
fix(ci): skip offline runners during pool switches
yiliang114 Sep 14, 2026
61bc697
fix(ci): quote runner schedule input values
yiliang114 Sep 14, 2026
d102332
fix(ci): include hk1 in scheduled runner switches
yiliang114 Sep 14, 2026
45f8b30
fix(ci): add the pool label before removing the others
yiliang114 Sep 14, 2026
e282a89
fix(ci): preserve autofix capacity during review pool switches
yiliang114 Sep 15, 2026
e53c97a
fix(ci): correct the pool-switch comment and pin the never-started guard
yiliang114 Sep 15, 2026
27fa25c
test(ci): verify runner label switch failure ordering
yiliang114 Sep 15, 2026
702a9b4
fix(ci): post an accurate body when review-pr never got a runner
yiliang114 Sep 15, 2026
3a8a8a6
fix(ci): drop the af-099 design record its code deletion orphaned
yiliang114 Sep 15, 2026
9a58f67
fix(ci): fence the schedule job to main and pin the guards it relies on
yiliang114 Sep 15, 2026
d45b5d9
refactor(ci): round-2 review follow-ups
yiliang114 Sep 15, 2026
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
127 changes: 127 additions & 0 deletions .github/scripts/review-runner-schedule.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env node
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

// Switch all online hk1/hk2 runners between review and CI, twice a day.
// Offline runners are skipped; their labels stay unchanged.
// Running jobs finish normally; labels only control which job starts next.

import { execFile as execFileCallback } from 'node:child_process';
import { appendFileSync } from 'node:fs';
import { promisify } from 'node:util';

const execFile = promisify(execFileCallback);
const MANAGED_LABELS = ['ecs-review', 'ecs-qwen', 'ecs-agent'];
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved

export function planLabels(runners, mode) {
if (!['review', 'ci'].includes(mode)) {
throw new Error('mode must be review or ci');
}
const target = mode === 'review' ? 'ecs-review' : 'ecs-qwen';
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
return runners
.filter(
(r) => r.status === 'online' && /^ecs-qwen-hk[12]-\d+$/.test(r.name),
)
.flatMap((r) => {
const labels = r.labels.map((l) => l.name);
const remove = labels.filter(
(l) => MANAGED_LABELS.includes(l) && l !== target,
);
const add = labels.includes(target) ? [] : [target];
return add.length || remove.length
? [{ id: r.id, name: r.name, add, remove }]
: [];
});
}

async function gh(args) {
const { stdout } = await execFile('gh', args, {
env: { ...process.env, GH_TOKEN: process.env.RUNNER_ADMIN_TOKEN },
maxBuffer: 16 * 1024 * 1024,
});
return stdout;
}

async function main() {
const [repo, mode] = process.argv.slice(2);
if (!/^[\w.-]+\/[\w.-]+$/.test(repo ?? '')) {
throw new Error(
'usage: review-runner-schedule.mjs <owner/repo> <review|ci>',
);
}
planLabels([], mode);
if (!process.env.RUNNER_ADMIN_TOKEN) {
throw new Error(
'RUNNER_ADMIN_TOKEN is empty (needs Administration: write)',
);
}
const pages = JSON.parse(
await gh([
'api',
'--paginate',
'--slurp',
`repos/${repo}/actions/runners?per_page=100`,
]),
);
const runners = pages.flatMap((page) => page.runners);
if (!runners.some((r) => /^ecs-qwen-hk[12]-\d+$/.test(r.name))) {
throw new Error('no ecs-qwen-hk1-<n> or ecs-qwen-hk2-<n> runner found');
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
}
const actions = planLabels(runners, mode);
const results = await Promise.all(
actions.map(async ({ id, name, add, remove }) => {
try {
// Add before removing, so a failure can only leave the host in both
// pools. The reverse order lets a failed POST strand the host with
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
// no pool label at all — no job in either pool can match it until
// the next successful switch, which can be 12 hours away.
if (add.length) {
await gh([
'api',
'--method',
'POST',
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
`repos/${repo}/actions/runners/${id}/labels`,
...add.flatMap((l) => ['-f', `labels[]=${l}`]),
]);
}
for (const label of remove) {
await gh([
'api',
'--method',
'DELETE',
`repos/${repo}/actions/runners/${id}/labels/${label}`,
]);
}
return {
message: `- ${name}: ${[...remove.map((l) => `−${l}`), ...add.map((l) => `+${l}`)].join(' ')}`,
};
} catch (error) {
return {
failed: true,
message: `- ${name}: failed — ${error.message}`,
};
}
}),
);
const summary = [
`### hk1/hk2 runner pool: ${mode}`,
`- ${actions.length} runners to switch`,
...results.map((r) => r.message),
].join('\n');
console.log(summary);
if (process.env.GITHUB_STEP_SUMMARY) {
appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${summary}\n`);
}
const failures = results.filter((r) => r.failed).length;
if (failures) throw new Error(`${failures} runner label change(s) failed`);
}

if (process.argv[1]?.endsWith('review-runner-schedule.mjs')) {
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
main().catch((error) => {
console.error(`::error::${error.message}`);
process.exitCode = 1;
});
}
106 changes: 106 additions & 0 deletions .github/scripts/review-runner-schedule.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { describe, it } from 'node:test';
import { planLabels } from './review-runner-schedule.mjs';

const runner = (id, labels, extra = {}) => ({
id,
name: `ecs-qwen-hk2-${id}`,
labels: labels.map((name) => ({ name })),
status: 'online',
...extra,
});

describe('review runner schedule', () => {
it('switches online hk1 and hk2 runners, including busy runners', () => {
const runners = Array.from({ length: 32 }, (_, i) =>
runner(i + 1, ['ecs-qwen', 'ecs-agent', 'diagnostic'], {
name: `ecs-qwen-hk${(i % 2) + 1}-${i + 1}`,
busy: i % 2 === 0,
status: i < 2 ? 'offline' : 'online',
}),
);
const actions = planLabels(runners, 'review');
const onlineRunners = runners.filter(({ status }) => status === 'online');
assert.equal(actions.length, 30);
for (const [i, action] of actions.entries()) {
assert.deepEqual(action, {
id: onlineRunners[i].id,
name: onlineRunners[i].name,
add: ['ecs-review'],
remove: ['ecs-qwen', 'ecs-agent'],
});
}
assert.deepEqual(
actions.map(({ id }) => id),
onlineRunners.map(({ id }) => id),
);
});

it('returns every online review runner to CI and leaves unrelated runners alone', () => {
assert.deepEqual(
planLabels(
[
runner(1, ['ecs-review', 'diagnostic']),
runner(2, ['ecs-agent'], { name: 'ecs-qwen-hk1-2' }),
runner(3, ['ecs-review'], { name: 'ecs-qwen-hk2-3-extra' }),
runner(4, ['ecs-review'], { status: 'offline' }),
runner(5, ['ecs-review'], { name: 'ecs-qwen-hk3-5' }),
],
'ci',
),
[
{
id: 1,
name: 'ecs-qwen-hk2-1',
add: ['ecs-qwen'],
remove: ['ecs-review'],
},
{
id: 2,
name: 'ecs-qwen-hk1-2',
add: ['ecs-qwen'],
remove: ['ecs-agent'],
},
],
);
});

it('is idempotent and rejects invalid modes', () => {
assert.deepEqual(
planLabels([runner(1, ['ecs-review', 'diagnostic'])], 'review'),
[],
);
assert.deepEqual(planLabels([runner(1, ['ecs-qwen'])], 'ci'), []);
assert.throws(() => planLabels([], 'invalid'), /mode must be review or ci/);
});

it('wires two daily UTC switches and manual pool selection', () => {
const schedule = readFileSync(
new URL('../workflows/qwen-review-runner-schedule.yml', import.meta.url),
'utf8',
);
assert.deepEqual(
[...schedule.matchAll(/cron: '([^']+)'/g)].map((m) => m[1]),
['0 9 * * *', '0 21 * * *'],
);
assert.ok(
schedule.includes(
"github.event_name == 'workflow_dispatch' && inputs.pool",
),
);
assert.ok(
schedule.includes(
"github.event.schedule == '0 9 * * *' && 'review' || 'ci'",
),
);
assert.ok(schedule.includes('"$GITHUB_REPOSITORY" "$POOL"'));
assert.ok(schedule.includes('secrets.RUNNER_ADMIN_PAT'));
});
});
1 change: 1 addition & 0 deletions .github/workflows/.size-baseline
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
79041 qwen-fleet-shepherd.yml
22680 qwen-issue-followup-bot.yml
5760 qwen-pr-safety-precheck.yml
1958 qwen-review-runner-schedule.yml
27648 qwen-triage-finalize.yml
350381 qwen-triage.yml
9657 release-sdk-java.yml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ env:
# re-runs every suite after `npm ci`, and a push to main always classifies
# `full` (classify_pr computes a profile only for pull_request), so what
# the fast lane skips is still re-checked post-merge.
HELPER_TESTS_DEP_FREE: '.github/scripts/pr-safety-precheck.test.mjs .github/scripts/cap-release-notes.test.mjs .github/scripts/ci/classify-profile.test.mjs .github/scripts/ci/classify-platform-sensitivity.test.mjs .github/scripts/ci/classify-pr-profile.test.mjs .github/scripts/upsert-bot-comment.test.mjs .github/scripts/ci/main-failure-signature.test.mjs .github/scripts/dsw-swe-verified/make-manifest.test.mjs .github/scripts/dsw-swe-verified/make-terminal-bench-manifest.test.mjs .github/scripts/update-ecs-runner-qwen-workflow.test.mjs .github/scripts/web-shell-visuals-compose.test.mjs .github/scripts/serve-ab-diff.test.mjs .github/scripts/serve-ab-drive.test.mjs .github/scripts/autofix-status-heartbeat.test.mjs .github/scripts/check-disk-floor.test.mjs .github/scripts/check-lint-gate-freshness.test.mjs'
HELPER_TESTS: '.github/scripts/pr-safety-precheck.test.mjs .github/scripts/cap-release-notes.test.mjs .github/scripts/ci/classify-profile.test.mjs .github/scripts/ci/classify-platform-sensitivity.test.mjs .github/scripts/ci/classify-pr-profile.test.mjs .github/scripts/upsert-bot-comment.test.mjs .github/scripts/ci/main-failure-signature.test.mjs .github/scripts/classify-release-notes.test.mjs .github/scripts/dsw-swe-verified/make-manifest.test.mjs .github/scripts/dsw-swe-verified/make-terminal-bench-manifest.test.mjs .github/scripts/resolve-sandbox-image.test.mjs .github/scripts/update-ecs-runner-qwen-workflow.test.mjs .github/scripts/web-shell-visuals-publish.test.mjs .github/scripts/web-shell-visuals-compose.test.mjs .github/scripts/serve-ab-diff.test.mjs .github/scripts/serve-ab-drive.test.mjs .github/scripts/qwen-triage-workflow.test.mjs .github/scripts/assign-issue-owner.test.mjs .github/scripts/auto-minimize-spam.test.mjs .github/scripts/ci-runner-routing.test.mjs .github/scripts/autofix-status-heartbeat.test.mjs .github/scripts/assign-pr-owner.test.mjs .github/scripts/check-disk-floor.test.mjs .github/scripts/check-lint-gate-freshness.test.mjs .github/scripts/ci-disk-pressure.test.mjs .github/scripts/e2e-build.test.mjs integration-tests/concurrent-runner/export-html-from-chatrecord-jsonl.test.mjs'
HELPER_TESTS_DEP_FREE: '.github/scripts/pr-safety-precheck.test.mjs .github/scripts/cap-release-notes.test.mjs .github/scripts/ci/classify-profile.test.mjs .github/scripts/ci/classify-platform-sensitivity.test.mjs .github/scripts/ci/classify-pr-profile.test.mjs .github/scripts/upsert-bot-comment.test.mjs .github/scripts/ci/main-failure-signature.test.mjs .github/scripts/dsw-swe-verified/make-manifest.test.mjs .github/scripts/dsw-swe-verified/make-terminal-bench-manifest.test.mjs .github/scripts/update-ecs-runner-qwen-workflow.test.mjs .github/scripts/web-shell-visuals-compose.test.mjs .github/scripts/serve-ab-diff.test.mjs .github/scripts/serve-ab-drive.test.mjs .github/scripts/autofix-status-heartbeat.test.mjs .github/scripts/check-disk-floor.test.mjs .github/scripts/check-lint-gate-freshness.test.mjs .github/scripts/review-runner-schedule.test.mjs'
HELPER_TESTS: '.github/scripts/pr-safety-precheck.test.mjs .github/scripts/cap-release-notes.test.mjs .github/scripts/ci/classify-profile.test.mjs .github/scripts/ci/classify-platform-sensitivity.test.mjs .github/scripts/ci/classify-pr-profile.test.mjs .github/scripts/upsert-bot-comment.test.mjs .github/scripts/ci/main-failure-signature.test.mjs .github/scripts/classify-release-notes.test.mjs .github/scripts/dsw-swe-verified/make-manifest.test.mjs .github/scripts/dsw-swe-verified/make-terminal-bench-manifest.test.mjs .github/scripts/resolve-sandbox-image.test.mjs .github/scripts/update-ecs-runner-qwen-workflow.test.mjs .github/scripts/web-shell-visuals-publish.test.mjs .github/scripts/web-shell-visuals-compose.test.mjs .github/scripts/serve-ab-diff.test.mjs .github/scripts/serve-ab-drive.test.mjs .github/scripts/qwen-triage-workflow.test.mjs .github/scripts/assign-issue-owner.test.mjs .github/scripts/auto-minimize-spam.test.mjs .github/scripts/ci-runner-routing.test.mjs .github/scripts/autofix-status-heartbeat.test.mjs .github/scripts/assign-pr-owner.test.mjs .github/scripts/check-disk-floor.test.mjs .github/scripts/check-lint-gate-freshness.test.mjs .github/scripts/ci-disk-pressure.test.mjs .github/scripts/e2e-build.test.mjs integration-tests/concurrent-runner/export-html-from-chatrecord-jsonl.test.mjs .github/scripts/review-runner-schedule.test.mjs'
# The growth ratchet and its vitest mirror compare each workflow against
# the PR's base commit to tell "this PR grew the file" apart from "the
# baseline went stale on main" (#9904). Wired once here so every lane
Expand Down
19 changes: 18 additions & 1 deletion .github/workflows/qwen-code-pr-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ jobs:
# (default: 360); must stay above QWEN_REVIEW_MAX_TIMEOUT_MINUTES so
# retry plus posting never hit the cap.
timeout-minutes: '${{ fromJSON(vars.QWEN_REVIEW_JOB_TIMEOUT_MINUTES) }}'
runs-on: '${{ (github.repository == ''QwenLM/qwen-code'' && vars.MAINTAINER_ECS_RUNNER_DISABLED != ''true'') && fromJSON(''["self-hosted", "linux", "x64", "ecs-agent"]'') || fromJSON(''["ubuntu-latest"]'') }}'
# The schedule switches hk1/hk2 to `ecs-review` at 17:00 Asia/Shanghai
# and back to CI at 05:00. Reviews queue while the pool is closed.
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
runs-on: '${{ (github.repository == ''QwenLM/qwen-code'' && vars.MAINTAINER_ECS_RUNNER_DISABLED != ''true'') && fromJSON(''["self-hosted", "linux", "x64", "ecs-review"]'') || fromJSON(''["ubuntu-latest"]'') }}'
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
permissions:
contents: 'read'
pull-requests: 'write'
Expand Down Expand Up @@ -3152,6 +3154,21 @@ jobs:
echo "Could not determine the PR number; skipping fallback comment." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
# A review-pr job no runner ever picked up has no runner and no
# steps: GitHub ends a job queued for 24 hours (as failure or
# cancelled), and the `ecs-review` pool is closed by
# day (qwen-review-runner-schedule.yml). Nothing ran, so "the
# review pipeline failed" would be false; the PR's next push
# queues a fresh review. An unreadable job list keeps the comment
# (fail toward telling the author something).
if [ "$REVIEW_PR_RESULT" = "failure" ] || [ "$REVIEW_PR_RESULT" = "cancelled" ]; then
never_started="$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID:?}/jobs?per_page=100" \
--jq '[.jobs[] | select(.name == "review-pr")] | if length == 0 then "unknown" elif all(.[]; (.runner_name // "") == "" and ((.steps // []) | length) == 0) then "true" else "false" end' 2>/dev/null)" || never_started="unknown"
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
if [ "$never_started" = "true" ]; then
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
echo "Skipping fallback comment: review-pr in run ${GITHUB_RUN_ID} was never started by a runner (queue expired); no review ran." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
fi
# A push landing mid-review leaves this comment pointing at a dead
# run while a fresh review of the new head already queues (per-run
# concurrency groups are not cancelled by pushes). The run's head
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/qwen-review-runner-schedule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: 'Qwen Review Runner Schedule'

# Switch every online hk1/hk2 runner at 17:00 / 05:00 Asia/Shanghai.
# GitHub cron uses UTC. Manual runs can select either pool explicitly.
# Running jobs finish; only the labels for the next job change.
#
# RUNNER_ADMIN_PAT needs runner-label write access: repo scope for a
# classic PAT, or repository Administration: write for a fine-grained PAT.
# Store it in the environment below, restricted to `main`.
# To pause the schedule, disable this workflow.
Comment thread
yiliang114 marked this conversation as resolved.
Resolved

on:
schedule:
- cron: '0 9 * * *' # 17:00 Asia/Shanghai: enable reviews
- cron: '0 21 * * *' # 05:00 Asia/Shanghai: return to CI
workflow_dispatch:
inputs:
pool:
description: 'Pool for all online hk1/hk2 runners'
type: 'choice'
required: true
default: 'ci'
options:
- 'review'
- 'ci'

permissions:
contents: 'read'

concurrency:
group: 'qwen-review-runner-schedule'
cancel-in-progress: false

jobs:
converge:
if: "${{ github.repository == 'QwenLM/qwen-code' }}"
runs-on: 'ubuntu-latest'
timeout-minutes: 10
# deployment: false — the job needs the environment's secret, not a
# deployment record for a label switch.
environment:
name: 'qwen-review-runner-schedule'
deployment: false
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
steps:
- name: 'Checkout the schedule script'
uses: 'actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10' # v6.0.3
with:
persist-credentials: false
sparse-checkout: '.github/scripts/review-runner-schedule.mjs'
sparse-checkout-cone-mode: false

- name: 'Switch runner pool'
env:
RUNNER_ADMIN_TOKEN: '${{ secrets.RUNNER_ADMIN_PAT }}'
POOL: "${{ github.event_name == 'workflow_dispatch' && inputs.pool || (github.event.schedule == '0 9 * * *' && 'review' || 'ci') }}"
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
run: 'node .github/scripts/review-runner-schedule.mjs "$GITHUB_REPOSITORY" "$POOL"'
Loading
Loading