Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

The daily stable check sees important fixes again, and stops red if its token can't see pull requests (#9499)

Garry Tanfd2731b62285
diff --git a/.github/workflows/stable-daily.yml b/.github/workflows/stable-daily.yml
index 1057b7a94f..8939e1e411 100644
--- a/.github/workflows/stable-daily.yml
+++ b/.github/workflows/stable-daily.yml
@@ -43,6 +43,7 @@ permissions:
contents: write # push the stable-v<version> and stable tags and the stable-record branch (stable.json)
actions: write # read soak and upgrade matrix runs and their artifacts; dispatch a soak or the matrix
issues: read # find the upgrade matrix's open break issue, which holds stable
+ pull-requests: read # search merged stable:important PRs; without it the search returns no pull requests
concurrency:
group: promote-stable
diff --git a/changelog.d/capy-stable-daily-pr-search.md b/changelog.d/capy-stable-daily-pr-search.md
new file mode 100644
index 0000000000..dee3568987
--- /dev/null
+++ b/changelog.d/capy-stable-daily-pr-search.md
@@ -0,0 +1,5 @@
+**The daily stable check sees merged important fixes again, and stops with a clear error if it ever loses access to pull requests.**
+
+### Fixed
+- The daily stable check's GitHub token can read pull requests again. A recent permissions change had left it unable to see any pull request, so the search for merged `stable:important` fixes came back empty and the check reported nothing to promote.
+- Each run now logs how many labelled pull requests the search found. If the search sees no merged pull request at all, the check stops red and names the missing `pull-requests: read` permission instead of quietly reporting nothing.
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index 3e44d7ec89..e951b9a66a 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -895,7 +895,10 @@ and keeps stable between one day and one week behind what matters:
the weekly floor unless a maintainer promotes by hand. The rule: an
important fix reaches stable within a day once it passes the full gate and
soak; everything else rides a weekly cut; stable never sits more than seven
- days behind gated changes on master.
+ days behind gated changes on master. It finds those PRs with GitHub's
+ search, so the workflow's token needs `pull-requests: read`; each run logs
+ how many labelled PRs the search returned, and if the search sees no merged
+ PR at all the check stops red and names that permission.
- **Soak first.** The candidate is the newest release newer than stable whose
commit is on master and whose exact tree passed a successful
`STABLE_SOAK_WORKFLOW` run with the integrity gates (`privacy_leaks`,
diff --git a/docs/architecture/key-files/ci-health-and-test-guards.md b/docs/architecture/key-files/ci-health-and-test-guards.md
index 7f998907a0..4322d8175d 100644
--- a/docs/architecture/key-files/ci-health-and-test-guards.md
+++ b/docs/architecture/key-files/ci-health-and-test-guards.md
@@ -12,7 +12,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `scripts/ci-manifest.ts` — the versioned failure and execution manifest (`gbrain-ci-manifest/v1`). The `executed-receipts` job of test.yml and e2e.yml builds it from every lane's receipts (via `scripts/ci-executed-counts.ts`, declared skips from the expected-deltas TSV), binds it to the workflow, event, SHA, run id and attempt, and uploads it as `ci-manifest`; each failure carries the JUnit message (credentials redacted) and the stress gate's `failureSignature` (omitted when the message holds a credential); `checkManifest` refuses a manifest for another run or attempt; `passedFiles` lists files that executed tests and failed none. Docs: `docs/ci-red-runbook.md#ci-failure-manifest`.
- `scripts/release-gate.ts` — release.yml's `ci-gate` job. Polls the push-to-master runs of Test and E2E Tests on the release commit and writes `publish`/`sha`: both green publishes; a failed run publishes nothing and fails with the next step; a cancelled or skipped run publishes nothing and fails with `gh run rerun <id>` (master push runs are keyed by sha, and between releases many commits share one VERSION, so it never follows to a later commit); non-master refs are refused; a `workflow_dispatch` (`--event`) gates only the release commit (the first-parent commit that last changed VERSION) and refuses a later master HEAD with the re-run of that commit's push Release run; it fails with the backfill command after 110 minutes. Build, release, `latest-stable` and the publish jobs use the gated commit. Tests: `test/scripts/release-gate.test.ts`. Docs: `docs/RELEASING.md#release-ci-gate`.
- `.github/workflows/promote-stable.yml` + `scripts/promote-stable.ts` — stable channel promotion (`workflow_dispatch`: `version`, `soak_run_url`, `matrix_run_url`, `scoreboard_url`, `rollback`, `reason`, `withdraw`, `not_promotable`, `not_promotable_reason`, `not_promotable_fixed_in`, `not_promotable_remove`; concurrency group `promote-stable`). `promote()` refuses unless the actor's `role_name` is admin or maintain (`authorize()`; the one exception is `PromoteDeps.scheduled`, set by `scheduleAuthorized()` only for a schedule event of `stable-daily.yml` on the default branch, which also requires the release commit on master and records `promoted_by: schedule (.github/workflows/stable-daily.yml)`), `v<VERSION>` exists with a `VERSION` file naming it and a published (non-draft) GitHub release, the soak run URL names a completed, successful run of this repository's `STABLE_SOAK_WORKFLOW` workflow (repository variable; bare file name or path), the run's head commit has the release tag's exact tree (fetched when missing), `checkMatrix()` accepts the named upgrade matrix run only through `scripts/stable-matrix.ts` `judgeMatrixRun()` (a completed schedule or dispatch run of master's harness, full profile, no fault, whose `upgrade-matrix-receipt` names the release's tag, commit and tree and the run's own harness, and green; a scheduled promotion must name one, a maintainer may not and the record says `matrix_run: null`), and the version is newer than the current stable (the highest `v*` tag on `refs/tags/stable^{commit}`), or older with `rollback` and a reason. Re-promoting the current stable (no rollback) moves no tag: `recordCurrentStable()` writes `stable.json` from the stable tag's message (`parseTagMessage()`, which must name the same commit, tree and soak run) when the published record does not name that release, leasing `stable` unchanged and the record branch, and refuses as a no-op otherwise (GBRA-346 backfill for releases promoted before the record existed). It creates the immutable annotated `stable-v<VERSION>` record (refused when it exists, except on a rollback re-promotion of the same commit) and moves the annotated `stable` tag, both with `renderTagMessage()`'s `key: value` body, commits the evidence record (`renderRecord()`, `stable.json`, `known_bad` carried forward and merged with `withdraw` by `mergeKnownBad()`, `not_promotable` carried forward, added to and removed from by `mergeNotPromotable()`, which caps a reason at 500 characters; a record over `STABLE_RECORD_MAX_BYTES`, the client's `RECORD_MAX_BYTES`, is refused before the push) on the `stable-record` branch, then pushes all three in one `--atomic` push (`stable` and `stable-record` leased on the values it read, so a failed push changes nothing) and writes the step summary. Side effects come in through `PromoteDeps`. Tests: `test/scripts/promote-stable.test.ts`. Docs: `docs/RELEASING.md#stable-channel-promotion`.
-- `.github/workflows/stable-daily.yml` + `scripts/stable-daily.ts` — the daily stable check (05:17 and 13:17 UTC; dispatch defaults to `dry_run`, and `dry_run=false` needs admin or maintain; concurrency group `promote-stable`). Off when `STABLE_AUTO_PROMOTE` is `off`, paused while the stable record says `rollback: true`. Acts only on a reason: a merged `stable:important` PR released but not in stable, or stable older than `WEEKLY_FLOOR_DAYS` (7) with a newer release. Promotes, through `promote()`, the newest release on master newer than stable whose exact tree passed a full `SOAK_SHAPE` `STABLE_SOAK_WORKFLOW` run with every `INTEGRITY_GATES` gate passing in every cell (on the important-only path it must contain the fix), skipping a release with a `stable-v<version>` tag (stable before, then rolled back) or on stable.json's `known_bad` (#8792) or `not_promotable` list; the soaked candidate also needs a green upgrade matrix gate run on its exact tag and tree (`judgeMatrixRun`), and with none it dispatches `upgrade-matrix.yml` on master with `candidate=v<version>` (not while a matrix run is active); a red or foreign run returns `held`. While the matrix's own break issue is open (`findBreakIssue`: `ISSUE_MARKER`, not the label alone) it returns `held` unless a released fix's `changelog.d` fragment says `important: security` or `data-loss` (`BREAK_PASS_CLASSES`) and the candidate's run fails only on from-versions the issue's `red-from` line names. Otherwise dispatches one soak (and the matrix, when it has no run) on the newest release's tag, never while a soak runs or after a soak on a newer release failed to qualify. Tests: `test/scripts/stable-daily.test.ts`. Docs: `docs/RELEASING.md#daily-stable-check`.
+- `.github/workflows/stable-daily.yml` + `scripts/stable-daily.ts` — the daily stable check (05:17 and 13:17 UTC; dispatch defaults to `dry_run`, and `dry_run=false` needs admin or maintain; concurrency group `promote-stable`). Off when `STABLE_AUTO_PROMOTE` is `off`, paused while the stable record says `rollback: true`. Acts only on a reason: a merged `stable:important` PR released but not in stable (found through GitHub's search, so the workflow needs `pull-requests: read`; each run logs the labelled-PR count, and a search that sees no merged PR at all is a refusal naming that permission), or stable older than `WEEKLY_FLOOR_DAYS` (7) with a newer release. Promotes, through `promote()`, the newest release on master newer than stable whose exact tree passed a full `SOAK_SHAPE` `STABLE_SOAK_WORKFLOW` run with every `INTEGRITY_GATES` gate passing in every cell (on the important-only path it must contain the fix), skipping a release with a `stable-v<version>` tag (stable before, then rolled back) or on stable.json's `known_bad` (#8792) or `not_promotable` list; the soaked candidate also needs a green upgrade matrix gate run on its exact tag and tree (`judgeMatrixRun`), and with none it dispatches `upgrade-matrix.yml` on master with `candidate=v<version>` (not while a matrix run is active); a red or foreign run returns `held`. While the matrix's own break issue is open (`findBreakIssue`: `ISSUE_MARKER`, not the label alone) it returns `held` unless a released fix's `changelog.d` fragment says `important: security` or `data-loss` (`BREAK_PASS_CLASSES`) and the candidate's run fails only on from-versions the issue's `red-from` line names. Otherwise dispatches one soak (and the matrix, when it has no run) on the newest release's tag, never while a soak runs or after a soak on a newer release failed to qualify. Tests: `test/scripts/stable-daily.test.ts`. Docs: `docs/RELEASING.md#daily-stable-check`.
- `scripts/check-install-ref.ts` (`bun run check:install-ref`, in verify) — every install pin, bootstrap runbook fetch and setup-helper fetch in tracked files (not CHANGELOG.md or test/) names `INSTALL_REF` from `src/core/install-ref.ts`; exact `v<version>` and commit pins are left alone; TypeScript must import the constant; `--write` rewrites the text surfaces. `scripts/check-bootstrap-tag.sh` reads its sanctioned ref from the same constant. Tests: `test/install-ref.test.ts`.
- `scripts/regen-all.ts` — one entry point for every generated artifact (`ARTIFACTS`: regen and check command per artifact). `bun run regen:all` regenerates offline and keyless (provider keys and database URLs removed) and lists what changed; a second run changes nothing. `--check` is read-only and runs in `verify` as `check:regen-all`; `--goldens` also regenerates the offline contract goldens. Postgres goldens are named with their own commands, and `llms.txt` regenerates last because it inlines other generated docs. Every `bun test` it spawns (two checks and the goldens) carries `--timeout=60000` through one `BUN_TEST` prefix, because Bun does not apply bunfig.toml's `[test] timeout`. Tests: `test/scripts/regen-all.test.ts`.
- `scripts/build-behavior-changes.ts` — writes (or `--check`s) `src/core/behavior-changes.generated.ts` from `behavior-changes.d/<id>.md` and the `<!-- behavior-change: <id> -->` markers in released CHANGELOG sections (and in `changelog.d` fragments while VERSION is newer than the top heading, i.e. inside a release PR): `RELEASED_BEHAVIOR_CHANGES` rows dated by their section, `BEHAVIOR_CHANGE_RELEASES` for `releasedIn(id)` rows. Refuses unmarked files, dangling markers, duplicate ids, bad names, texts over 2,000 characters and a `changelog.d` fragment whose `bump:` is not `patch`. The release PR's `release_tool`; in `regen:all`. Tests: `test/scripts/build-behavior-changes.test.ts`.
diff --git a/scripts/stable-daily.ts b/scripts/stable-daily.ts
index 50c22dbae7..3d4d96dccf 100644
--- a/scripts/stable-daily.ts
+++ b/scripts/stable-daily.ts
@@ -193,9 +193,14 @@ export async function daily(deps: DailyDeps): Promise<DailyResult> {
const since = new Date((Number.isFinite(promotedAt) ? promotedAt : deps.now().getTime()) - 14 * DAY_MS).toISOString().slice(0, 10);
const q = `repo:${deps.repo} is:pr is:merged label:"${IMPORTANT_LABEL}" merged:>=${since}`;
- const found = await deps.ghApi(`search/issues?q=${encodeURIComponent(q)}&per_page=100`) as { items?: Array<{ number: number }> };
+ const labelled = ((await deps.ghApi(`search/issues?q=${encodeURIComponent(q)}&per_page=100`)) as { items?: Array<{ number: number }> }).items ?? [];
+ deps.log(`[stable-daily] the ${IMPORTANT_LABEL} search returned ${labelled.length} merged PR${labelled.length === 1 ? '' : 's'} since ${since}.`);
+ if (labelled.length === 0) {
+ const any = (await deps.ghApi(`search/issues?q=${encodeURIComponent(`repo:${deps.repo} is:pr is:merged`)}&per_page=1`)) as { items?: unknown[] };
+ if ((any.items ?? []).length === 0) throw new Refusal(`the pull-request search sees no merged pull request at all in ${deps.repo}, so this token cannot read pull requests and every ${IMPORTANT_LABEL} fix would be missed; give the workflow's GITHUB_TOKEN \`pull-requests: read\` (.github/workflows/stable-daily.yml permissions).`);
+ }
const important: Array<{ pr: number; version: string; passesBreak: boolean }> = [];
- for (const { number } of found.items ?? []) {
+ for (const { number } of labelled) {
const pr = await deps.ghApi(`repos/${deps.repo}/pulls/${number}`) as { merge_commit_sha?: string | null };
const sha = pr.merge_commit_sha;
if (!sha || (await treeOf(deps, sha)) === null || await isAncestor(deps, sha, stableCommit)) continue;
diff --git a/test/scripts/stable-daily.test.ts b/test/scripts/stable-daily.test.ts
index 1882aaa197..dda90fdd12 100644
--- a/test/scripts/stable-daily.test.ts
+++ b/test/scripts/stable-daily.test.ts
@@ -43,6 +43,8 @@ interface World {
stable: { version: string; commit: number; message: string };
/** `important`: the class its changelog.d fragment's front matter names. */
importantPrs?: Array<{ number: number; merge: number; important?: string }>;
+ /** The token sees no pull request at all, as a GITHUB_TOKEN without pull-requests: read does. */
+ prsHidden?: boolean;
runs?: Array<SoakRunRow & { boards?: Scoreboard[] }>;
/** Upgrade matrix runs, newest first; default: one green gate run on every release (MATRIX_ID + its commit). */
matrix?: Array<MatrixRunRow & { receipt?: MatrixReceipt | null }>;
@@ -141,7 +143,11 @@ function world(w: World) {
dryRun: w.dryRun ?? false,
async ghApi(path) {
api.push(path);
- if (path.startsWith('search/issues')) return { items: (w.importantPrs ?? []).map(p => ({ number: p.number })) };
+ if (path.startsWith('search/issues')) {
+ if (w.prsHidden) return { total_count: 0, items: [] };
+ if (!decodeURIComponent(path).includes('label:')) return { total_count: 1, items: [{ number: 1 }] };
+ return { items: (w.importantPrs ?? []).map(p => ({ number: p.number })) };
+ }
if (path.includes('/issues?')) return w.breakIssues ?? [];
if (path.includes('/actions/workflows/upgrade-matrix.yml/runs')) {
const q = new URLSearchParams(path.split('?')[1] ?? '');
@@ -282,6 +288,22 @@ describe('daily: when it does nothing', () => {
expect(w.posts).toEqual([]);
});
+ test('a quiet fortnight with no labelled PR stays none, and the check logs how many labelled PRs the search returned', async () => {
+ const w = world(base({ runs: [soak(9, 4)] }));
+ expect((await daily(w.deps)).action).toBe('none');
+ expect(w.logs.some(l => /stable:important search returned 0 merged PRs/.test(l))).toBe(true);
+ const found = world(base({ importantPrs: [{ number: 11, merge: 1 }], runs: [soak(9, 4)] }));
+ await daily(found.deps);
+ expect(found.logs.some(l => /stable:important search returned 1 merged PR\b/.test(l))).toBe(true);
+ });
+
+ test('a token that sees no merged pull request at all stops the check and names the missing pull-requests: read permission', async () => {
+ const w = world(base({ prsHidden: true, runs: [soak(9, 4)] }));
+ await expect(daily(w.deps)).rejects.toThrow(/pull-requests: read/);
+ expect(w.pushes).toEqual([]);
+ expect(w.posts).toEqual([]);
+ });
+
test('an important fix already in stable, or not released yet, is no reason', async () => {
const inStable = world(base({ importantPrs: [{ number: 11, merge: 1 }], runs: [soak(9, 4)] }));
expect((await daily(inStable.deps)).action).toBe('none');
@@ -659,7 +681,7 @@ describe('stable-daily.yml', () => {
expect(Object.keys(wf.on).sort()).toEqual(['schedule', 'workflow_dispatch']);
expect(wf.on.schedule.map(s => s.cron)).toEqual(['17 5 * * *', '17 13 * * *']);
expect(wf.on.workflow_dispatch.inputs.dry_run).toMatchObject({ type: 'boolean', default: true });
- expect(wf.permissions).toEqual({ contents: 'write', actions: 'write', issues: 'read' });
+ expect(wf.permissions).toEqual({ contents: 'write', actions: 'write', issues: 'read', 'pull-requests': 'read' });
expect(wf.concurrency).toEqual({ group: 'promote-stable', 'cancel-in-progress': false });
});