Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: pre-landing review fixes
garrytanc5b04db2596a
diff --git a/.github/workflows/promote-stable.yml b/.github/workflows/promote-stable.ymlindex 68e657d68c..97867329fb 100644--- a/.github/workflows/promote-stable.yml+++ b/.github/workflows/promote-stable.yml@@ -70,6 +70,11 @@ on:required: falsetype: stringdefault: ''+ not_promotable_remove:+ description: Versions to take off the not_promotable list, comma-separated+ required: false+ type: string+ default: ''permissions:contents: write # create and push the stable-v<version> and stable tags and the stable-record branch@@ -105,6 +110,7 @@ jobs:PROMOTE_NOT_PROMOTABLE: ${{ inputs.not_promotable }}PROMOTE_NOT_PROMOTABLE_REASON: ${{ inputs.not_promotable_reason }}PROMOTE_NOT_PROMOTABLE_FIXED_IN: ${{ inputs.not_promotable_fixed_in }}+ PROMOTE_NOT_PROMOTABLE_REMOVE: ${{ inputs.not_promotable_remove }}run: |git config user.name "gbrain-release-bot"git config user.email "41898282+github-actions[bot]@users.noreply.github.com"diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e3e53f70e8..334d5614a6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,7 +24,7 @@ The upgrade restarted autopilot only through an installed launchd or systemd ser**The daily stable check no longer sticks on a rolled-back release.** A release that was stable before (its `stable-v<version>` record tag exists) or that `stable.json` lists in `known_bad` is skipped and logged, so the newest release gets its soak instead of a refused promotion on every scheduled run (#8792).-**A release can be marked not promotable when it soaked clean but is known bad from outside evidence.** Dispatch `promote-stable.yml` for the current stable with `not_promotable`, `not_promotable_reason` and `not_promotable_fixed_in`. The stable record gains a `not_promotable` list, and no tag moves. The daily check never soaks or promotes a release on it, on the important path and the weekly floor alike, and a manual promotion of one is refused. Clients ignore the list, so unlike `withdraw` it moves no install to another release.+**A release can be marked not promotable when it soaked clean but is known bad from outside evidence.** Dispatch `promote-stable.yml` for the current stable with `not_promotable`, `not_promotable_reason` and `not_promotable_fixed_in`. The stable record gains a `not_promotable` list, and no tag moves. The daily check never soaks or promotes a release on it, on the important path and the weekly floor alike, and a manual promotion of one is refused. Clients ignore the list, so unlike `withdraw` it moves no install to another release. `not_promotable_remove` takes a release off the list. A reason over 500 characters is refused, and so is a record larger than clients accept; nothing is pushed in either case.## [0.60.655.0] - 2026-11-10diff --git a/docs/RELEASING.md b/docs/RELEASING.mdindex c3d9057294..5f3aca2c60 100644--- a/docs/RELEASING.md+++ b/docs/RELEASING.md@@ -626,8 +626,8 @@ gh workflow run promote-stable.yml -f version=<VERSION> \`rollback` (default false), `reason` (required with rollback) and`withdraw` (versions added to the carried-forward `known_bad` list;clients on one are offered the current stable, even when older), and- `not_promotable` with `not_promotable_reason` and `not_promotable_fixed_in`- (see below).+ `not_promotable` with `not_promotable_reason` and `not_promotable_fixed_in`,+ and `not_promotable_remove` (see below).- **Not promotable.** A release can soak clean and still be bad, when theevidence comes from outside the soak (a regression found on a large brain,say). Record it so the daily check never soaks or promotes it: dispatch this@@ -636,8 +636,12 @@ gh workflow run promote-stable.yml -f version=<VERSION> \`not_promotable_reason` saying why and `not_promotable_fixed_in` naming thenewer release that fixes them. The list is carried forward on every laterrecord, and `promote()` refuses a release on it. Clients never read it, so- unlike `withdraw` it offers nobody a different release. Use `withdraw`- only for a release that was stable, so its installs move off it:+ unlike `withdraw` it offers nobody a different release. To take a release+ off the list (one listed by mistake), pass it in `not_promotable_remove` the+ same way. A reason is at most 500 characters (link the evidence), and a+ record larger than clients accept (64 KiB) is refused before anything is+ pushed. Use `withdraw` only for a release that was stable, so its installs+ move off it:```bashgh workflow run promote-stable.yml -f version=<current stable> -f soak_run_url=<its soak run> \diff --git a/docs/architecture/key-files/ci-health-and-test-guards.md b/docs/architecture/key-files/ci-health-and-test-guards.mdindex 4c7726e1a1..90bfdda8d0 100644--- a/docs/architecture/key-files/ci-health-and-test-guards.md+++ b/docs/architecture/key-files/ci-health-and-test-guards.md@@ -10,8 +10,8 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `scripts/lib/ci-run.ts` — one run's failure evidence (`collectEvidence`): jobs, failing jobs' annotations and, for test.yml and e2e.yml, the `ci-manifest` artifact, returned as structured records (job, step, every failing test file and identity) apart from sanitized excerpts; a cancelled job is not run (listed in `cancelled`) unless its annotation says it timed out, and a red run whose only failures are aggregators of cancelled jobs is `ignored`; with `complete`/`problems` (an unreadable page, annotation or manifest is incomplete evidence, never zero failures). A push run with a succeeded `reused-full-suite` job is judged by the run its `reuse.json` names (`checkRecord` from `scripts/ci-reuse.ts`, recorded attempt, identical commit tree): that run's succeeded jobs and complete `ci-manifest` stand in for the push, and any gap is incomplete. `reproduceCommand` builds `bun run test:stress <file> --iterations 10 [--postgres]` from a validated test path only. `exemptionRows` turns failing identities with an exact test name and signature into the stress gate's `<!-- gbrain-stress-exemption -->` records (backend per `stressBackend`, owner `agent on release duty`), written into master-red, flake and nightly-red bodies; `test/fixtures/nightly-watch/stress-exemption-contract.ts` vendors the gate's parser so the tests prove it accepts them.- `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 run cancelled by a newer push is followed to the next master commit with the same VERSION (published there) or marks the version superseded; non-master refs are refused; 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`, `scoreboard_url`, `rollback`, `reason`, `withdraw`; 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), 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()`) 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); otherwise dispatches one soak 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/promote-stable.yml` + `scripts/promote-stable.ts` — stable channel promotion (`workflow_dispatch`: `version`, `soak_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), 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; otherwise dispatches one soak 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/release-restamp.ts` + `scripts/lib/restamp.ts` — `bun run release:restamp`, run when a PR is next to merge. The CLI refuses a dirty tree, fetches `origin/master`, captures the branch CHANGELOG entry and migration inventory, merges master with a merge commit (version-only stamp hunks, `CHANGELOG.md` and the `GENERATED_PATHS` files resolve mechanically; anything else stops), sets VERSION to master's PATCH + 1, renumbers branch-only migrations from master's latest + 1 (filename, export name and `version:` literal only; `migrationPayloadKey` proves the rest is token-identical and refuses a copy of a published migration or an edited published one), rewrites `STAMPS` (the CLAUDE.md "Version locations" Required rows) plus CHANGELOG and TODOS, runs `DEFAULT_STEPS`, lists branch-added lines that still name an old number (`findLeftoverRefs`, never rewritten), runs `DEFAULT_CHECKS` and commits once. Stops save `.git/gbrain-restamp.json` for `--continue` / `--abort`; `--dry-run` prints the plan, `--no-commit` stages. Generators run through `offlineEnv` (no database URLs, no provider keys). Tests: `test/scripts/release-restamp.test.ts` (fixture repos with the real migration generator; also pins CLAUDE.md table coverage and docs anchors).diff --git a/scripts/promote-stable.ts b/scripts/promote-stable.tsindex 08c00a593a..af63ccb364 100644--- a/scripts/promote-stable.ts+++ b/scripts/promote-stable.ts@@ -72,11 +72,17 @@ export interface PromoteInputs {withdraw?: string[];/** Releases to add to the record's not_promotable list: stable-daily never soaks or promotes them; clients never read it. */notPromotable?: NotPromotable[];+ /** Releases to take off the record's not_promotable list (one listed by mistake, say). */+ notPromotableRemove?: string[];}/** A release outside evidence shows is bad although it may soak clean, with the release that fixes it. */export interface NotPromotable { version: string; reason: string; fixed_in: string }+/** The largest stable.json clients accept (src/core/stable-channel.ts RECORD_MAX_BYTES; a test pins the two). */+export const STABLE_RECORD_MAX_BYTES = 64 * 1024;+const NOT_PROMOTABLE_REASON_MAX = 500;+export interface GitResult { code: number; stdout: string; stderr: string }export interface PromoteDeps {@@ -144,14 +150,20 @@ export function mergeKnownBad(previous: readonly string[], withdraw: readonly streturn all;}-/** The previous record's not_promotable plus this run's entries (a new entry replaces one for its version), sorted; refuses one naming the promoted version. */-export function mergeNotPromotable(previous: readonly NotPromotable[], add: readonly NotPromotable[], version: string): NotPromotable[] {+/** The previous record's not_promotable minus `remove`, plus this run's entries (a new entry replaces one for its version), sorted; refuses one naming the promoted version. */+export function mergeNotPromotable(previous: readonly NotPromotable[], add: readonly NotPromotable[], version: string, remove: readonly string[] = []): NotPromotable[] {+ for (const v of remove) {+ if (add.some(e => e.version === v)) throw new Refusal(`v${v} is both added to and removed from the not_promotable list; pass it in one of not_promotable or not_promotable_remove.`);+ if (!previous.some(e => e.version === v)) throw new Refusal(`v${v} is not on the not_promotable list, so there is nothing to remove; check the version against stable.json on stable-record.`);+ }for (const e of add) {if (!VERSION_RE.test(e.version)) throw new Refusal(`not_promotable entry "${e.version}" is not a release version; pass versions like 0.60.649.0, comma-separated.`);if (!VERSION_RE.test(e.fixed_in) || compareVersions(e.fixed_in, e.version) <= 0) throw new Refusal(`not_promotable v${e.version} needs fixed_in: the newer release that carries the fix, like 0.60.652.0 (got "${e.fixed_in}").`);if (!e.reason.trim()) throw new Refusal(`not_promotable v${e.version} needs a reason: say what shows the release is bad.`);+ const length = e.reason.trim().replace(/\s+/g, ' ').length;+ if (length > NOT_PROMOTABLE_REASON_MAX) throw new Refusal(`not_promotable v${e.version}'s reason is ${length} characters; keep it to ${NOT_PROMOTABLE_REASON_MAX} (link the evidence instead of pasting it).`);}- const byVersion = new Map(previous.map(e => [e.version, e]));+ const byVersion = new Map(previous.filter(e => !remove.includes(e.version)).map(e => [e.version, e]));for (const e of add) byVersion.set(e.version, { version: e.version, reason: e.reason.trim().replace(/\s+/g, ' '), fixed_in: e.fixed_in });const all = [...byVersion.values()].sort((a, b) => compareVersions(a.version, b.version));const own = all.find(e => e.version === version);@@ -348,7 +360,10 @@ export async function readPriorRecord(deps: PromoteDeps): Promise<PriorRecord |/** Commit stable.json for `fields` on top of the previous record commit (none before the first record). */async function commitRecord(deps: PromoteDeps, fields: TagFields, knownBad: string[], notPromotable: NotPromotable[], parent: string | null): Promise<string> {- const blob = await gitOut(deps, ['hash-object', '-w', '--stdin'], 'Could not write the stable record blob; re-run this workflow.', renderRecord(fields, knownBad, notPromotable));+ const record = renderRecord(fields, knownBad, notPromotable);+ const bytes = Buffer.byteLength(record);+ if (bytes > STABLE_RECORD_MAX_BYTES) throw new Refusal(`stable.json would be ${bytes} bytes, over the ${STABLE_RECORD_MAX_BYTES} clients accept, so nothing was pushed; shorten the not_promotable reasons or take old entries off with not_promotable_remove.`);+ const blob = await gitOut(deps, ['hash-object', '-w', '--stdin'], 'Could not write the stable record blob; re-run this workflow.', record);const recordTree = await gitOut(deps, ['mktree'], 'Could not write the stable record tree; re-run this workflow.', `100644 blob ${blob}\t${RECORD_FILE}\n`);const recordCommit = await gitOut(deps, ['commit-tree', recordTree, ...(parent ? ['-p', parent] : []), '-m', `stable record: v${fields.version}`],'Could not commit the stable record; re-run this workflow.');@@ -374,7 +389,7 @@ async function recordCurrentStable(deps: PromoteDeps, inputs: PromoteInputs, relconst prior = await readPriorRecord(deps);const knownBad = mergeKnownBad(prior?.knownBad ?? [], inputs.withdraw ?? [], version);- const notPromotable = mergeNotPromotable(prior?.notPromotable ?? [], inputs.notPromotable ?? [], version);+ const notPromotable = mergeNotPromotable(prior?.notPromotable ?? [], inputs.notPromotable ?? [], version, inputs.notPromotableRemove ?? []);const sameNotPromotable = JSON.stringify(notPromotable) === JSON.stringify(mergeNotPromotable(prior?.notPromotable ?? [], [], version));if (prior && prior.version === version && prior.releaseCommit === commit && knownBad.length === new Set(prior.knownBad).size && sameNotPromotable) {throw new Refusal(`${already}, and stable.json on stable-record records it, so there is nothing to promote.`);@@ -455,7 +470,7 @@ export async function promote(deps: PromoteDeps, inputs: PromoteInputs): Promiseconst prior = await readPriorRecord(deps);const priorRecordCommit = prior?.commit ?? null;const knownBad = mergeKnownBad(prior?.knownBad ?? [], inputs.withdraw ?? [], version);- const notPromotable = mergeNotPromotable(prior?.notPromotable ?? [], inputs.notPromotable ?? [], version);+ const notPromotable = mergeNotPromotable(prior?.notPromotable ?? [], inputs.notPromotable ?? [], version, inputs.notPromotableRemove ?? []);const recordCommit = await commitRecord(deps, fields, knownBad, notPromotable, priorRecordCommit);if (!recordExists) {@@ -508,6 +523,7 @@ if (import.meta.main) {withdraw: (env.PROMOTE_WITHDRAW ?? '').split(',').map(v => v.trim().replace(/^v/, '')).filter(Boolean),notPromotable: (env.PROMOTE_NOT_PROMOTABLE ?? '').split(',').map(v => v.trim().replace(/^v/, '')).filter(Boolean).map(version => ({ version, reason: env.PROMOTE_NOT_PROMOTABLE_REASON ?? '', fixed_in: (env.PROMOTE_NOT_PROMOTABLE_FIXED_IN ?? '').trim().replace(/^v/, '') })),+ notPromotableRemove: (env.PROMOTE_NOT_PROMOTABLE_REMOVE ?? '').split(',').map(v => v.trim().replace(/^v/, '')).filter(Boolean),};const deps = processDeps();try {diff --git a/src/commands/doctor/checks/upgrade-health.ts b/src/commands/doctor/checks/upgrade-health.tsindex 8336c582f1..679ff72d90 100644--- a/src/commands/doctor/checks/upgrade-health.ts+++ b/src/commands/doctor/checks/upgrade-health.ts@@ -189,7 +189,7 @@ export function checkSelfUpgradeHealth(restart?: RestartPlan | null): Check {const blockers = (restart?.manual ?? []).filter((m) => !(m.role === 'mcp' && m.argv[0] === 'kill'));if (blockers.length) {- const autopilot = blockers.find((m) => m.role === 'autopilot');+ const autopilot = blockers.find((m) => m.role === 'autopilot' && m.argv[0] === 'gbrain');return {name: 'self_upgrade_health',status: 'warn',diff --git a/src/core/stable-channel.ts b/src/core/stable-channel.tsindex d005bdb35d..5e44316968 100644--- a/src/core/stable-channel.ts+++ b/src/core/stable-channel.ts@@ -20,7 +20,7 @@ const GBRAIN_GIT_URL = `https://github.com/${REPO_SLUG}`;export const STABLE_RECORD_BRANCH = 'stable-record';export const STABLE_RECORD_FILE = 'stable.json';export const STABLE_RECORD_URL = `https://raw.githubusercontent.com/${REPO_SLUG}/${STABLE_RECORD_BRANCH}/${STABLE_RECORD_FILE}`;-const RECORD_MAX_BYTES = 64 * 1024;+export const RECORD_MAX_BYTES = 64 * 1024;const STABLE_ERRORS_DOCS = 'docs/guides/upgrades-auto-update.md#stable-channel-errors';const SHA_RE = /^[0-9a-f]{40}$/;const RUN_URL_RE = /^https:\/\/github\.com\/garrytan\/gbrain\/actions\/runs\/\d+(\/attempts\/\d+)?\/?$/;diff --git a/src/core/upgrade-restart.ts b/src/core/upgrade-restart.tsindex 05eb833415..aba7d1540d 100644--- a/src/core/upgrade-restart.ts+++ b/src/core/upgrade-restart.ts@@ -320,6 +320,7 @@ export function planRestart(processes: readonly HostProcess[], ctx: RestartConteif (runsUnder(p, ctx.autopilotService)) addService('autopilot', p.pid);else if (launcherOf(p)) addHandoff(p, launcherOf(p)!);else if (ctx.autopilotLauncher?.pid === p.pid) kill(p, `${label(p)} is known only from its heartbeat row (the process table could not be read), so the upgrade cannot confirm it is the process to stop before handing autopilot to its launcher: stop it (\`kill ${p.pid}\`) and let the launcher start it again, then run the upgrade.`);+ else if (ctx.autopilotLauncher) kill(p, `${label(p)} is not the daemon this brain's autopilot lock names (it names ${ctx.autopilotLauncher.pid === null ? 'no running autopilot' : `pid ${ctx.autopilotLauncher.pid}`}), so the upgrade does not hand it to ${launcherName(ctx.autopilotLauncher)}: if it is this brain's autopilot, stop it (\`kill ${p.pid}\`) and let the launcher start it again, then run the upgrade; if it serves another brain, upgrade from that brain.`);else manual.push({ role: p.role, pid: p.pid, version: p.version, argv: ['gbrain', 'autopilot', '--install'],instruction: `${label(p)} was started outside gbrain's autopilot service (by a cron entry, a wrapper or by hand), so the upgrade cannot restart it. `+ 'Either run `gbrain autopilot --install`, which runs autopilot under launchd, systemd or a gbrain cron line so every upgrade restarts it (retire the launcher that starts it now first, or both race for the autopilot lock), 'diff --git a/test/scripts/promote-stable.test.ts b/test/scripts/promote-stable.test.tsindex f058bbddf0..543a14a258 100644--- a/test/scripts/promote-stable.test.ts+++ b/test/scripts/promote-stable.test.ts@@ -19,10 +19,11 @@ import { tmpdir } from 'node:os';import { join } from 'node:path';import { load } from 'js-yaml';import {- checkOrder, checkSoakRun, compareVersions, mergeKnownBad, mergeNotPromotable, normaliseWorkflowPath, parseRunUrl, parseTagMessage, processDeps, promote, Refusal, renderRecord, renderSummary, renderTagMessage,+ checkOrder, checkSoakRun, compareVersions, mergeKnownBad, mergeNotPromotable, normaliseWorkflowPath, parseRunUrl, parseTagMessage, processDeps, promote, Refusal, renderRecord, renderSummary, renderTagMessage, STABLE_RECORD_MAX_BYTES,type GitResult, type PromoteDeps, type PromoteInputs, type SoakRun, type TagFields,} from '../../scripts/promote-stable.ts';import { offeredVersion } from '../../src/core/self-upgrade.ts';+import { RECORD_MAX_BYTES } from '../../src/core/stable-channel.ts';import { parseStableRecord } from '../../src/core/stable-channel.ts';const ROOT = join(import.meta.dir, '..', '..');@@ -438,6 +439,29 @@ describe('evidence record (GBRA-224 W1)', () => {expect(corrupt.calls.filter(c => c.startsWith('push'))).toEqual([]);});+ test('a reason over 500 characters is refused, and a record over the size clients accept is refused before anything is pushed', async () => {+ expect(STABLE_RECORD_MAX_BYTES).toBe(RECORD_MAX_BYTES);+ refused(() => mergeNotPromotable([], [{ ...bad('0.60.362.0'), reason: 'x'.repeat(501) }], '0.60.361.0'), /reason is 501 characters; keep it to 500/);+ expect(mergeNotPromotable([], [{ ...bad('0.60.362.0'), reason: 'x'.repeat(500) }], '0.60.361.0')).toHaveLength(1);+ const big = harness();+ const many = Array.from({ length: 200 }, (_, i) => ({ version: '0.59.' + i + '.0', reason: 'y'.repeat(400), fixed_in: '0.60.365.0' }));+ big.repo.records = { 'rec-prior': JSON.stringify({ schema: 1, version: '0.60.360.0', known_bad: [], not_promotable: many }) };+ big.repo.recordBranch = 'rec-prior';+ await refusedAsync(promote(big.deps, inputs()), /stable\.json would be \d+ bytes, over the 65536 clients accept/);+ expect(big.calls.filter(c => c.startsWith('push'))).toEqual([]);+ });++ test('not_promotable_remove takes a listed release off the list, so it can be promoted; a version not on the list is refused', async () => {+ expect(mergeNotPromotable([bad('0.60.362.0'), bad('0.60.363.0')], [], '0.60.361.0', ['0.60.362.0'])).toEqual([bad('0.60.363.0')]);+ refused(() => mergeNotPromotable([bad('0.60.362.0')], [], '0.60.361.0', ['0.60.364.0']), /v0\.60\.364\.0 is not on the not_promotable list/);+ refused(() => mergeNotPromotable([bad('0.60.362.0')], [bad('0.60.362.0')], '0.60.361.0', ['0.60.362.0']), /both added to and removed from/);+ const h = harness();+ h.repo.records = { 'rec-prior': JSON.stringify({ schema: 1, version: '0.60.360.0', known_bad: [], not_promotable: [bad('0.60.361.0'), bad('0.60.363.0')] }) };+ h.repo.recordBranch = 'rec-prior';+ await promote(h.deps, inputs({ notPromotableRemove: ['0.60.361.0'] }));+ expect(JSON.parse(h.repo.records![h.repo.recordBranch!]!)).toMatchObject({ version: '0.60.361.0', not_promotable: [bad('0.60.363.0')] });+ });+test('a client reads a record carrying not_promotable exactly as one without it: a client on a listed release is offered nothing, never a downgrade', () => {const fields: TagFields = {version: '0.60.361.0', commit: sha('b'), tree: sha('2'), soakRun: RUN_URL, scoreboard: RUN_URL,@@ -596,6 +620,8 @@ describe('stable.json bridge for a stable promoted before the evidence record (Gawait refusedAsync(promote(h.deps, inputs({ notPromotable: [bad('0.60.362.0')] })), /already the stable release, and stable\.json on stable-record records it/);await promote(h.deps, inputs({ withdraw: ['0.60.355.0'] }));expect(JSON.parse(h.repo.records![h.repo.recordBranch!]!)).toMatchObject({ known_bad: ['0.60.355.0'], not_promotable: [bad('0.60.362.0'), bad('0.60.363.0')] });+ await promote(h.deps, inputs({ notPromotableRemove: ['0.60.363.0'] }));+ expect(JSON.parse(h.repo.records![h.repo.recordBranch!]!)).toMatchObject({ known_bad: ['0.60.355.0'], not_promotable: [bad('0.60.362.0')] });});test('a record left behind by a later record-less promotion is brought up to the stable tag, keeping known_bad', async () => {@@ -699,8 +725,8 @@ describe('promote-stable.yml', () => {test('dispatch only, with the decided inputs, one serial group and scoped permissions', () => {expect(Object.keys(wf.on)).toEqual(['workflow_dispatch']);const i = wf.on.workflow_dispatch!.inputs;- expect(Object.keys(i)).toEqual(['version', 'soak_run_url', 'scoreboard_url', 'rollback', 'reason', 'withdraw', 'not_promotable', 'not_promotable_reason', 'not_promotable_fixed_in']);- for (const k of ['withdraw', 'not_promotable', 'not_promotable_reason', 'not_promotable_fixed_in']) expect(i[k]).toMatchObject({ required: false, type: 'string', default: '' });+ expect(Object.keys(i)).toEqual(['version', 'soak_run_url', 'scoreboard_url', 'rollback', 'reason', 'withdraw', 'not_promotable', 'not_promotable_reason', 'not_promotable_fixed_in', 'not_promotable_remove']);+ for (const k of ['withdraw', 'not_promotable', 'not_promotable_reason', 'not_promotable_fixed_in', 'not_promotable_remove']) expect(i[k]).toMatchObject({ required: false, type: 'string', default: '' });expect([i.version!.required, i.soak_run_url!.required, i.scoreboard_url!.required]).toEqual([true, true, false]);expect(i.rollback).toMatchObject({ type: 'boolean', default: false });expect(wf.concurrency).toEqual({ group: 'promote-stable', 'cancel-in-progress': false });@@ -715,6 +741,7 @@ describe('promote-stable.yml', () => {PROMOTE_VERSION: '${{ inputs.version }}', PROMOTE_SOAK_RUN_URL: '${{ inputs.soak_run_url }}', PROMOTE_SCOREBOARD_URL: '${{ inputs.scoreboard_url }}',PROMOTE_ROLLBACK: '${{ inputs.rollback }}', PROMOTE_REASON: '${{ inputs.reason }}', PROMOTE_WITHDRAW: '${{ inputs.withdraw }}',PROMOTE_NOT_PROMOTABLE: '${{ inputs.not_promotable }}', PROMOTE_NOT_PROMOTABLE_REASON: '${{ inputs.not_promotable_reason }}', PROMOTE_NOT_PROMOTABLE_FIXED_IN: '${{ inputs.not_promotable_fixed_in }}',+ PROMOTE_NOT_PROMOTABLE_REMOVE: '${{ inputs.not_promotable_remove }}',});for (const s of steps) expect(s.run ?? '').not.toContain('${{');const releaseYml = readFileSync(join(ROOT, '.github/workflows/release.yml'), 'utf8');diff --git a/test/upgrade-restart-external-autopilot-8776.test.ts b/test/upgrade-restart-external-autopilot-8776.test.tsindex 5091bdefd9..7590a5b6e5 100644--- a/test/upgrade-restart-external-autopilot-8776.test.ts+++ b/test/upgrade-restart-external-autopilot-8776.test.ts@@ -65,6 +65,22 @@ describe('planRestart: an autopilot started outside gbrain\'s service', () => {expect(planRestart([autopilot(30)], ctx({ autopilotLauncher: { ...CRON, pid: null } })).manual.map(m => m.pid)).toEqual([30]);});+ test('with a launcher known but a lock that names another pid or none, the refusal says so instead of asking for the launcher again', async () => {+ for (const launcher of [{ ...DECLARED, pid: null }, { ...DECLARED, pid: 31 }, { ...CRON, pid: null }]) {+ const plan = planRestart([autopilot(30)], ctx({ expected: PENDING_BUILD, autopilotLauncher: launcher }));+ expect(plan.steps).toEqual([]);+ expect(plan.manual.map(m => [m.role, m.pid, m.argv])).toEqual([['autopilot', 30, ['kill', '30']]]);+ expect(plan.manual[0]!.instruction).toContain(launcher.pid ? 'names pid 31' : 'names no running autopilot');+ expect(plan.manual[0]!.instruction).not.toContain('gbrain config set self_upgrade.autopilot_launcher external');+ }+ await withEnv({ GBRAIN_SELF_UPGRADE_MODE: 'auto' }, () => {+ const check = checkSelfUpgradeHealth(planRestart([autopilot(30)], ctx({ expected: PENDING_BUILD, autopilotLauncher: { ...DECLARED, pid: null } })));+ expect(check.status).toBe('warn');+ expect(check.fix?.ask_user).not.toBe(true);+ expect(check.fix?.argv).toEqual(['gbrain', 'upgrade', '--restart-only', '--dry-run', '--json']);+ });+ });+test('an autopilot from another install that is not a Bun global copy still refuses: the hand-off never moves a clone', () => {const plan = planRestart([autopilot(30, OLD, { install_root: '/srv/gbrain-checkout', install_version: OLD })], ctx({ ownInstallRoot: '/opt/gbrain', autopilotLauncher: CRON }));expect(plan.steps).toEqual([]);