Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge origin/master (v0.60.191.0) into capy/w16-flakes
garrytan68e273fcb79e
diff --cc CHANGELOG.mdindex d07fec440c,84cb13cf44..ef0fef6d77--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,14 -10,46 +10,54 @@@ credits are retained; no result has beeidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [Unreleased]++### Itemized changes++- **Flake fix: `test/write-contract-conformance.test.ts` (and its Postgres arm) no longer fails with `ECONNRESET` on a loaded CI shard.** The conformance HTTP clients connected before the stdio arm and reused a pooled keep-alive socket afterwards; when the stdio arm outlived the test server's 10 s idle timeout (`Bun.serve` default in the test-only `startHttpTransport`, swept every 4 s; production `serve --http` is Express and advertises `Keep-Alive: timeout=5`), the first HTTP POST could land in the sweep that closed the socket, and Bun's fetch, which parks pooled sockets for 5 minutes, parses no `Keep-Alive` hint and never retries a POST, surfaced "The socket connection was closed unexpectedly". The clients now send `Connection: close`, so each call uses its own socket. Forced probe (test server `idleTimeout: 1`, a 4.1 s busy loop across one sweep, then a POST): 3/3 ECONNRESET before, 3/3 pass after, both engines. No assertion or timeout changed. Sixteen other tests share the same test server with persistent MCP HTTP clients and carry the same exposure if a case idles a client 10 s before a POST; a Bun-based thin client (`src/commands/protocol.ts`, `src/core/connect-probe.ts`) has the same narrow window against the production server past 5 s idle (follow-up, not changed here).+- **Flake fix: `test/entity-card-perf.slow.test.ts` gates its 100 ms p99 on the call's thread CPU time instead of wall time.** PGLite runs every query in-process on the test thread with no I/O, so on an idle machine the two are equal, and on a loaded CI runner wall time was measuring the shard's load, not the card path (p99 100.52 ms on a loaded 8-VM shard against about 30 ms idle). The budget, the getPage ratio guard and every assertion are unchanged; wall p99 is still logged. Forced probe: master's wall gate fails under 8 busy loops, the CPU gate passes, and an injected 96 ms slowdown fails both idle and under contention. Known limit: CPU time cannot catch a regression that blocks on a sleep or I/O, and the card path has neither apart from the 2 s references deadline. `process.threadCpuUsage` ticks in 1 ms steps on the Ubicloud runners (kernel `CONFIG_HZ=1000`, Bun 1.4.0 and 1.4.2) and 4 ms on a `CONFIG_HZ=250` box, rounding up; it is absent on Bun 1.3.14, which CI does not run.+- **Flake fix: `test/e2e/worker-configuration-release.test.ts` cleanup accepts `ESRCH` from `/proc/<pid>/stat`.** The "completion-recording failure never releases an isolated handler with a live descendant" case passed every assertion and then threw in its `finally` wait loop: right after the SIGKILL, Linux reaps the descendant between the loop's `open()` and `read()` of its stat file and returns `ESRCH` instead of `ENOENT` (#6575, job 115084475795). The catch now treats both as "gone"; the `running` must-end-false assertion is unchanged. Forced probe (a `bun test --preload` that makes the test's first stat read throw `ESRCH`): 3/3 fail before, 3/3 pass after; unforced 4/4.+- The `[0.60.189.0]` entry names migrations v241 and v242, the numbers it merged with (the merge-slot renumber from v240/v241 updated the stamps, not the entry text).+ ## [0.60.191.0] - 2026-10-13++ **`gbrain setup codex` gives Codex memory in one command, with the same target-first, hash-owned shape as `gbrain setup claude-code` (D8's Codex slice).** It shows the brain, source, launcher and owner before writing, creates a keyless brain only when none exists, and wires the MCP server plus the read-context hooks SessionStart and UserPromptSubmit. In three fresh installs on codex-cli 0.162.1, a fresh Codex session answered a question only the injected context could answer, with 0 tool calls. The bootstrap harness also stops wiring Codex transcript capture when capture was declined or in registrar mode.++ ### Itemized changes++ - **`gbrain setup codex`** (`src/core/setup/codex.ts`, `src/commands/setup.ts`): Codex needs three writes, `[mcp_servers.<name>]` in `config.toml`, the hook groups in `hooks.json` and a `[hooks.state."<key>"]` trust table per group (without it Codex lists the hook and never runs it). Memory-only by default; SessionEnd capture only with `--capture`, providers only with `--providers`, existing opt-outs win; `--scope project` exits 2 because Codex keeps hooks and config in `CODEX_HOME`. `--dry-run`, `--json`, `--surface`, `--no-hooks`, `--remove` and `GBRAIN_SURFACE` work as for Claude Code.+ - **Ownership and crash safety:** receipt `.gbrain-connection-codex-<name>.json` beside `config.toml` (receipt version 2) with a sha256 fingerprint per owned entry; write order receipt → brain → MCP → inert hook groups → trust tables, reversed on `--remove`, so every crash point leaves the hooks inert or fully wired and resume never duplicates. An entry the user edited is preserved and reported; the other owned entries are still written or removed. Setup's groups carry `GBRAIN_HOOK_LANE=setup`, and a bootstrap-lane wiring of the same events is refused as an owner conflict. `codex-toml.ts` gains single-table read, append and remove that keep every other byte.+ - **Bootstrap Codex capture gate** (`src/core/bootstrap/harness.ts`): `--no-capture` now suppresses the Codex SessionEnd capture hook and registrar mode (a non-loopback `--url`) no longer wires it, since it would capture into the local brain instead of the registered remote one. Disclosed in BEHAVIOR_CHANGES.+ - **`gbrain hook user-prompt --harness codex`** confines and parses Codex transcripts with the Codex capture spec and skips the Claude Code pressure probe; before, every native Codex prompt degraded with `transcript_outside_projects_dir`.+ - **Capability table v2:** the Codex row reports setup supported, pull connection-verified and push native-verified only when the receipt owns the UserPromptSubmit trust entry (otherwise native-pending), with a `push_evidence` field. `docs/mcp/CODEX.md` no longer says Codex has no lifecycle hooks.+ - **Tests:** the Codex lifecycle in `test/setup.test.ts` (byte-exact remove, crash resume at every seam, edited-entry preservation, a shifted hook index, two installs, unowned and remote MCP tables, consent and flags, the bootstrap-lane conflict, live trust-hash vectors); registrar mode and `--no-capture` in `test/bootstrap-harness.serial.test.ts`; Codex transcript confinement in `test/hook-command.serial.test.ts`. The #6499 backup-verification tests now run their probe stub on a virtual clock (a forced 400 ms per-repo delay fails the old tests and passes the new ones), and `test/session-seat-synthesize.test.ts` prints the whole phase result when it fails.+ - Credit: the Codex context-hook approach draws on #6408 and #6409 by @benswinney and the #5577 discussion in #6283 by @andreineacsu (evidence only; those PRs stay open).++ ## [0.60.190.0] - 2026-10-13++ **No Postgres statement outlives its budget now, a stalled managed sync says what is blocking it, and doctor stops misleading on managed and image-heavy brains (#6543, part 2).** v0.60.187.0 stopped the Supavisor wedge itself. This release closes the gaps the reporter hit around it. A statement that kept receiving bytes was never retired, so `/health?deep=1` stayed red forever. A sync stalled 300-600 s with "claimable here: no" no matter the cause. `repair failed-writes --apply` stopped at every pending write. Doctor recommended a `--retry-failed` that did nothing on a managed brain, and reported existing images as missing when only their letter case differed.++ ### Itemized changes++ - **Per-statement age cap.** A second in-flight clock, which received bytes never restart, retires a connection whose statement runs past its budget (`pg_connection_stuck reason=age`; `reason=idle` when nothing came back). The budget is per statement:+ - An operation that declares a longer `statement_timeout` gets that timeout plus the grace. This covers `SET LOCAL`, `set_config`, and a session `SET` on a reserved connection.+ - A declared 0 has no cap.+ - The driver reads these declarations from the statements it sends, so the budget holds behind a transaction pooler.++ The warn line adds `reason=` and `budget_ms=`, and `/health?deep=1` judges each statement against its own budget. A guard test fails CI on any `statement_timeout` change in `src/` written in a form the driver can't read. Driver edits went through `patches/[email protected]`. The ANN index build and both migration paths run past the pool budget unretired.+ - **Recovery counters.** `recovered` and `recovery_failed` appear in `/health?deep=1` and pool diagnostics, and a failed reconnect logs `pg_connection_recovery_failed`. Serve writes stuck, desync and recovery events to the pool-recovery audit, so `doctor --only pool_reap_health` sees them.+ - **A stalled sync names what is blocking it.** A new head-blocker probe names the predicate that keeps the queued head unclaimable: `refresh_fence`, `worktree_owner`, `effect_recovery`, `withdrawal_mirror`, `request_recovery`, `zombie_publication`, `lease` or `root_hold`.+ - **Operator-required blockers:** an unowned refresh fence, or a request held by a process that reports `restart_required`. These stop the drain within one governor tick with `drain_stalled`, `cause: head_blocked`, and a `next.fix` per predicate.+ - **Live blockers:** these keep the progress-aware wait.++ The stall line gains `consumer=` and `blocked_by=`, and `claimable here` reads the head itself (`unknown` on a failed read). `sources writer status` names the blocker, and offers `cancel-write-request` only when that request can be cancelled.+ - **`repair <kind> --apply` keeps going past pending writes.** While a consumer here publishes, it keeps each pending receipt and pins the cursor before the earliest one. It admits the rest with bounded backpressure (at most half the principal outstanding cap unresolved) and settles everything against one shared wait. A stopped run lists `pending` and the same command resumes. With no live consumer, or one reporting `restart_required`, it still stops at the first pending write and names the owner.+ - **`gbrain sync` on a managed brain implies `--no-pull`.** This covers one source, `--all`, and serve-delegated runs. It prints one stderr line naming `gbrain sources refresh <id>`. The library and MCP refusal of an explicit pull stays.+ - **Doctor and image fixes:**+ - The image importer no longer writes `type`/`title` into frontmatter, so re-imports stop re-creating `stale_frontmatter_keys`.+ - `embed --stale --images` and doctor `image_assets` share one resolver. An exact recorded path wins. A case-only match imports under the real-case path. Ambiguous or out-of-root matches are refused.+ - A successful managed sync settles legacy `sync-failures.jsonl` rows one at a time, against the imported commit and live pages. Doctor `sync_failures` says how many rows are legacy, and `--retry-failed` names them.+ - **Serve logs pending behavior-change notices** once per process at startup, without consuming the CLI or MCP delivery.+ - **`[persistence] phase=` lines** carry `request_id`, `operation`, `source`, `slug`, `principal` and `elapsed_ms`, and repeat suppression is per request.## [0.60.189.0] - 2026-10-12