Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(doctor): goldens gain atom_retirements_restorable and parked_effects git_push_holds; writer inventories list atoms-restore

garrytan957642c1ebfb
diff --git a/docs/architecture/canonical-writers.tsv b/docs/architecture/canonical-writers.tsv
index 745912202f..9631217366 100644
--- a/docs/architecture/canonical-writers.tsv
+++ b/docs/architecture/canonical-writers.tsv
@@ -8,7 +8,7 @@ src/core/persistence/origin-guard.ts 2 engine_guard #6948 bindOrigin records a p
src/core/persistence/takes-prepare.ts 4 coordinator Semantic takes apply only through the journal publication callback after current revision, holder and authority validation. takes_remove deletes the removed row inside the same coordinated apply (#5167).
src/commands/extract-timeline-db.ts 2 coordinator `gbrain extract timeline --source db` (#5904): on a managed brain the timeline retraction and insert run only inside the managed_maintenance_timeline_extract publication (prepareTimelineExtract; owner-checked by maintenancePreflight, page key locked, revision-bound); only an unmanaged brain retracts and batch-inserts directly, where no canonical writer enforcement applies.
src/commands/extract-conversation-facts.ts 4 coordinator On a managed brain each page's fact rows and outcome row are frozen into one database-only managed_maintenance_conversation_facts request (facts/conversation-publication.ts) after a maintenance preflight before provider work; the coordinator's preparer revalidates page identity, revision and parser-input snapshot under the page key. Unmanaged calls keep their direct engine writes behind the SQL guard (writeDerivedFacts refuses on a managed brain).
-src/core/facts/conversation-publication.ts 6 coordinator The managed conversation-facts preparer, only for a complete replacement (#7013; otherwise it keeps the prior facts and replaces only the outcome row), clears the page's extractor rows (deleting them, but expiring rows an open loop or another fact's superseded_by references and keeping rows a label repair retired) and inserts each member page's frozen entry inside the coordinator publication of its admitted managed_maintenance_conversation_facts batch request, after rechecking authority, page identity, revision and version token under each page key (a moved page is skipped and reported, never failing the batch; a page whose rows fail validation gets a blocked not-extractable outcome row); a lost insert rolls the publication back. The unmanaged extractor runs the same publication in its maintenance transaction. The clear also expires rows the free conversation relink linked, after deleting the previous clear's expired relinked copies, so the replacement inherits their entity (#6764, conversation-relink-carry.ts).
+src/core/facts/conversation-publication.ts 7 coordinator The managed conversation-facts preparer, only for a complete replacement (#7013; otherwise it keeps the prior facts and replaces only the outcome row), clears the page's extractor rows (deleting them, but expiring rows an open loop or another fact's superseded_by references and keeping rows a label repair retired) and inserts each member page's frozen entry inside the coordinator publication of its admitted managed_maintenance_conversation_facts batch request, after rechecking authority, page identity, revision and version token under each page key (a moved page is skipped and reported, never failing the batch; a page whose rows fail validation gets a blocked not-extractable outcome row); a lost insert rolls the publication back. The unmanaged extractor runs the same publication in its maintenance transaction. The clear also expires rows the free conversation relink linked, after deleting the previous clear's expired relinked copies, so the replacement inherits their entity (#6764, conversation-relink-carry.ts).
src/core/facts/conversation-relink.ts 1 coordinator `gbrain facts relink --conversation` (#6764) sets entity_slug and the relink note on a conversation page's unlinked derived rows still exactly as planned (same claim, unlinked, active, target page live) under the page key: one database-only managed_maintenance_conversation_relink request per page on a managed brain (the preparer authorizes the anchor and the page), one writeDerivedFacts maintenance transaction per page on an unmanaged brain.
src/commands/extract.ts 7 engine_guard Canonical table SQL trigger requires coordinator capability; legacy calls fail before canonical DB publication. On a managed brain extract --stale inserts only the canonical timeline tuples inside withCoordinatedWrite for that page, after the revision-bound derived-link replacement locked and verified the page revision in the same transaction.
src/commands/frontmatter.ts 0 filesystem_guard Batch frontmatter repair preflights every target before the first backup/write.
@@ -225,6 +225,7 @@ src/core/repair/facts-rehome.ts 1 coordinator `gbrain repair facts-rehome` (B-7,
src/core/repair/conversation-labels.ts 4 coordinator `gbrain repair conversation-labels` expires preview-approved label-misattributed conversation facts, expires the page completion marker and writes the not-extractable outcome, under the page key: one database-only managed_maintenance_conversation_label_retire request per batch of up to 25 pages on a managed brain (the preparer reclassifies each page under its lock), one maintenanceTransaction per batch on an unmanaged brain.
src/core/persistence/atom-maintenance.ts 1 coordinator A managed atom retirement stamps retired_by/retired_at on the tombstone inside the coordinator publication of its managed_atom_delete request, after the page deletion path removed the canonical file, so the database row and file change commit or roll back together.
src/core/repair/stale-atoms.ts 2 coordinator gbrain repair stale-atoms retires an atom on a managed brain through a managed_maintenance_retire_stale_atoms coordinated request (the marker stamp runs in its publication); only an unmanaged brain soft-deletes and stamps in a direct page-locked transaction, where no canonical writer enforcement applies.
+src/core/repair/atoms-restore.ts 2 coordinator gbrain repair atoms-restore (#7013) restores a preview-approved atom an empty re-extraction retired: on a managed brain only through a managed_maintenance_restore_reextract_atom request (deleted_page admission, revision-bound, the restore rule rechecked under the atom and origin locks, then a revert_version to the pre-stamp version); only an unmanaged brain archives, restores and unstamps the atom in one page-locked maintenanceTransaction, where no canonical writer enforcement applies.
src/core/repair/ghost-pages.ts 1 coordinator `gbrain repair ghost-pages` (#6696 B5) retires a preview-approved ghost page (its canonical file is gone): on a managed brain only through a managed_maintenance_retire_ghost_page request whose preparer reruns the classifier under the approved owner and prepares a delete_page with allowMissingFile that refuses unless the file target is the approved path with no bytes (a restored file refuses at preparation or at filesystem publication); only an unmanaged brain versions and soft-deletes directly, inside maintenanceTransaction under the page lock after the revision, page id and file-absence recheck.
src/core/repair/aliases.ts 2 coordinator `gbrain repair aliases` (#6619) deletes preview-approved page_aliases / slug_aliases rows whose target page no longer exists (soft-deleted targets are never touched), under the page key: inside withCoordinatedWrite with maintenance attribution on a managed brain, one transaction on an unmanaged brain.
src/core/repair/rename-identity.ts 5 early_refusal `gbrain repair rename-identity` (#6729) carries a previewed old page's identity onto its new slug only on an unmanaged brain: the plan and the apply refuse `managed_remedy_unavailable` on a managed brain before any canonical write. The unmanaged carry runs in one maintenanceTransaction under both page locks after the plan-hash, open-record and fence-row recheck: it merges matching fence rows onto the old rows (never valid_until), retires the provisional page under its purged slug, moves the old page to the new slug (updateSlug) and imports the new file it read from the checkout; it writes no file, so there is no filesystem ordering to keep.
diff --git a/docs/architecture/system-of-record.md b/docs/architecture/system-of-record.md
index 4ed6ba5e60..540754b0e6 100644
--- a/docs/architecture/system-of-record.md
+++ b/docs/architecture/system-of-record.md
@@ -222,7 +222,6 @@ Attributed (inside a request, a coordinated scope or `maintenanceTransaction`,
or a physical projection that leaves attribution untouched):
<!-- write-attribution-covered:start -->
-- `src/commands/extract-conversation-facts.ts` (2): the unmanaged conversation fact index publishes each page's extracted rows and outcome row once through `writeDerivedFacts` (one `maintenanceTransaction` at the page's derived tier) running `publishConversationFacts` (`facts/conversation-publication.ts`), which also runs the write gate; managed brains publish each page as a receipted `managed_maintenance_conversation_facts` request.
- `src/commands/extract-timeline-db.ts` (2): `gbrain extract timeline --source db` commits one `maintenanceTransaction` per 100-row batch on unmanaged brains; managed brains publish per page through a maintenance request.
- `src/commands/migrate-engine.ts` (5): engine copy keeps the source rows' attribution values verbatim.
- `src/commands/sync/holds.ts` (1): a full sync's move of a held rename (`updateSlug` and its `source_path`) runs in one `maintenanceTransaction`; managed sources publish renames through the sync request preparer.
@@ -289,6 +288,7 @@ or a physical projection that leaves attribution untouched):
- `src/core/persistence/sync-prepare.ts` (4): managed sync request preparer.
- `src/core/persistence/sync-streamed.ts` (1): the streamed sync of a file over the single-string ceiling moves a renamed page (`updateSlug`) in its request's apply, inside the coordinated publication.
- `src/core/persistence/takes-prepare.ts` (3): takes request preparer.
+- `src/core/repair/atoms-restore.ts` (3): the unmanaged `gbrain repair atoms-restore` apply archives the retired atom's version, restores it and drops its `retired_by`/`retired_at` stamp in one `maintenanceTransaction`; managed brains publish a `managed_maintenance_restore_reextract_atom` request instead.
- `src/core/repair/captured-facts.ts` (1): a request on managed brains; the unmanaged captured-facts expiry runs in `maintenanceTransaction`.
- `src/core/repair/conversation-labels.ts` (4): a request on managed brains; the unmanaged label retirement runs in `maintenanceTransaction`.
- `src/core/repair/extractor-facts.ts` (1): a request on managed brains; the unmanaged extractor-facts restore runs in `maintenanceTransaction`.
diff --git a/test/fixtures/goldens/doctor/content-pglite-human.json b/test/fixtures/goldens/doctor/content-pglite-human.json
index b13f6de40b..f80fc599da 100644
--- a/test/fixtures/goldens/doctor/content-pglite-human.json
+++ b/test/fixtures/goldens/doctor/content-pglite-human.json
@@ -121,6 +121,7 @@
" [OK] stale_embedding_effects: No committed write has a stale queued or failed embedding effect.",
" [OK] google_file_modes: No group- or world-readable gbrain files under Google source directories outside ~/.gbrain.",
" [OK] google_calendar_readable: No Google source recorded an unreadable calendar at its last sync.",
+ " [OK] atom_retirements_restorable: No atom retired by an empty re-extraction is waiting to be restored.",
" [OK] extractor_facts_expired: No conversation-extractor fact is left expired by the pre-v0.60.11.0 projection.",
" [OK] conversation_label_facts: No conversation fact carries the pre-fix meeting-label signature (a 1970-01-01 segment on a label page).",
" [OK] conversation_outcomes_stale: No conversation extraction outcome predates extractor version 1.",
diff --git a/test/fixtures/goldens/doctor/content-pglite-json.json b/test/fixtures/goldens/doctor/content-pglite-json.json
index 47778bd5e4..f714a6a089 100644
--- a/test/fixtures/goldens/doctor/content-pglite-json.json
+++ b/test/fixtures/goldens/doctor/content-pglite-json.json
@@ -898,6 +898,7 @@
"details": {
"effects": [],
"exact": true,
+ "git_push_holds": [],
"inspected": 0,
"parked_effects": 0,
"truncated": false
@@ -1624,6 +1625,24 @@
"name": "google_calendar_readable",
"status": "ok"
},
+ {
+ "category": "brain",
+ "details": {
+ "by_source": [],
+ "count": 0,
+ "docs": "docs/guides/repair.md#atoms-restore",
+ "hold_until": null,
+ "newest_retired_at": null,
+ "oldest_retired_at": null,
+ "origins": 0,
+ "repair": "atoms-restore",
+ "source_ids": []
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No atom retired by an empty re-extraction is waiting to be restored.",
+ "name": "atom_retirements_restorable",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {
diff --git a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
index 7ac64be993..4a38a2225c 100644
--- a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
@@ -958,6 +958,7 @@
"details": {
"effects": [],
"exact": true,
+ "git_push_holds": [],
"inspected": 0,
"parked_effects": 0,
"truncated": false
@@ -1792,6 +1793,24 @@
"name": "google_calendar_readable",
"status": "ok"
},
+ {
+ "category": "brain",
+ "details": {
+ "by_source": [],
+ "count": 0,
+ "docs": "docs/guides/repair.md#atoms-restore",
+ "hold_until": null,
+ "newest_retired_at": null,
+ "oldest_retired_at": null,
+ "origins": 0,
+ "repair": "atoms-restore",
+ "source_ids": []
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No atom retired by an empty re-extraction is waiting to be restored.",
+ "name": "atom_retirements_restorable",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {
@@ -5236,6 +5255,7 @@
"details": {
"effects": [],
"exact": true,
+ "git_push_holds": [],
"inspected": 0,
"parked_effects": 0,
"truncated": false
@@ -6070,6 +6090,24 @@
"name": "google_calendar_readable",
"status": "ok"
},
+ {
+ "category": "brain",
+ "details": {
+ "by_source": [],
+ "count": 0,
+ "docs": "docs/guides/repair.md#atoms-restore",
+ "hold_until": null,
+ "newest_retired_at": null,
+ "oldest_retired_at": null,
+ "origins": 0,
+ "repair": "atoms-restore",
+ "source_ids": []
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No atom retired by an empty re-extraction is waiting to be restored.",
+ "name": "atom_retirements_restorable",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {
diff --git a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
index a4f3559947..fce2bc2aa6 100644
--- a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
@@ -961,6 +961,7 @@
"details": {
"effects": [],
"exact": true,
+ "git_push_holds": [],
"inspected": 0,
"parked_effects": 0,
"truncated": false
@@ -1797,6 +1798,24 @@
"name": "google_calendar_readable",
"status": "ok"
},
+ {
+ "category": "brain",
+ "details": {
+ "by_source": [],
+ "count": 0,
+ "docs": "docs/guides/repair.md#atoms-restore",
+ "hold_until": null,
+ "newest_retired_at": null,
+ "oldest_retired_at": null,
+ "origins": 0,
+ "repair": "atoms-restore",
+ "source_ids": []
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No atom retired by an empty re-extraction is waiting to be restored.",
+ "name": "atom_retirements_restorable",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {
@@ -5240,6 +5259,7 @@
"details": {
"effects": [],
"exact": true,
+ "git_push_holds": [],
"inspected": 0,
"parked_effects": 0,
"truncated": false
@@ -6076,6 +6096,24 @@
"name": "google_calendar_readable",
"status": "ok"
},
+ {
+ "category": "brain",
+ "details": {
+ "by_source": [],
+ "count": 0,
+ "docs": "docs/guides/repair.md#atoms-restore",
+ "hold_until": null,
+ "newest_retired_at": null,
+ "oldest_retired_at": null,
+ "origins": 0,
+ "repair": "atoms-restore",
+ "source_ids": []
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No atom retired by an empty re-extraction is waiting to be restored.",
+ "name": "atom_retirements_restorable",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {
diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.json
index 9a821f3a29..6a6ec317ac 100644
--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json
+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json
@@ -822,6 +822,7 @@
"details": {
"effects": [],
"exact": true,
+ "git_push_holds": [],
"inspected": 0,
"parked_effects": 0,
"truncated": false
diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.json
index 852583fe18..709f1565f1 100644
--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json
@@ -869,6 +869,7 @@
"details": {
"effects": [],
"exact": true,
+ "git_push_holds": [],
"inspected": 0,
"parked_effects": 0,
"truncated": false
diff --git a/test/fixtures/goldens/doctor/json-postgres-fresh.json b/test/fixtures/goldens/doctor/json-postgres-fresh.json
index 308c5f8cf1..d4ebba0b02 100644
--- a/test/fixtures/goldens/doctor/json-postgres-fresh.json
+++ b/test/fixtures/goldens/doctor/json-postgres-fresh.json
@@ -872,6 +872,7 @@
"details": {
"effects": [],
"exact": true,
+ "git_push_holds": [],
"inspected": 0,
"parked_effects": 0,
"truncated": false
@@ -1573,6 +1574,24 @@
"name": "google_calendar_readable",
"status": "ok"
},
+ {
+ "category": "brain",
+ "details": {
+ "by_source": [],
+ "count": 0,
+ "docs": "docs/guides/repair.md#atoms-restore",
+ "hold_until": null,
+ "newest_retired_at": null,
+ "oldest_retired_at": null,
+ "origins": 0,
+ "repair": "atoms-restore",
+ "source_ids": []
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No atom retired by an empty re-extraction is waiting to be restored.",
+ "name": "atom_retirements_restorable",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {