Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

docs(release): document release:restamp and test:stress; RELEASING example is a PATCH bump

garrytandbc0a8919ccc
diff --git a/CLAUDE.md b/CLAUDE.md
index 09cc2ca53b..99e4e224dc 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -302,16 +302,17 @@ checkpoint resume, or DB-contention-aware pace mode.
## Version locations (single source of truth: `VERSION` file)
Every release updates the required version stamps in the table below.
-Update TODOS only when filing new work, not to rewrite old entries. Keep these in sync. `/ship` enforces this via Step 12's idempotency check (VERSION vs
-package.json drift), but the canonical list lives here so future runs and
-the auto-update agent know where to look.
+`bun run release:restamp` rewrites all of them, renumbers the branch's own
+schema migrations after master's and runs the auto-derived regenerations;
+run it when the PR is next to merge ([how](docs/RELEASING.md#release-restamp)).
+Update TODOS only when filing new work. `/ship`'s Step 12 idempotency check
+catches VERSION vs package.json drift; the canonical list lives here.
**Version format is mandatory: `MAJOR.MINOR.PATCH.MICRO` (four numeric
segments, dot-separated, no leading `v`).** Every new release MUST use the
-4-segment form. The `.MICRO` slot is the dot-suffix follow-up channel: when
-a release ships its commit subject ahead of its VERSION bump (e.g. PR #795
-landing as `v0.31.4` without bumping the file), the corrective ship lands
-as `0.31.4.1` rather than churning the patch number to `0.31.5`. Suffixes
+4-segment form. The `.MICRO` slot is the dot-suffix follow-up channel: a
+release whose commit subject shipped ahead of its VERSION bump is corrected
+as `0.31.4.1`, not by churning the patch number to `0.31.5`. Suffixes
like `-fixwave` are still allowed as needed (`0.31.1.1-fixwave`), but the
four numeric segments are required first. Historical 3-segment versions
(`0.31.3`, `0.22.1`) remain valid in `git log` and migration filenames
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 5ac00dfd5b..7cae230c59 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -397,7 +397,7 @@ Parity tests (`test/parity.test.ts`) verify CLI/MCP/tools-json stay in sync.
An op added to a domain module under `src/core/ops/` keeps its automatic path:
it appears in the CLI, the MCP server and `--tools-json` with no other edit
(see [Adding a new operation](#adding-a-new-operation)). Everything else lands
-in one of these six places. Every row ends with the same pre-merge gate:
+in one of these eight places. Every row ends with the same pre-merge gate:
`bun run verify`, then `bun run ci:ubicloud` (or `bun run ci:local`) for the
full unit + E2E run on PGLite, direct Postgres and PgBouncer.
@@ -417,6 +417,12 @@ to a sibling module. Every row also adds a behavior test of its own; the
| CLI-only command | The implementation in `src/commands/<name>.ts`; the dispatch module `src/cli/commands/<name>.ts`; a help line in `printHelp` (`src/cli.ts`, so raise its `module-size-limits.tsv` ceiling by one) | A record in `CLI_COMMANDS` (`src/cli/command-table.ts`): `phase: 'pre-connect'` when the command never touches the database, `'post-connect'` when its `run(engine, args, ctx)` needs an engine; `thinClient: 'none'` unless remote brains must refuse it (`'refuse'`, or `'route-then-refuse'` for subcommand routing); `selfHelp: true` when the command has flags or subcommands (its `run` then prints its own `--help`); optional `skipStartupHooks`; `load: () => import('<literal>')` | `bun run build:flag-registry`; the CLI goldens, deliberately: `GBRAIN_TEST_UPDATE_GOLDENS=1 bun test test/cli-goldens.test.ts test/cli-dispatch-phase.test.ts test/cli-dispatch-thin-client.test.ts` | `test/<name>.test.ts` spawning `bun src/cli.ts <name>` and asserting output and exit code, plus `bun test test/cli-command-table.test.ts test/cli-flag-validation.test.ts` |
| HTTP route (`gbrain serve --http`) | The route inside `mount<Area>(app, ctx)` in `src/commands/serve-http-<area>.ts` (`/admin/api/*` goes in `serve-http-admin-api.ts`, `/mcp` in `serve-http-mcp.ts`, OAuth in `serve-http-oauth.ts`); a new area is a new module plus one mount call in `buildServeHttpApp` (`src/commands/serve-http.ts`). An `/admin` route takes `ctx.requireAdmin` before its handler | None for a route in an existing area; a new area adds its mount call in `buildServeHttpApp` (order matters) | The route goldens, deliberately: `GBRAIN_TEST_UPDATE_GOLDENS=1 bun test test/serve-http-route-golden.test.ts test/serve-http-route-runtime-golden.test.ts` | A behavior test (`test/serve-http-<area>-<route>.test.ts`: mount the area on a bare `express()` app with a stub ctx; `mountAdminApi` reads `requireAdmin`, `sseClients` and `mcpResourceUrl` at mount time) plus `bun test test/serve-http-admin-route-guard.test.ts`, which finds the new route by itself |
| Sync phase | A module under `src/commands/sync/` taking `(run, Pick<SyncPlan, ...>, ...)` and returning `SyncResult \| undefined`; state it shares across awaits becomes a field on `SyncRun` (`src/commands/sync/sync-run.ts`). A value for the final summary flows `SyncRun` field -> `finalizeIncrementalSync` (`sync/finalize.ts`) -> `SyncResult` (`src/commands/sync.ts`, raise its ceiling) -> `printSyncResult` (`sync/report.ts`) when it should print | The phase call order in `performSyncInner` (`src/commands/sync/incremental.ts`) | Nothing | A case in `test/sync-run-ordering.serial.test.ts` (it has the git-repo + PGLite harness: `commitPages`, `performSync`), plus `bun test test/sync.test.ts test/sync-run-ordering.serial.test.ts` |
+| Release version and migration numbers | Nothing by hand: when your PR is next to merge, `bun run release:restamp` (preview with `--dry-run`) merges `origin/master`, sets the PATCH version, renumbers your own migrations and commits once | None: it rewrites every required row of the CLAUDE.md "Version locations" table | It runs the generators itself and prints the golden-regeneration reason for the PR body | `bun run verify`; `bun test test/scripts/release-restamp.test.ts` when you change restamp itself ([docs](docs/RELEASING.md#release-restamp)) |
+| Stress-test a touched test (flake hunt) | Nothing: `bun run test:stress [files…] [--iterations N] [--base <ref>] [--postgres]` (defaults: files changed versus `origin/master`, 10 iterations, a fresh database per iteration) | None | Nothing | The same command; a failing iteration prints its reproduce line |
+
+The PR stress gate (`stress-changed-tests`) runs every test file the PR adds or
+changes 10 times with that same `bun run test:stress` command; a touched file
+that fails an iteration is root-caused in the same PR, never retried green.
A golden regenerated on purpose is a reviewer-visible diff: say in the PR body
why the output changed. Regenerate generated files instead of merging them
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index e32e8cb2f4..d2def8bd4e 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -127,8 +127,8 @@ in the plan file at `~/.claude/plans/`, not in the CHANGELOG. One unified entry
per branch, covering what the branch added vs the base branch.
**Never edit a CHANGELOG entry that already landed on master.** If master has
-v0.18.2 and your branch adds features, bump to the next version (v0.19.0, not
-editing master's v0.18.2). When merging master into your branch, master may
+v0.18.2.0 and your branch adds features, bump to the next PATCH version
+(v0.18.3.0, never MINOR) instead of editing master's v0.18.2.0. When merging master into your branch, master may
bring new CHANGELOG entries above yours — push your entry above master's
latest and verify:
@@ -160,6 +160,80 @@ If any answer is no, fix it before continuing.
- Upgrade instructions: `gbrain upgrade` + any manual step if needed.
- Credit to external contributors when a community PR was incorporated.
+## Release restamp
+
+`bun run release:restamp` makes a branch next-to-merge in one command. Run it
+when your PR is next in the merge line, not earlier: the merge coordinator
+merges one PR at a time, so restamping at that moment allocates the version
+and migration numbers without races. Preview first with `--dry-run`, which
+prints every planned edit, predicted merge conflict, migration renumbering
+and the commit it would make, and changes nothing.
+
+**Say to your agent:** *"Restamp this branch onto master, it's next to merge."*
+
+1. Refuses a dirty working tree (commit or `git stash -u` first) and a
+ failed fetch (offline: `git fetch origin master`, then rerun).
+2. Captures the branch's CHANGELOG entry (the sections above the newest entry
+ it shares with master; one entry per branch) and its migration inventory.
+3. Merges `origin/master` with a merge commit. Version-only hunks in the stamp
+ files, `CHANGELOG.md` and generated files (migration registry,
+ `migrations/records.json`, `llms*.txt`, plugin trees, the template repo,
+ `bun.lock`) resolve mechanically; any other conflict stops with the file
+ list.
+4. Sets VERSION to master's `MAJOR.MINOR.(PATCH+1).0` and rewrites every
+ required row of the CLAUDE.md "Version locations" table: VERSION,
+ `package.json`, the three plugin manifests, the BOOTSTRAP runbook stamp,
+ the CHANGELOG entry (re-stamped on top of master's entries with today's
+ date), and branch-added TODOS lines naming the old version.
+5. Renumbers the branch's own schema migrations (files `origin/master` does
+ not have) consecutively from master's latest + 1, in their original order.
+ It changes only the filename, the `export const v<NNN>` name and the
+ `version:` literal, and proves the rest of the file is token-identical.
+ Published migrations are never renumbered or edited; a branch file whose
+ payload matches a migration master already published under another number
+ (squash-merged or cherry-picked) stops with the `git rm` fix.
+6. Regenerates the migration registry, `migrations/records.json` (when the
+ branch has migrations), `bun.lock`, the bootstrap template repo and
+ everything `bun run regen:all` covers.
+7. Lists every line the branch added that still names an old migration number
+ (`v209`, `v209-name`, `migration 209`, `schema_version ... 209`,
+ `version: 209`) and stops: such a line may mean the moved migration or the
+ published one that now owns the number, so it is never rewritten. Edit each
+ line (an edited line is not listed again), or pass `--accept-references`
+ with `--continue` when a line means the published migration.
+8. Runs the drift checks (version stamps and CHANGELOG agree, bootstrap
+ stamp, plugin tree, template repo, migration registry and order), commits
+ once as `v<new> chore(release): restamp onto master v<master>`, and prints
+ the old-to-new migration mapping with the collision-recovery steps, the
+ golden-regeneration reason for the PR body, the PR title and
+ `bun run verify`.
+
+Every stop prints what happened, why, and the fix, saves its state, and ends
+with `bun run release:restamp --continue` (after you fix it) or `--abort`
+(back to the pre-run commit). `--no-commit` leaves the restamp edits staged.
+A second run with nothing to change commits nothing. It renumbers source
+only and never touches a database: if you applied an old number locally,
+follow "Collision recovery" in [TESTING.md](TESTING.md#schema-migration-registry)
+(disposable DB: rebuild and replay; retained data: explicit `schema_version`
+reconciliation).
+
+**Why stamps are not derived at build time.** Several readers take the
+version from committed files with no build step: `bun install -g
+github:garrytan/gbrain` installs from source, `gbrain bootstrap status`
+compares the BOOTSTRAP runbook stamp with the installed binary, the plugin
+manifests and generated trees are published as committed, and `release.yml`
+fires on a VERSION change. A build-time value would leave those copies
+wrong, so the files stay stamped and one command rewrites them.
+
+**Why migration IDs stay sequential.** A brain records one integer,
+`schema_version`, and the runner applies every migration above it in order.
+A migration numbered at or below master's latest is skipped forever on
+current brains, which `check:schema-migration-order` rejects. Unordered IDs
+(timestamps, hashes) would need a per-migration applied-set table and a
+bookkeeping migration for every existing brain. Renumbering at merge time,
+serialized by the merge coordinator, keeps the counter correct with no
+schema change. Build on `release:restamp` rather than a second restamp tool.
+
## CHANGELOG voice + release-summary format
**IRON RULE: the CHANGELOG describes what the user gets, not how the work
diff --git a/docs/TESTING.md b/docs/TESTING.md
index e27e604136..9462fce18e 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -794,7 +794,9 @@ Two guards run in `bun run verify`:
Collision recovery: an unapplied branch migration is renumbered (`git mv`, edit
`version`, regenerate); one already applied to a disposable dev DB means rebuilding
that DB and replaying; one applied to retained data needs explicit `schema_version`
-reconciliation, never just a counter edit. Pinned by
+reconciliation, never just a counter edit. `bun run release:restamp` does the
+renumbering at merge time and prints the old-to-new mapping with these steps
+([RELEASING.md](RELEASING.md#release-restamp)). Pinned by
`test/scripts/build-schema-migrations.test.ts` and `test/migrations-golden.test.ts`.
### Schema generator freshness
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 37b7f2e795..9691fd45bf 100644
--- a/docs/architecture/key-files/ci-health-and-test-guards.md
+++ b/docs/architecture/key-files/ci-health-and-test-guards.md
@@ -7,6 +7,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `scripts/lib/gh-issue.ts` — the GitHub seam shared by the CI watchers. `inert()` makes run-derived text (job, step and test names, error text) safe to show an agent: control characters stripped, length capped, backticks and pipes replaced, mentions and links neutralized. `GitHubClient` is the one interface both watchers call (`restClient()` uses `GH_TOKEN`/`GITHUB_TOKEN` in Actions or the authenticated `gh api` locally); `findIssueByTitle` finds an issue by label and exact title, open first, else the most recently updated closed one.
- `.github/workflows/ci-health.yml` + `scripts/ci-health-report.ts` — weekly CI health report. Reads the last N days (`--days`, default 7) of same-repository pull-request runs of test.yml and e2e.yml through the REST API (runs, jobs, check-run annotations; never logs, fork runs or fork artifacts) and upserts `CI health (week of <date>)` (label `ci-health`) with first-attempt pass rates, the test files with the most failure annotations and the count of fork runs it did not read. Tests: `test/scripts/ci-health-report.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. 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).
- `scripts/ci-manifest-diff.sh` — parsed-JSON classification of manifest diffs for CI scoping: `version-only` (only the top-level `version` differs), `dependency-change` (any dependency field differs), `dependency-scope` (whether a changed-file list touches lockfiles, `patches/` or dependency fields) and `drop-version-only` (filters version-only `package.json` and `openclaw.plugin.json` entries out of a changed-file list, so a release bump does not widen the native scope). Used by test.yml's `changes` job (before `scripts/ci-native-scope.sh`) and its dependency-audit scope step. Tests: `test/scripts/ci-manifest-diff.test.ts`.
- `scripts/ci-dependency-audit.sh` — runs `bun audit` for the root and `admin/` lockfiles. It blocks (`BLOCKING=true`) on pushes, schedules and dispatches, on lockfile, `patches/` or dependency-field changes, with the `dependency-audit` label, or when the diff cannot be read; elsewhere an advisory is a `::warning::` naming why the run does not block.
- `scripts/e2e-provider-key-notice.sh` — e2e.yml's visible-skip step: when `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` is empty, prints a `::warning::` and step-summary line naming the empty secret and the owner-only fix, so a green keyless run is never read as keyed coverage. Exits 0 always.
diff --git a/llms-full.txt b/llms-full.txt
index 4c303208ff..1aa45b76d9 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -2233,16 +2233,17 @@ checkpoint resume, or DB-contention-aware pace mode.
## Version locations (single source of truth: `VERSION` file)
Every release updates the required version stamps in the table below.
-Update TODOS only when filing new work, not to rewrite old entries. Keep these in sync. `/ship` enforces this via Step 12's idempotency check (VERSION vs
-package.json drift), but the canonical list lives here so future runs and
-the auto-update agent know where to look.
+`bun run release:restamp` rewrites all of them, renumbers the branch's own
+schema migrations after master's and runs the auto-derived regenerations;
+run it when the PR is next to merge ([how](docs/RELEASING.md#release-restamp)).
+Update TODOS only when filing new work. `/ship`'s Step 12 idempotency check
+catches VERSION vs package.json drift; the canonical list lives here.
**Version format is mandatory: `MAJOR.MINOR.PATCH.MICRO` (four numeric
segments, dot-separated, no leading `v`).** Every new release MUST use the
-4-segment form. The `.MICRO` slot is the dot-suffix follow-up channel: when
-a release ships its commit subject ahead of its VERSION bump (e.g. PR #795
-landing as `v0.31.4` without bumping the file), the corrective ship lands
-as `0.31.4.1` rather than churning the patch number to `0.31.5`. Suffixes
+4-segment form. The `.MICRO` slot is the dot-suffix follow-up channel: a
+release whose commit subject shipped ahead of its VERSION bump is corrected
+as `0.31.4.1`, not by churning the patch number to `0.31.5`. Suffixes
like `-fixwave` are still allowed as needed (`0.31.1.1-fixwave`), but the
four numeric segments are required first. Historical 3-segment versions
(`0.31.3`, `0.22.1`) remain valid in `git log` and migration filenames