Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
docs: CI red runbook, master-red ownership, release CI gate
garrytancce8c807e658
diff --git a/docs/RELEASING.md b/docs/RELEASING.mdindex e32e8cb2f4..c7db055883 100644--- a/docs/RELEASING.md+++ b/docs/RELEASING.md@@ -88,7 +88,8 @@ re-check, and a "Next step for the agent" block plus a JSON block.A matching cell keeps the issue open with the `known-red` label; a new failure inthe same job opens a new incident; a passed review-by date asks for a fix again.- **Closing:** nightly-watch closes the issue only when a later scheduled run is- green and every previously failing job executed. A skipped job never closes it.+ green with complete evidence and every previously failing job executed. A+ skipped job never closes it.- **Re-check after a fix:** `gh workflow run <workflow>.yml --ref master`, then`gh workflow run nightly-watch.yml -f run_id=<that scheduled run id>` to preview(`-f dry_run=true`) or apply the issue update.@@ -97,6 +98,26 @@ re-check, and a "Next step for the agent" block plus a JSON block.carry the `dependency-audit` label; pushes and the nightly run always block, so anew upstream advisory shows up as one red nightly instead of every open PR.+## Master-red issues++nightly-watch keeps one `master-red` issue per workflow (`Master red: Test`,+`Master red: E2E Tests`) for push-to-master runs; scheduled runs stay in+`nightly-red`. The body names each failing job, every failing test file with+its `bun run test:stress` reproduce line, and the suspect range (last green+push SHA, first red SHA, merged PRs). Labels, close rules and recovery steps:+[CI red runbook](ci-red-runbook.md#ci-issue-labels).++- **Owner:** the agent on release duty owns every open `master-red` issue, as+ for `nightly-red`; Garry is the escalation for owner-only actions.+- **First response within 1 hour:** a comment or a linked repair PR. CI health+ measures it; nothing enforces it.+- **Response:** a repair PR whose body says `Fixes #<issue>`. Known-red rows+ never apply to push runs. A master-red repair PR is fast-tracked when Garry+ asks.+- **Closing:** nightly-watch closes the issue on a green push run where every+ previously failing job (E2E Tests: every failing test file) ran and passed+ with complete evidence. Without a merged repair PR it opens `flake` issues.+## Merge queue`test.yml` and `e2e.yml` carry `merge_group` triggers. They are inert until the@@ -444,10 +465,27 @@ already-published bad binaries; an affected release needs its own explicitlyapproved recovery and asset verification. The template and plugin publishingjobs pin the same Bun version.+### Release CI gate++The `ci-gate` job (`scripts/release-gate.ts`) holds build, publication and the+`latest-stable` move until the push-to-master runs of Test and E2E Tests both+succeed on the release commit.++- **Failed run:** nothing is published and the job fails with the run and the+ master-red issue. After master is green again, publish the current VERSION+ with `gh workflow run release.yml --ref master`.+- **Run cancelled by a newer push:** the gate follows the next master commit.+ If it contains the release commit and carries the same VERSION, that commit+ is gated and published. If VERSION moved on, this version is skipped and the+ newer VERSION's release run publishes.+- **Backfill:** `gh workflow run release.yml --ref master` gates and publishes+ master HEAD's VERSION. Other refs are refused.+- The gate waits up to 110 minutes, then fails with the backfill command.+### The `latest-stable` tagThe **final step of the release job** force-advances the `latest-stable` tag to-the release commit (`git push origin "+${GITHUB_SHA}:refs/tags/latest-stable"`).+the gated release commit (`git push origin "+${RELEASE_SHA}:refs/tags/latest-stable"`).`latest-stable` is the single sanctioned distribution ref: the README pasteblock, the `BOOTSTRAP_FOR_AGENTS.md` fetch URL, and`bun install -g github:garrytan/gbrain#latest-stable` all reference itdiff --git a/docs/TESTING.md b/docs/TESTING.mdindex e27e604136..5a3782c56b 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -30,6 +30,10 @@ log's absolute path. A failing `bun run verify` keeps each failed check's logand prints it. In CI, each red job's step summary lists the failing tests with a`bun test … -t` reproduce command.+**CI check is red on master:** follow the [CI red runbook](ci-red-runbook.md)+(`master-red`, `flake`, `nightly-red` and `known-red` labels, the failure+manifest, CI health).+| File suffix or location | Lane | Command | Runs in PR CI ||---|---|---|---|| `*.test.ts` | unit (parallel shards) | `bun run test` | yes, 8 weighted shards |diff --git a/docs/architecture/key-files/ci-health-and-test-guards.md b/docs/architecture/key-files/ci-health-and-test-guards.mdindex 37b7f2e795..0aaf88c3ae 100644--- a/docs/architecture/key-files/ci-health-and-test-guards.md+++ b/docs/architecture/key-files/ci-health-and-test-guards.md@@ -3,9 +3,13 @@[Subsystem index](../KEY_FILES.md). Read only the entries relevant to your change.Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.-- `.github/workflows/nightly-watch.yml` + `scripts/nightly-issue.ts` — nightly-red incidents. On every completed scheduled run of a watched workflow (scheduled runs from this repository only; one queued concurrency group per workflow), `nightly-issue.ts --run-id <id> [--dry-run]` keeps one issue titled `Nightly red: <workflow>` (label `nightly-red`): opens it on red with job/step pairs, error annotations, the first red run, the last green SHA and compare link, a "Next step for the agent" (code fix or owner action) and a JSON block; updates it while red; reopens it on a flap with the run attempt; and closes it only when a later scheduled run is green and every previously failing job executed and passed. Rows in `.github/nightly-known-red.tsv` (workflow, job, signature, kind `known-red|known-skipped`, owning TODOS title, review-by date; at most 3) keep a matching incident open under the `known-red` label and comment only when the failing set changes or the review date passes. A ratchet test fails when a scheduled workflow is not watched. Tests: `test/scripts/nightly-issue.test.ts`. Process: `docs/RELEASING.md#nightly-red-issues`.-- `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`.+- `.github/workflows/nightly-watch.yml` + `scripts/nightly-issue.ts` — nightly-red and master-red incidents. `workflow_run` fires only for master-branch completions; the `resolve` job admits scheduled runs and push-to-master runs of Test and E2E Tests from this repository (head repository checked) plus dispatch, and `nightly-issue.ts --resolve` turns every entry path into the target workflow id and track (`schedule`, `push`; a replay writes `push`); `watch` queues on one group per repository + workflow + track. `nightly-issue.ts --run-id <id> [--replay-issue <n>] [--dry-run]` routes the run (`routeRun`: pull-request, fork, other-branch and non-allowlisted push runs are refused with a next step). Scheduled runs keep one `Nightly red: <workflow>` issue (label `nightly-red`): open on red with job/step pairs, every failing test file with its reproduce line, sanitized error excerpts, the first red run, the last green SHA and compare link, a "Next step for the agent" and a JSON block; update while red; reopen on a flap; close only on a later green scheduled run with complete evidence where every previously failing job executed. Rows in `.github/nightly-known-red.tsv` (at most 3; race-hunt jobs refused) keep a matching incident open under `known-red`. A scheduled Test or E2E Tests run also feeds that workflow's open master-red issue. Push runs go to `scripts/lib/master-red.ts`. A ratchet test fails when a scheduled workflow is not watched. Tests: `test/scripts/nightly-issue.test.ts`. Process: `docs/RELEASING.md#nightly-red-issues`, `docs/ci-red-runbook.md`.+- `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; `redactCredentials()` strips user:password from database URLs. `GitHubClient` is the one interface the watchers call (`restClient()` uses `GH_TOKEN`/`GITHUB_TOKEN` in Actions or the authenticated `gh api` locally; `download()` reads artifact archives without forwarding the token to blob storage). `findIssueByTitle` finds an issue by label and exact title, open first, else the most recently updated closed one; `listLabeled`, `getIssue` and `linkedPulls` (PRs cross-referencing an issue) back master-red and CI health; `fetchArtifactJson` + `readZipEntry` read one JSON file from a run artifact and return a reason instead of throwing.+- `.github/workflows/ci-health.yml` + `scripts/ci-health-report.ts` — CI health report. Reads one window (`--days`, default 7, or `--since/--until`, also dispatch inputs) of same-repository pull-request and push-to-master runs of test.yml and e2e.yml (runs, jobs, check-run annotations, issues; never logs, fork runs or fork artifacts), paging the whole window (`listRuns` splits a query over the 1000-result search cap). It reports first-attempt pass rates (`firstAttempt()`), the exit criteria (master >= 95%, PR >= 90%; met, missed or indeterminate when the window cannot be read in full), stress-gate failures, failure classes, cancellation and completion coverage, master-red time to first response, the nightly-watch residual, the test files with the most failure annotations, shard spread and the count of fork runs it did not read; an explicit window with a missed target opens a follow-up issue. Tests: `test/scripts/ci-health-report.test.ts`. Docs: `docs/ci-red-runbook.md#ci-health-report`.+- `scripts/lib/master-red.ts` — master-red reconciliation for push-to-master runs of Test and E2E Tests (`PUSH_ALLOWLIST`). Each watch evaluates every completed push run above the high-water mark (`evaluated`: run number, then attempt) stored in the newest `Master red: <workflow>` issue's `master-red:json` block (`applyRun` folds runs; cancelled runs change nothing); a missing or malformed block is rebuilt from the actions API (`pendingRuns`). It opens on red with the suspect range (`suspectRange`: compare plus commit-to-PR lookups), updates while red, closes when every previously failing job (E2E Tests: every failing file, from the manifest) ran and passed with complete evidence, records an incident that opened and closed between watches, and keeps a not-run-since failure open with the manual-close step. `externalPass` lets a scheduled run or an issue-bound E2E replay clear failures. Closing without a merged linked repair PR opens `flake` issues (`flakeFor`, `flake:json`); `closeFlakes` closes one after its repair PR merged and a later complete run passed its file and arm. Writes re-read the issue first and re-plan when it moved; a create race closes the newer duplicate. Tests: `test/scripts/nightly-issue.test.ts`. Docs: `docs/ci-red-runbook.md`.+- `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, with `complete`/`problems` (an unreadable page, annotation or manifest is incomplete evidence, never zero failures). `reproduceCommand` builds `bun run test:stress <file> --iterations 10 [--postgres]` from a validated test path only.+- `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`; `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`.- `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/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.diff --git a/docs/ci-red-runbook.md b/docs/ci-red-runbook.mdnew file mode 100644index 0000000000..6a68117a8a--- /dev/null+++ b/docs/ci-red-runbook.md@@ -0,0 +1,105 @@+# CI red runbook++What to do when a CI check on master is red, which issue tracks it, and what+closes it. The watchers are `scripts/nightly-issue.ts` (run by+`.github/workflows/nightly-watch.yml`), `scripts/ci-health-report.ts` (run by+`.github/workflows/ci-health.yml`) and `scripts/release-gate.ts` (run by+`.github/workflows/release.yml`). Ownership and response times live in+[`docs/RELEASING.md`](RELEASING.md#master-red-issues).++## CI issue labels++| Label | Who opens it | What closes it | Owner |+|---|---|---|---|+| `master-red` | nightly-watch, on a red push-to-master run of Test or E2E Tests (one issue per workflow). A hand-opened tracking issue for a "cause not found" row uses this label with a different title, so no green rule touches it. | nightly-watch, on a later green push run where every previously failing job ran and passed with complete evidence (E2E Tests: every previously failing test file was among the files that run executed and passed). The scheduled full run or an issue-bound replay also counts. Hand-opened issues close by hand when their row is fixed. | The agent on release duty; first response within 1 hour (measured, not enforced). |+| `flake` | nightly-watch, when a `master-red` issue closes on green with no merged repair PR linked: one issue per previously failing test (at most 10 per close; the rest are listed in the close comment). | nightly-watch, after the repair PR linked to it merged and a later complete run passed that test's file and arm (a Windows or macOS flake: the job that failed passed). | The agent on release duty; review by the `expires` date in its JSON block. |+| `nightly-red` | nightly-watch, on a red scheduled run of any watched workflow (one issue per workflow). | nightly-watch, on a later green scheduled run with complete evidence where every previously failing job executed. | The agent on release duty; respond within 24 hours. |+| `known-red` | nightly-watch adds it to a `nightly-red` issue whose only failures match `.github/nightly-known-red.tsv` rows. | Removed when the run no longer matches only known rows. Rows never apply to push runs, and race-hunt jobs cannot have rows. | The TODOS.md entry each row names. |++Every issue body ends with a "Next step for the agent" block and a fenced JSON+block (`master-red:json`, `flake:json`, `nightly-watch:json`). Read the JSON+instead of parsing the prose. A `master-red` or race-hunt failure has one+response: a repair PR whose body says `Fixes #<issue>`.++## Master-red reconciliation++- **Which runs count:** completed push-to-master runs of Test and E2E Tests from+ this repository. Pull-request, fork, other-branch and other-workflow push runs+ are refused with a next step. Scheduled runs go to `nightly-red`.+- **Order:** every watch reads that workflow's push runs and evaluates each run+ above the high-water mark (`evaluated`: run number, then attempt) in the newest+ issue's JSON block. A dropped or superseded watch therefore loses nothing; a+ run that completes after a newer one was evaluated is ignored; a successful+ re-run is a newer attempt; a run cancelled by a newer push changes nothing.+- **Missing or malformed JSON block:** the state is rebuilt from the actions API+ by folding from the last green run before the newest red one. The body says+ so. If the API cannot be read, the watch fails and writes nothing.+- **Suspect range:** the last green push SHA, the first red SHA, the compare link+ and the PRs merged in that range.+- **Not run since:** a failing job that has not run and passed since (renamed,+ skipped, or an E2E file the selection skipped) keeps the issue open. Close it+ by hand with a comment naming the replacement, or replay E2E files:+ `gh workflow run e2e.yml --ref master -f full_corpus=true`, then+ `gh workflow run nightly-watch.yml -f run_id=<that run id> -f replay_issue=<issue>`.+- **Serialization:** each watch queues on one group per repository, target+ workflow and track (`schedule` or `push`; a replay writes `push`). Before the+ first write it re-reads the issue and re-plans when the issue moved. When two+ watches create the same issue at once, the newer one closes itself as a+ duplicate and re-plans.+- **Re-check:** `gh workflow run nightly-watch.yml -f run_id=<run id>`, with+ `-f dry_run=true` to preview.++## Flake issues++A `flake` issue records one intermittent failure: the file, test name, lane,+arm, platform, failing job, failure signature, first red run, owner and an+expiry date 14 days out. The stress gate can exempt only a failure that matches+an open issue's test name, backend and signature. Next step: run the reproduce+line (`bun run test:stress <file> --iterations 10 [--postgres]`) until it fails,+find the race, and open a repair PR with `Fixes #<issue>`. Never widen a+timeout or weaken an assertion. When the signature names a runner, disk or+secret problem, ask the repository owner for that fix instead of a code PR.++## CI failure manifest++The `executed-receipts` job of test.yml and e2e.yml runs `scripts/ci-manifest.ts`+and uploads the `ci-manifest` artifact: a versioned JSON file+(`gbrain-ci-manifest/v1`) bound to the workflow, event, SHA, run id and run+attempt. It lists every failing test identity (lane, file, test, arm) and, per+file, how many tests executed, failed and were skipped. It is `complete` only+when every lane's receipts are valid (no killed shard, truncated report, older+attempt, or lane that executed nothing without a declared skip row).++nightly-watch also reads the failing jobs' annotations. A manifest or annotation+that cannot be read, or a manifest from another SHA or attempt, is incomplete+evidence. It is reported, never read as zero failures, and never clears a+failure, closes an issue or grants an exemption. After a partial re-run+("re-run failed jobs") the manifest is incomplete. Wait for the next push run,+or replay E2E files as above.++## CI health report++`bun scripts/ci-health-report.ts --since <date> --until <date> --dry-run` prints+the report for a window. `gh workflow run ci-health.yml -f since=<date> -f until=<date> -f dry_run=false`+writes it as `CI health (<since>..<until>)`. The weekly schedule writes+`CI health (week of <date>)`. The report covers:++- first-attempt pass rates for pull-request and push-to-master runs (a re-run+ counts as a failed first attempt; cancelled, skipped, dispatch and scheduled+ runs are excluded);+- the exit criteria: master Test and E2E at least 95%, PR test.yml and e2e.yml+ at least 90%. A window that cannot be read in full is indeterminate, which is+ never satisfied. In an explicit window, a missed target opens+ `CI health targets missed (...)` listing the top failing files;+- stress-gate failures and the failure classes (stress gate, test or check,+ infrastructure), plus cancellation and completion coverage;+- master-red time to first response: the first comment by the repository owner,+ a member, a collaborator or a `--responders` login (bots do not count), or+ the first linked PR from anyone;+- the nightly-watch residual: skipped watch runs, and watched-workflow runs on+ master outside the schedule and push allowlist, which still start a skipped+ watch run.++The agent on release duty dispatches the report on day 8 after a wave merges,+with the window starting at the merge date, and records the numbers on the CI+health issue.diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsvindex 295cb8c9c3..0b5a63fd7d 100644--- a/scripts/structural-suites.tsv+++ b/scripts/structural-suites.tsv@@ -278,7 +278,10 @@ test/scripts/heavy-door-workflow.test.ts heavy door supply chain and coverage gatest/scripts/native-lock-prebuilds.test.ts native lock distribution integrity 2 readFileSynctest/scripts/nightly-e2e.test.ts nightly E2E scheduling 4 readFileSynctest/scripts/nightly-issue.test.ts .github/nightly-known-red.tsv 2 readFileSync+test/scripts/nightly-issue.test.ts nightly-watch coverage ratchet 1 readFileSynctest/scripts/nightly-issue.test.ts nightly-watch incidents 9 readFileSync+test/scripts/nightly-issue.test.ts nightly-watch routing and guard 9 readFileSync+test/scripts/nightly-issue.test.ts operator messages carry docs anchors that resolve 1 readFileSynctest/scripts/postgres-lane-coverage.test.ts check-postgres-lane-coverage.ts 6 readFileSynctest/scripts/regen-all.test.ts regen:all 4 readFileSynctest/scripts/run-verify-parallel.test.ts guard registration ⇒ execution coverage 1 readFileSync