Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(wave17): lane 1 integration: key-files cap, canonical-writer and receipt inventories
time-attack456ee38a0e6d
diff --git a/docs/architecture/canonical-writers.tsv b/docs/architecture/canonical-writers.tsvindex 89085ee6ee..c0eb15ad43 100644--- a/docs/architecture/canonical-writers.tsv+++ b/docs/architecture/canonical-writers.tsv@@ -131,7 +131,7 @@ src/commands/files.ts 0 filesystem_guard Attachment copying, redirection, restorsrc/commands/schema.ts 0 filesystem_guard Schema manifest scaffolding and forks check managed roots before creating files; separate config settings are control data.src/core/ingestion/sources/inbox-folder.ts 0 filesystem_guard Inbox archive moves refuse managed canonical input paths before emitting the event or moving source bytes.src/core/persistence/links-preparation.ts 2 coordinator Automatic graph projections publish inside canonical page transactions; delayed reconciliation locks all affected page keys and compares the originating revision.-src/core/persistence/sync-prepare.ts 8 coordinator Managed imports and deletes validate the recorded raw file hash plus enumerated page identity/revision; a managed rename moves the page with updateSlug and re-infers an implicit type inside the same journal publication after the renamed page's identity and revision are rechecked; the source-exclusive final checkpoint requires every selected receipt to be committed. Its importFromContent calls carry prepare and run inside the coordinator publication. The checkpoint also stamps sources.chunker_version after a full walk (#5566), inside the same source-exclusive publication; the column is outside managed_writer_guard's protected checkpoint tuple.+src/core/persistence/sync-prepare.ts 9 coordinator Managed imports and deletes validate the recorded raw file hash plus enumerated page identity/revision; a managed rename moves the page with updateSlug and re-infers an implicit type inside the same journal publication after the renamed page's identity and revision are rechecked; the source-exclusive final checkpoint requires every selected receipt to be committed. Its importFromContent calls carry prepare and run inside the coordinator publication. The checkpoint also stamps sources.chunker_version after a full walk (#5566), inside the same source-exclusive publication; the column is outside managed_writer_guard's protected checkpoint tuple. #6536: when it records a page's origin it clears that page's database_only_reason='unbound_source' marker in the same publication.src/core/persistence/sync-image.ts 2 coordinator The managed sync image branch prepares through importImageFile with prepare and applies inside the coordinator publication after the sync-wide and import validations rerun; a Git rename versions and soft-deletes the old slug's page in that same transaction, and source_path is stamped there too.src/core/persistence/sync-run.ts 1 coordinator The managed up-to-date heartbeat stamps only sources.last_sync_at inside withCoordinatedWrite, scoped to the checked source id and incarnation; no checkpoint, commit or content-freshness column changes.src/commands/enrich.ts 0 coordinator A managed brain preflights maintenance authority before any model spend and publishes each enriched page through publishMaintenancePage; unmanaged enrichment writes through the put_page operation.@@ -216,6 +216,7 @@ src/core/repair/conversation-labels.ts 4 coordinator `gbrain repair conversationsrc/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/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/frontmatter.ts 2 coordinator `gbrain repair frontmatter --apply` (#5988) publishes a managed source's repaired file only through submitManagedFileRepair (the managed_file_repair request, preview-hash bound). On an unmanaged (legacy) source it writes the previewed bytes after a backup, moves a renamed page with updateSlug and its source_path in one maintenanceTransaction, then imports the file through importFromFile; no canonical writer enforcement applies there.src/commands/sources-mirror.ts 1 engine_guard `gbrain sources mirror-readonly|mirror-writable` (#5409) updates only sources.config.mirror_read_only, exactly as `sources federate` updates sources.config.federated; the sources managed_writer_guard trigger governs the row and no page, fact or file is written.src/core/sync-upstream.ts 1 engine_guard `recordUpstreamObservation` (#5255/#5176) updates only sources.upstream_checked_at, upstream_commit and upstream_behind, observations of the checkout's Git upstream outside managed_writer_guard's protected topology and checkpoint tuples; no page, fact or file is written, and a failure never fails the sync.@@ -227,7 +228,7 @@ src/core/repair/timeline-comments.ts 2 coordinator `gbrain repair timeline-commesrc/core/repair/take-supersession.ts 1 coordinator gbrain repair take-supersession reprojects superseded_by for a page whose fence is already right: a managed_maintenance_take_reproject request replanned under the page key on a managed brain, maintenanceTransaction (revision-checked) on an unmanaged one. Fence edits go through a revision-bound put_page request.src/core/facts/derivation-inputs.ts 3 coordinator hideDerivedRows expires derived facts, deactivates derived takes and soft-deletes derived pages only inside the purge_fact transaction, after write admission and under withCoordinatedWrite on the purge source with the affected page keys locked.src/core/facts/purge.ts 3 coordinator purge_fact deletes the purged fact and take rows and rewrites affected page bodies inside one admitted write transaction under withCoordinatedWrite, after the pending-publication check and page-key locks; the request journal records the terminal receipt.-src/core/persistence/page-purge.ts 2 coordinator purgePageInTransaction deletes the page's filed facts and hard-deletes the page only from the prepared delete_page purge publication callback in page-prepare.ts, under the same source/page identity, revision and durable authority guards as receipt completion.+src/core/persistence/page-purge.ts 4 coordinator purgePageInTransaction deletes the page's filed facts and hard-deletes the page only from the prepared delete_page purge publication callback in page-prepare.ts, under the same source/page identity, revision and durable authority guards as receipt completion. #6619: in the same callback it deletes the purged page's page_aliases and the slug_aliases redirects that resolve to it.src/core/trust/fence-append.ts 1 coordinator withPageTierKept restores the page's prior trust_tier and write_origin in the same coordinated fence-append transaction that wrote the page (fence-write, facts-prepare and memory-prepare callers); it changes no content column.src/commands/sources-trust.ts 1 engine_guard gbrain sources set-trust rewrites only the source's config jsonb (its default trust tier for future writes); the managed writer guard exempts sources rows whose id, incarnation, local_path, archived and checkpoint columns are unchanged, and no knowledge row changes.src/core/trust/claim.ts 2 engine_guard gbrain trust claim-sources records the claim and its lift receipt in the source's config jsonb only (like sources set-trust); the managed writer guard exempts sources rows whose identity columns are unchanged. The tier lift itself runs through trust/backfill.ts inside withCoordinatedWrite on a managed brain.diff --git a/docs/architecture/key-files/commands-2.md b/docs/architecture/key-files/commands-2.mdindex b215a4f6e5..2a276576e6 100644--- a/docs/architecture/key-files/commands-2.md+++ b/docs/architecture/key-files/commands-2.md@@ -11,7 +11,7 @@ Doctor's embedding-dimension warning treats existing chunks as existing data eve- `src/commands/doctor/checks/vector-plan.ts` — `vector_plan` (#5824, OPS, wave check with operator resolution). Postgres only: EXPLAINs (no ANALYZE) the statement `searchVector` emits for the active embedding column with a zero vector through `PostgresEngine.explainVectorSearch` (same builder, scoped read transaction and scan settings) and warns when an HNSW-indexed column's plan does not use its HNSW index, naming the observed scans, whether the index exists and is valid (`pg_index.indisvalid`, with the create/reindex command), the 8 s candidate-budget risk and the legacy guard as rollback. Skipped on PGLite, on columns wider than the HNSW cap, and below 10,000 embedded chunks (`pg_class.reltuples` x `pg_stats.null_frac`, a bounded count when never analyzed). A configured legacy guard warns "active after restarting the owning service". Details carry a sampled stale-text fraction and point to `gbrain embed --stale` above 5%. Tested in `test/e2e/vector-plan-real-column-postgres.test.ts` (empty, small, ok, unused valid index, INVALID index, guard via env and config).- `src/commands/doctor/checks/persistence-requests.ts` — wave checks (OPS, registered in `wave-checks.ts`); `persistence_terminal_failures` (#6650) is in [Managed sync bookkeeping](managed-sync-bookkeeping.md). `persistence_request_indexes` (#5762) reports each managed sync request index missing, INVALID or still building (with progress) and names `gbrain repair request-indexes --apply`. `persistence_request_growth` reports the request-table row count (a `reltuples` estimate on Postgres), each scope's admission rate over the last 7 days (the newest 10,000 admissions per scope, one bounded index read), lifetime IDs against `persistence.limits.*` and the projected exhaustion date within ten years; it warns under 90 days with the `oneYearCapacity` `gbrain config set` value and the doctor re-check. `persistence_write_stall` (#6176, host-only) reads running requests and warns when one has held its claim longer than `persistence.max_claim_ms` (`claim-phase.ts`; an owner that predates phase recording falls back to the request's age on the database clock), naming the stuck phase, the root, the claim age, the queued writes behind it and whether the request resumes on its own, with `gbrain sources writer status --source <id> --json` as the fix. `persistence_session_timeouts` (#6278, host-only) reads `SHOW statement_timeout` through the configured URL and warns `session_timeouts_not_applied` when it is `0` while `resolveSessionTimeouts()` configured one (a transaction-mode pooler dropped the startup parameter), naming the role-level fix. Tests: `test/persistence-request-indexes.test.ts`, `test/e2e/persistence-request-indexes-postgres.test.ts`, `test/persistence-write-stall.test.ts`, `test/persistence-session-timeouts-check.test.ts`.- `src/commands/doctor/checks/{persistence-capacity,parked-effects}.ts` — `persistence_capacity` (OPS) warns when a principal or the brain reaches 80% of permanent request IDs or receipt bytes (via `capacityDiagnostics`) and prints one `gbrain config set <key> <value>` per brain-wide key, using the largest value any scope needs for about one more year; transient caps never warn. `parked_effects` (BRAIN) reads the partial parked-effect index, counts exactly, samples 20, and names each parked page with its `retry-effects ... --dry-run` command. Both report `exact`/`inspected`/`truncated` details; an unreadable state is warn, never clean. Tests: `test/persistence-capacity.test.ts`, `test/persistence-effect-parking.test.ts`.-- `src/commands/doctor/checks/unbound-source.ts` — `unbound_source` (#5254) counts live pages with `pages.database_only_reason='unbound_source'` and no recorded origin (blank `source_path` and `source_uri`) per source, using `databaseOnlyPageSql` from `persistence/unbound-pages.ts`, the SQL form of the `isDatabaseOnlyPage` predicate persistence uses (#6536; parity pinned by `test/unbound-source-6536.test.ts`). A managed sync that records a page's origin, and a reconcile apply, clear the marker. While the source is unbound the count is ok and the message carries the filled `sources writer status`/`writer claim` bind command (database-only is the chosen mode); once the source has a binding it warns, because binding never materializes those pages into canonical files. Unreadable state warns. Registered on the `persistence_capacity` line in `doctor.ts`. Tests: `test/e2e/unbound-source-postgres.test.ts`, `test/unbound-source-6536.test.ts`.+- `src/commands/doctor/checks/unbound-source.ts` — `unbound_source` (#5254) counts live pages with `pages.database_only_reason='unbound_source'` and no recorded origin (blank `source_path` and `source_uri`) per source, via `databaseOnlyPageSql` (`persistence/unbound-pages.ts`), the SQL form of `isDatabaseOnlyPage` (#6536). A managed sync that records a page's origin, and a reconcile apply, clear the marker. While the source is unbound the count is ok and the message carries the filled `sources writer status`/`writer claim` bind command (database-only is the chosen mode); once the source has a binding it warns, because binding never materializes those pages into canonical files. Unreadable state warns. Registered on the `persistence_capacity` line in `doctor.ts`. Tests: `e2e/unbound-source-postgres`, `unbound-source-6536`.- `src/commands/doctor/checks/revision-backfill.ts` — `revision_backfill` (#5216, META, registered before `search_mode`): reads `readRevisionBackfillStatus` (column state, pages still without `knowledge_revision`, failed rows still pending with their page). ok when the column is NOT NULL; warn with the pending count and `gbrain apply-migrations --force-schema` as `fix` while any row is resumable (or only the NOT NULL step remains); failed rows are listed by page id, `source:slug`, attempt and error, and when only rows with spent attempts remain the `fix` is the read-only `gbrain repair orphan-children` preview. Tests: `test/doctor-revision-backfill.test.ts`.- `src/commands/doctor/checks/extractor-facts.ts` — `extractor_facts_expired` (#5731): counts conversation-extractor facts the pre-v0.60.11.0 projection expired, by class (`evidenced`, `ambiguous`; `excluded` reported but never a finding) through `classifyExtractorFacts`, and names `gbrain repair extractor-facts` (explicit-only, so the remediation plan and banner list it with its preview). Read-only; health unknown when the query fails.- `src/commands/doctor/checks/conversation-outcomes.ts` — `conversation_label_facts` (wave check, host-only, resolution `repair`): bounded count (capped at 1000, reported as at least N) of the default set `gbrain repair conversation-labels` would retire; names the preview, never the apply. `conversation_outcomes_stale` (wave check, host-only, resolution `operator`): counts active conversation extraction outcomes stamped with an older `extractor_version` than `CONVERSATION_EXTRACTOR_VERSION` (outcomes are never reopened automatically) and names the `--force --dry-run` re-extract preview; outcomes older than the stamp are counted as `unstamped` and never warn. Bounded scan of the extractor rows, capped at 5000 (reported as at least N). Read-only.diff --git a/test/receipt-coverage.test.ts b/test/receipt-coverage.test.tsindex 9f7a2a2e7d..cf17854e54 100644--- a/test/receipt-coverage.test.ts+++ b/test/receipt-coverage.test.ts@@ -38,6 +38,7 @@ const RECEIPT_COVERAGE: Record<string, Coverage> = {'src/core/page-state/materialize.ts': { sites: 1, tables: ['pages'], todo: 'TODO(receipts): derived page materialization should publish as a maintenance intent' },'src/core/timeline-extract.ts': { sites: 1, tables: ['timeline_entries'], todo: 'TODO(receipts): timeline retraction should publish like managed_maintenance_timeline_extract' },'src/commands/reindex-aliases.ts': { sites: 1, tables: ['page_aliases', 'slug_aliases'], todo: 'TODO(receipts): reindex --aliases should publish per page as a maintenance intent' },+ 'src/core/repair/aliases.ts': { sites: 1, tables: ['page_aliases', 'slug_aliases'], todo: 'TODO(receipts): gbrain repair aliases (#6619) deletes alias rows whose target page no longer exists (no page, no content column) in withCoordinatedWrite as explicit-only maintenance without a request; publish each item as a maintenance intent' },'src/core/repair/timeline-comments.ts': { sites: 1, tables: ['timeline_entries'], todo: 'TODO(receipts): gbrain repair timeline-comments row cleanup should publish per page as a maintenance intent' },'src/core/mentions/pass.ts': { sites: 1, tables: ['page_aliases'], todo: 'TODO(receipts): derived alias rows should publish per page as a maintenance intent' },'src/core/bootstrap/verify.ts': { sites: 1, tables: ['facts'], todo: 'TODO(receipts): bootstrap verify deletes its own probe facts without a request; publish the cleanup as a maintenance intent' },