Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/master' into capy/gbrain-repair-stuck-recovery
garrytan103cdda7e7a7
diff --cc CHANGELOG.mdindex 117f87cbf0,f98be86348..5d84429949--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,52 -10,33 +10,79 @@@ credits are retained; no result has beeidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).- ## [0.60.219.0] - 2026-10-14++## [0.60.220.0] - 2026-10-14++**When a file you edited by hand blocks every write to its source, one command now shows you both versions and lets you pick which one to keep (#6650).** If you edit a page file while gbrain is publishing a write to that same file, gbrain can no longer tell whether it is safe to put the file back. It used to stop there and leave every later write to that source pending, and the only ways out were deleting the file or editing the database by hand. `gbrain repair stuck-recovery` previews the blocked file with a diff of the version from before the write against what is on disk now. You then choose: `--keep prior` restores the old version so the write publishes again, or `--keep disk` keeps your edit and drops the write. Either way, both versions are backed up first.++### How to use it++```bash+gbrain repair stuck-recovery --source notes # preview: each blocked file, its diff, the choices+gbrain repair stuck-recovery --source notes --keep prior --apply --expect <hash> --yes+gbrain repair stuck-recovery --source notes --keep disk --apply --expect <hash> --yes+gbrain sources reconcile notes <slug> --brain host --preview # after --keep disk: bring the page in line with your file+```++Run it on the host that owns the source. Only you choose: there is no default `--keep`, and `--all`, `gbrain doctor --remediate` and remediation plans never run it.++### What each choice does++| Your choice | Your file afterwards | The write that was publishing | The page in the database |+|---|---|---|---|+| `--keep prior` | The version from before the write | Queued again and published on the next pass (or ended with the failure it already had) | Updated by that publication |+| `--keep disk` | Your edit, unchanged | Ended as a conflict (`source_changed`), or with the failure it already had | Unchanged until you reconcile it |++### Things to watch++- `--keep prior` discards your edit, and the write that was publishing then overwrites the file again. Check the diff and keep a copy if you need the edit.+- A write that already finished is never changed. If its recovery is still waiting, the preview lists it as refused (`recovery_choice_refused`), because changing it would roll back committed content.+- Shared-skill bundle recoveries (`recovery_bundle_unsupported`) and withdrawal-mirror recoveries (`recovery_effect_unsupported`) are listed and left alone, because either choice could undo a withdrawal.+- If the file or the page changes after the preview, the apply refuses with `preview_changed`. Preview again and apply the new hash.++### Itemized changes++- **New repair kind `stuck-recovery`** (`src/core/repair/stuck-recovery.ts`, `src/core/persistence/recovery-resolve.ts`):+ - It is explicit-only, preview-bound and needs destructive consent. A non-interactive apply without `--yes` exits 3 with the consent payload.+ - `--request-id <uuid>` narrows the preview or apply to one request.+ - The preview prints each file's prior and disk fingerprints (hash, size, mode), plus what recovery sees. It writes the prior, disk and unified-diff files with mode 0600 under `~/.gbrain/backups/stuck-recovery/<request>/<digest>/` and prints the `diff -u` command that reproduces the diff.+ - The preview hash binds the recovery identity, the disk bytes and the page's database revision.+- **Resolution behavior:**+ - The apply takes the worktree lock with a bounded 10-second wait and refuses `writer_lock_unavailable` with nothing changed.+ - `--keep prior` writes the prior bytes through the writer's own durable, confined publication, staged at the recovery's reserved restoration path. An older recovery first reserves that path within the recovery budget, and the apply refuses `queue_capacity` with nothing changed when the budget is full.+ - `--keep disk` ends the request and leaves its recovery record unchanged, so the recovery bytes it reserved are released when the record is cleared.+ - Each step is journaled in `op_checkpoints` (op `stuck-recovery-resolution`). A run killed at any point resumes with the same command, an identical apply replays its recorded result, and a resident writer of any version can finish a resolution this command started.+- **New error codes:** `recovery_bundle_unsupported`, `recovery_choice_refused` and `recovery_effect_unsupported`, each with a section in `docs/guides/repair.md`.+- **Tests:**+ - `test/repair-stuck-recovery.test.ts` (PGLite) covers the preview, both choices on live requests with and without a recorded failure, terminal and effect refusals, the bounded lock wait, staging and byte accounting, kills at every step, mixed-version finish, replay and the consent exit.+ - `test/e2e/repair-stuck-recovery-postgres.test.ts` covers a SIGKILL at each step on real Postgres.++ ## [0.60.219.0] - 2026-10-14++ **A new brain made by `gbrain setup` is finished when setup ends, and a plain-English question to `gbrain recall` now finds facts on a brain without embeddings.** Before, `gbrain setup claude-code` (or `codex`) created a brain and then printed a line telling you to run `gbrain apply-migrations --yes --no-autopilot-install` yourself, so a fresh install still had setup migrations pending and `gbrain doctor` said so. Setup now runs those migrations itself, on the brain it just created, and says which ones it ran. Separately, on a brain with no embeddings, `gbrain recall "how does the user take their coffee"` printed "No matching facts." even when a fact about coffee existed, because recall looked for an entity with that whole sentence as its name. Now it ranks the facts against the sentence as a question and tells you it did.++ ### What you'd see++ | You run | Before | Now |+ |---|---|---|+ | `gbrain setup claude-code` on a new machine | `[init] Migrations: ...` plus a hand-off command to run | `[setup] Migrations: 14 recorded as not needed on a new brain; 5 setup migration(s) applied by setup without installing services (0.11.0, 0.14.0, 0.22.4, 0.28.0, 0.53.0); none pending.` |+ | `gbrain setup claude-code` on a brain that already exists | the hand-off line | the same hand-off line, nothing run |+ | `gbrain recall "how does the user take their coffee"` on a brain without embeddings | `No matching facts.` | the coffee fact, ranked first, with a note on stderr |+ | the same on a brain with embeddings | `No matching facts.` | `No matching facts.`, plus a stderr hint naming `gbrain recall --question "<q>"` |+ | `gbrain recall --help` | the generic one-line stub | recall's own usage, including `--question` |++ ### What to watch for after you upgrade++ - On a brain without embeddings, a multi-word `gbrain recall "<text>"` that matches no entity and no fact text now prints ranked facts instead of "No matching facts." Scripts that relied on the empty result should pass `--grep` or check the stderr note. Brains with embeddings return exactly what they did before.+ - If `~/.claude/AGENTS.md`, `~/.openclaw/AGENTS.md` or an OpenClaw cron manifest already exists, setup does not run v0.11.0 (which would edit that file). It leaves that one migration pending and names the file and the command to run it.+ - `gbrain init` on its own is unchanged and still prints the hand-off line.++ ### Itemized changes++ - **Setup finishes a brain it created** (`src/commands/setup-migrations.ts`, called from `src/commands/setup.ts` only when this run created the brain): one `gbrain apply-migrations --yes --no-autopilot-install --json` child, bounded at 60 s, with `GBRAIN_NO_AUTOPILOT_INSTALL=1`. These migrations are local ledger, schema and file work: no provider calls, no paid work, no services installed, and they run offline. The summary line replaces init's `[init] Migrations:` line. If the run fails, init's line stays with `(setup ran it and it failed: <code>)` appended. Verify output is unchanged.+ - **Host files are never edited silently** (`src/commands/migrations/v0_11_0.ts` `hostRewriteTargets`): setup holds back v0.11.0 when any file its host phase would rewrite already exists.+ - **Keyless question fallback** (`src/commands/recall.ts`, `src/core/facts/keyword-only.ts` `factRecallIsKeywordOnly`): applies only when fact recall is keyword-only (embedding opted out or no provider configured) and the positional has several words and matched nothing. It ranks with the same path as `recall --question` and writes `[recall] no entity or fact text matched '<q>'; ranked facts by relevance to it as a question (keyword-only: this brain has no embeddings).` to stderr.+ - **`gbrain recall --help`** prints `Usage: gbrain recall [<entity>] [options]` with every option, and works without a configured brain.+## [0.60.218.0] - 2026-10-14**Fencing legacy facts no longer leaks, loops or blocks.** When a legacy fact is adopted into a fence row that an earlier, interrupted run left behind, the row is now rebuilt from the stored fact, so the fact's own kind, dates, confidence, visibility and speaker attribution are kept. Before, a leftover row with a different visibility made the adoption refuse every time, and one with the same visibility overwrote the fact's metadata. A managed adoption that gbrain refused as a planning defect is no longer resubmitted every cycle, so the writer stops collecting one identical failed request per page per cycle. And one fact that can't be fenced now holds up only its own page: the phantom-redirect pass runs for the rest of the source.diff --cc src/core/behavior-change-notice.tsindex f177415dfd,3c30a028bd..c9ad719670--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@@ -550,8 -550,9 +550,11 @@@ export const BEHAVIOR_CHANGES: Readonly{ since: '0.60.218.0', text: 'Fencing a legacy fact into a fence row a partial earlier run left behind now rebuilds that row from the stored fact: the published row carries the fact\'s own visibility, kind, validity, confidence and speaker attribution instead of the leftover cell\'s, a leftover private row is never reused for a world fact (the world fact gets its own row), and a newly fenced fact keeps its `attributed_to`. Before, a leftover row with a different visibility made the adoption refuse every time, a leftover row with the same visibility overwrote the fact\'s kind, dates and confidence, and every adoption cleared the fact\'s speaker attribution.' },{ since: '0.60.218.0', text: 'A managed fact-fence adoption refused as a planning defect (`fence_unrenderable`) is no longer resubmitted every cycle: for a day after the refusal the page is reported as unadoptable (`prior_refusal`), then it gets one more try, or right away once the adoption planner changes. The writer stops collecting one identical failed request per page per cycle.' },{ since: '0.60.218.0', text: 'The `extract_facts` phantom-redirect pass no longer waits for the whole source to have no unfenced legacy fact rows: it holds only the top-level pages that own such rows or are the provenance page of an ontology observation (`phantoms_held_legacy_rows` in the cycle report), and redirects the rest.' },+ // Cat 41 run 4 (GBRA-60). `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.+ { since: '0.60.219.0', text: 'When `gbrain setup claude-code` or `gbrain setup codex` creates a new brain, it now runs the setup migrations `gbrain init` leaves pending (the same `gbrain apply-migrations` run, without installing services) and prints `[setup] Migrations: ... none pending.` in place of init\'s "Finish setup" line, so there is nothing left to run. If an existing ~/.claude/AGENTS.md, ~/.openclaw/AGENTS.md or OpenClaw cron manifest would be edited by v0.11.0, setup leaves v0.11.0 pending and names the file and the command. A brain that already existed is not touched, and `gbrain init` on its own still prints the hand-off line.' },+ { since: '0.60.219.0', text: 'On a brain without embeddings, `gbrain recall "<a question>"` (several words that match no entity and no fact text) now ranks facts by relevance to the question, as recall\'s question option does there, with a note, instead of printing "No matching facts." On a brain with embeddings the output is unchanged apart from a hint naming the question command. Recall\'s help now prints its own usage, including the question option.' },+ // #6650 §1.10 (GBRA L2). `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.- { since: '0.60.218.0', text: 'A page write whose recovery is blocked on `unexpected_file_bytes` (its file matches neither the recorded prior nor the published bytes, so every write on that source stays pending) now has a sanctioned exit: `gbrain repair stuck-recovery --source <id>` previews each blocked file with a private diff under ~/.gbrain/backups/stuck-recovery/, and `--keep prior` (restore the prior bytes; the write publishes again) or `--keep disk` (keep your edit; the write ends conflict) with `--apply --expect <hash> --yes` backs up both versions first. A terminal request is never changed. It runs only when named; nothing changes until you apply it, and each resolution is kept as an audit entry that does not expire.' },++ { since: '0.60.219.0', text: 'A page write whose recovery is blocked on `unexpected_file_bytes` (its file matches neither the recorded prior nor the published bytes, so every write on that source stays pending) now has a sanctioned exit: `gbrain repair stuck-recovery --source <id>` previews each blocked file with a private diff under ~/.gbrain/backups/stuck-recovery/, and `--keep prior` (restore the prior bytes; the write publishes again) or `--keep disk` (keep your edit; the write ends conflict) with `--apply --expect <hash> --yes` backs up both versions first. A terminal request is never changed. It runs only when named; nothing changes until you apply it, and each resolution is kept as an audit entry that does not expire.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */