Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge remote-tracking branch 'origin/master' into capy/gbrain-repair-stuck-recovery

garrytan6462e3bb18fe
diff --cc CHANGELOG.md
index 0df7c31075,82878081e2..117f87cbf0
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -10,52 -10,19 +10,65 @@@ credits are retained; no result has bee
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
- ## [0.60.218.0] - 2026-10-13
++## [0.60.219.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.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.
+
+ ### Itemized changes
+
+ - **Leftover fence rows** (`src/core/facts/unfenced-facts.ts`): a leftover row is reused only when that can't widen its visibility (a private row is never reused for a world fact; the world fact gets its own row), and the reused row is re-rendered from the legacy fact. A newly fenced fact keeps its `attributed_to`.
+ - **One read-back check** (`src/core/facts-fence.ts` `fenceCellReadBackProblem`): the planner runs the publisher's own check on the whole rendered fence before it submits. A page that fails is reported as unadoptable (class `whole_fence`) and nothing is submitted.
+ - **No resubmission loop** (`src/core/persistence/prepared-maintenance.ts`): a `fence_unrenderable` refusal of the same intent in the last day is not resubmitted. The page is reported as unadoptable (class `prior_refusal`). It gets one more try after a day, or right away once the adoption planner changes (its revision is part of the request identity).
+ - **Phantom redirects** (`src/core/cycle/extract-facts.ts`, `src/core/cycle/phantom-redirect.ts`): the pass holds only top-level pages that own legacy fact rows, or that are the provenance page of an ontology observation, instead of waiting for the whole source. Held pages are excluded before the per-pass cap, so they never crowd out other phantoms. The count is `phantoms_held_legacy_rows` in the cycle report.
+ - **Stale plans** (`src/core/facts/unfenced-facts.ts`): when a legacy fact changed between planning and submission, the page is skipped and replanned next run, so an older plan never writes old metadata back over the newer row.
+ - **Census** (`scripts/diagnose/fence-adoption-census.sql`): a read-only query that counts failed adoptions by build, code and message (first and last seen, last 24 hours) and shows how many of those pages still hold legacy facts.
+
## [0.60.217.0] - 2026-10-13
**Pages whose writes keep refusing `source_changed` can now be listed, resolved and measured, and maintenance stops adding to the pile (#6643).** A page whose canonical file differs from its database copy refuses every coordinated write with `source_changed` (`file_database_drift`) until someone reconciles it. Nothing listed those pages, nothing resolved them in bulk, and `synthesize_concepts` paid for a new narrative for each drifted concept on every cycle and left another conflict receipt each time. Now the audit groups the receipts by page, maintenance checks the file before it spends or admits anything, `gbrain repair file-drift` resolves the pages through canonical reconciliation, and doctor counts what is left.
diff --cc src/core/behavior-change-notice.ts
index cb76a3b36f,35359a9b8e..f177415dfd
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@@ -546,8 -546,10 +546,12 @@@ export const BEHAVIOR_CHANGES: Readonly
{ since: '0.60.217.0', text: '`synthesize_concepts` now checks each concept page against its canonical file before it calls a model or admits a write. A concept whose file differs from the database (`file_database_drift`) is skipped on every cycle, recorded in `dream.concepts.drift_skips` and released once the file and database agree, and the phase reports `warn` naming `gbrain sources reconcile <source> --brain host --audit --conflicts` and `gbrain repair file-drift`. Before, it paid for a narrative per drifted concept every cycle and left another `source_changed` conflict receipt.' },
{ since: '0.60.217.0', text: 'A maintenance write (a dream-cycle page publication) to a page whose canonical file differs from the database now refuses `source_changed` with detail `file_database_drift` before admission and leaves no request row, instead of being admitted and ending as a conflict receipt. A replay of an earlier request with the same id still returns its receipt.' },
{ since: '0.60.217.0', text: 'Doctor has a new `maintenance_write_drift` check: it warns when pages behind recent `file_database_drift` conflict receipts (or recorded concept skips) still have a canonical file that differs from the database, and names the read-only `--audit --conflicts` listing and the explicit-only `gbrain repair file-drift` preview. New: `gbrain sources reconcile <source> --audit --conflicts`, MCP `list_write_conflicts` (read scope; database-derived fields only for remote callers) and `gbrain repair file-drift --prefer file|database`.' },
+ // #6650 (fact-fence adoption exits). `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.
+ { 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.' },
+ // #6650 §1.10 (GBRA L2). `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.
- { since: '0.60.217.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.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.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */