Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge remote-tracking branch 'origin/master' into capy/6712-overwrite-detect

garrytan16af26fe69a6
diff --cc docs/architecture/key-files/canonical-reconciliation.md
index 7fbff7b2ee,c824c163cf..b02d47c3cf
--- a/docs/architecture/key-files/canonical-reconciliation.md
+++ b/docs/architecture/key-files/canonical-reconciliation.md
@@@ -21,9 -21,8 +21,11 @@@
- `src/core/repair/file-drift.ts` — `gbrain repair file-drift` (#6643): explicit-only, preview-bound resolution of drifted pages through `reconcileCanonical` with one side preferred (`preferSideDecisions`) inside reconcile's protections; `driftExceptions` lists where the result differs from the preferred side. The preview writes a private artifact under `configDir()/repair-previews/file-drift/<hash>.json` and saves the approved set; apply runs `runReconcileApply` per page under request ids derived from the hash and slug, so an interrupted apply resumes. `--all-drifted` refuses mixed drift classes unless `--class` keeps one. Repeatable `--only`/`--skip` over the source-relative canonical file path (`src/core/repair/path-glob.ts` `matchesRepairPath`: a value without `*` is an exact path, as every kind's `--only`; with `*` it is a glob, file-drift only: `*` within a segment, `**` across) narrow the selection before the class check, the 1,000-page bound and any preview work (`not_selected` residual); they join the selection digest only when given (so earlier hashes are unchanged) and appear in every printed preview and apply command. `prepareDriftPage` builds one page's ready reconcile preview for a preferred side; the plan and the keep_db policy share it. `--keep` is refused at parse in `src/commands/repair.ts` with the same command rewritten to `--prefer database`. `reconcile-prepare.ts` keeps the file bytes when they already parse to the result digest. Doctor `maintenance_write_drift` (`src/commands/doctor/checks/maintenance-drift.ts`) counts what remains and, on the owner host, echoes each declared `storage.keep_db` policy as `keep_db_policy` (prefixes, matched drifted pages among those checked live, `unchecked`, receipt cost from `keepDbReceiptCost`). #6712 wave: a selected page whose `liveFileDrift` reason is `canonical_file_missing` goes through `fileGonePage` (`ghostPageNow` for the path, revision and owner; `canonicalDeletionState` for the route): still committed at HEAD is listed `deletion_uncommitted`, gone from HEAD becomes a `prepareDriftPage(..., { fileGone: true })` recreate (`file_gone`, details `action: 'recreate_file'`; a warning when `gitDurabilityPolicy` is not durable, since an uncommitted recreated file loses to the committed deletion on the next sync) or a `SoftDeletePage` applied through `retireGhost` (exported from `repair/ghost-pages.ts`, under the file-drift request id) with the ghost-pages mass valve; `--all-drifted` never selects missing files.
- `src/core/ghost-pages.ts` — #6696 B5, the one ghost-page classifier: a ghost is a live page for which `liveFileDrift` returns reason `canonical_file_missing` on the source's canonical owner host (`prepareFileTarget` tags that refusal `detail: 'canonical_file_missing'`). `scanGhostSource` reads a source's live pages in id order (at most `GHOST_SCAN_LIMIT`), resolves each recorded canonical path exactly as `prepareFileTarget` does and stats it, skips `publishesDatabaseOnly` and legacy slugs, and runs the full check on at most `candidateLimit` candidates; it returns the ghosts, `inspected`, `file_backed` (the mass-delete valve's population), `truncated` and the owner it ran under (host, worktree, owner epoch, incarnation). Off the owner host a source is `not_applicable` (`not_owner_host`, or `not_applicable` with no binding); a missing root is `unknown` (`storage_unavailable`), a stat error, invalid gbrain.yml or inconclusive check `unknown` (`ambiguous_storage`). `ghostPageNow` re-checks one page (the repair's recheck); `readGhostPages(engine, { sourceIds?, sampleLimit? })` is the counts-and-samples summary for doctor and the read-scope health op. Tests: `test/ghost-pages-6696.test.ts`.
- `src/core/repair/ghost-pages.ts` — `gbrain repair ghost-pages --source <id>` (#6696 B5): explicit-only, preview-bound, destructive consent (`GHOST_CONSENT_TEXT`: the 72 h purge fuse, the per-slug `gbrain restore <slug> --force` undo, and the keep path of restoring the file and syncing). The preview binds the ghost set to the owner and each page's revision and path; the apply refuses `not_owner_host`, `ghost_storage_unknown`, `preview_changed` on an owner change, and `ghost_mass_delete_refused` (`massGhosts`: the sync valve, `MASS_RECONCILE_RATIO` over more than `MASS_RECONCILE_MIN_PAGES` file-backed pages, unless `massReconcileAllowed()`). Each page re-checks with `ghostPageNow`, then a managed brain submits one `managed_maintenance_retire_ghost_page` request (`prepareGhostPageRetirement`, dispatched from `prepared-maintenance.ts`: re-check, `delete_page` with `allowMissingFile`, refusal unless the prepared file target is the approved path with no bytes, so filesystem publication refuses a file that appeared later); an unmanaged brain soft-deletes in one transaction after the same check. Outcomes `soft_deleted`, `file_restored` (asks for a new preview), `changed_since_preview`. Doctor `ghost_pages` (`src/commands/doctor/checks/ghost-pages.ts`, BRAIN, after `fence_integrity`) reports the count, samples and coverage with the preview as its fix, `ok` + info off the owner host, unknown on an unreadable checkout; `gbrain pages ghosts` (`src/commands/pages-ghosts.ts`) lists them read-only.
+ - `src/core/persistence/unindexed-files.ts` — #6865 the unindexed-file detector: `findUnindexedFiles(engine, sourceId, opts)` streams `git ls-tree -r -l -z` of the source's last synced commit, filters it through discovery's own `loadSyncEligibility`, and in batches (one `pages.source_path = ANY` read on `pages_source_path_idx`, one hold read by fingerprint) keeps files with no live page recording their origin (source-path space, with the legacy Git-root spelling in source-root mode), no hold and no scheduled re-screen (`readGitHoldRetryPaths`; those count as `scheduled`); a file whose path slug belongs to a live page with another or no origin is still unindexed and counted `slug_taken`. Found files are screened read-only with `screenImportContent` (at most 2,000 per pass, the rest `unscreened`). Folder-scaffolding names sync skips on purpose (`isSyncMetafile`) that would otherwise be eligible (checked against a probe name in the same directory plus `sync.exclude` and the reserved skill paths) and carry a frontmatter `type:` or `title:` are counted apart as `metafile_skipped` with samples, and never scheduled. A time or count budget stops it with `complete: false` and a cursor (the last Git path, compared in byte order, which is Git's recursive tree order). `refreshUnindexedFiles` continues an incomplete stored result, schedules the found paths (`requestGitHoldRetry`, a scheduling write only) and stores one `op_checkpoints` row per source (op `unindexed-files`, fingerprint the source id; the 7-day checkpoint purge applies). `judgeUnindexedFiles` is doctor's read: unscheduled finds, scheduled paths still in the retry row (waiting for a sync), and consumed paths that still have no page and no hold, without scanning. Test: `test/unindexed-files.test.ts`.
+ - `src/commands/doctor/checks/unindexed-files.ts` — #6865 doctor `unindexed_files` (BRAIN, after `missing_recorded_files`): reads `judgeUnindexedFiles` for each bound managed Git source; `ok` when every result is complete, recent and nothing is missing; `warn` with counts by code, samples and age when files are unindexed (fix `gbrain sources retry-held <id> --unindexed`, `then` the follow-up sync from `gitFollowUpSync`, verify `gbrain doctor --only unindexed_files --json`) or scheduled and waiting (fix the sync); info `unknown` when a result is missing, older than 7 days or incomplete with nothing found, naming the maintenance phase and the command; info `not_applicable` on a classic brain. `metafile_skipped` files are named in the message and details and never make it warn; alone they are info `degraded` with a `user` fix (rename the file, then the sync). Test: `test/unindexed-files.test.ts`.
- `src/commands/doctor/checks/missing-recorded-files.ts` — #6609 doctor `missing_recorded_files` (BRAIN, after `ghost_pages`): the classic-brain counterpart of `ghost_pages`. Read-only; per source with a checkout on this host and managed persistence off it runs `scanMissingRecordedFiles` (`src/core/persistence/detached-pages.ts`) and warns with counts, samples and an `ask_user` fix (put the file back and sync, or `gbrain delete` then `gbrain restore <slug> --source-id <id> --detach`) for live pages whose recorded file a `gbrain sync --full` would not find; `ok` + `not_applicable` when no source qualifies. Test: `test/restore-detach-6609.test.ts`.
+- `src/core/persistence/overwritten-edits.ts` — #6712 follow-up: `scanOverwrittenEdits` finds live pages whose database-only revision a managed-sync import replaced with different content and no hold, from durable rows only (it survives receipt compaction): `page_versions.write_request_id` / `archived_write_request_id`, the writer's committed receipt (`outcome.persistence.mode = 'database'`, not an import, no `git` effect for that revision, not a read-only mirror write), the archiving request recognised as a managed-sync import by intent kind or, once compacted, by operation `submit_job` + `outcome.imported_file` without `connector_database`, and `reconcileCanonical` digests (the import's own revision differs; no later revision holds the edit again). `high` or `unknown` (`no_persistence_outcome`, `import_content_unreadable`, `segmented`); the newest open overwrite per page; at most `OVERWRITE_SCAN_LIMIT` candidate versions per source. Revisions with no recorded writer are not reported.
+- `src/commands/doctor/checks/overwritten-edits.ts` — doctor `sync_overwritten_db_edits` (BRAIN, after `missing_recorded_files`): per source count and first slugs from `scanOverwrittenEdits`; `warn` only for `high` findings, with the read-only `gbrain repair overwritten-edits --source <id>` preview as an `ask_user` fix; `unknown` findings are counted in `details` and never warn.
+- `src/core/repair/overwritten-edits.ts` — `gbrain repair overwritten-edits`, explicit-only and preview-bound (`--slug` narrows): the preview lists each `high` page with a diff of the live page against the archived edit and saves the set; `--apply --expect <hash>` rechecks the page revision and version digest, then submits `revert_version` with `expected_revision` and `databaseOnly: 'overwrite_restore'` (`page-mutations.ts`: no worktree, receipt `write_through.skipped: overwrite_restore`), so the committed file is never rewritten; when this host owns the checkout and the committed HEAD blob differs from the restored page (`fileMatchesSnapshot`), it writes a `file_drift` hold (`fileDriftHold` + `writeGitHold`, `page_revision` = the restored revision). Outcomes `restored`, `restored_file_held`, `changed_since_preview`. Test: `test/overwritten-edits-6712.test.ts` (PGLite and Postgres).
- `src/core/persistence/detached-pages.ts` — #6609 (D5) restore of a page whose recorded canonical file is gone on a brain without managed persistence. `assertRestoreOrigin` (called by `submitPageMutation` for `restore_page`, `publishesFile` = write-through on and a file target) refuses a restore that writes no file of a soft-deleted page whose `source_path` file `inSyncableTree` does not find (exists and is tracked or untracked-not-ignored, the set sync imports) with `source_changed` / detail `canonical_file_absent`, `retryable: false`, docs `storage-tiering.md#restoring-a-page-whose-file-is-gone` and an `ask_user` fix (`gbrain restore <slug> --source-id <id> --detach`, MCP `restore_page` `detach: true`); `detach: true` with nothing to detach refuses `invalid_params`. `detachRestoredPage` runs in the restore publication (from `classifyUnboundPage`) and clears `source_path`, stamping `pages.database_only_reason='detached'`; the page upsert in `engine-sql/pages.ts` clears that stamp when a sync writes a `source_path` again. `scanMissingRecordedFiles` (at most `MISSING_FILES_SCAN_LIMIT` live pages per source, `collectSyncableFiles` + `scannerSlugRootMode` path resolution) feeds doctor `missing_recorded_files`. Test: `test/restore-detach-6609.test.ts`.
- `src/core/repair/keep-db-policy.ts` — the opt-in `storage.keep_db` policy (#6696 C7). `readKeepDbPolicy` reads a source's `keep_db` prefixes from the gbrain.yml of its canonical checkout, only when the given host owns the active binding. `runKeepDbPolicy` takes the slugs under the prefixes with a drift conflict receipt in the newest 100,000 request sequences plus the recorded concept drift skips, checks each live, prepares the `--prefer database` resolution (`prepareDriftPage`) and submits it through `runReconcileApply` under this installation's own CLI writer registration (never an inherited caller context), with a request id derived from the page revision and file bytes, so one drift is never submitted twice. A run submits at most `KEEP_DB_BATCH` (10) requests (`stopped: 'rate_limit'`) and asks its `admission` gate before each one (default: the repair core's 90% stop line on lifetime ids and receipt bytes, `stopped: 'capacity'`; the seam for background-producer backpressure). The persistence consumer (`consumer.ts`) runs it while idle at most every 10 minutes when started with `keepDbPolicy` (`service.ts`: serve, jobs and autopilot owners only; never with `requestsOnly`), and `stop()` awaits the pass. Tests: `test/file-drift-bulk-reconcile.test.ts` (PGLite; Postgres via `test/e2e/file-drift-bulk-reconcile-postgres.test.ts`).
diff --cc src/commands/doctor/registry.ts
index 3ccc21acbe,a7ddb12fe9..b4940094a2
--- a/src/commands/doctor/registry.ts
+++ b/src/commands/doctor/registry.ts
@@@ -118,9 -118,9 +118,10 @@@ import { fenceIntegrityEntry } from './
import { syncConfigKeysEntry } from './checks/sync-config-keys.ts';
import { ghostPagesEntry } from './checks/ghost-pages.ts';
import { renameIdentityDowngradesEntry } from './checks/rename-identity-downgrades.ts';
+ import { unindexedFilesEntry } from './checks/unindexed-files.ts';
import { purgeParkedPagesEntry } from './checks/purge-parks.ts';
import { missingRecordedFilesEntry } from './checks/missing-recorded-files.ts';
+import { overwrittenEditsEntry } from './checks/overwritten-edits.ts';
import { managedSyncMovementEntry } from './checks/managed-sync-movement.ts';
import { managedSyncBlockedEntry } from './checks/managed-sync-blocked.ts';
import { atomHeldFailedEntry } from './checks/atom-holds.ts';
@@@ -242,7 -246,7 +247,8 @@@ export const DOCTOR_CHECK_REGISTRY: rea
renameIdentityDowngradesEntry,
purgeParkedPagesEntry,
missingRecordedFilesEntry,
+ unindexedFilesEntry,
+ overwrittenEditsEntry,
syncConfigKeysEntry,
fenceIntegrityEntry,
searchModeEntry,
diff --cc src/core/behavior-change-notice.ts
index 18dd30846a,caeb961f14..36e56e8148
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@@ -752,7 -752,18 +752,20 @@@ export const BEHAVIOR_CHANGES: Readonly
{ since: '0.60.276.0', text: 'On a writer-claimed brain, background writes are refused before any receipt, so they spend no write-request id, when their source cannot publish: the worktree is in recovery, or the claim\'s owner verification fails on the owner host (a missing canonical or coordination path, or a physical root whose owner marker .gbrain-owner.json or reservation is gone or changed; a device-only change is still re-stamped by the write). The refusal is owner_unavailable with the fix `gbrain sources writer status --source <id> --json`, checked once per source per run. Background writes are every write not made from an interactive surface: the autopilot cycle and its maintenance phases (extraction, synthesis, patterns, consolidation, fence and content repair, lint fixes), Minion jobs (sync, extract and the other job handlers), connector syncs, delegated serve syncs started as background, the keep-DB reconcile, autopilot and job managed syncs, and the transcript stale-part delete. Interactive CLI, MCP and repair writes are unaffected; a paused (draining) owner still accepts and replays.' },
{ since: '0.60.276.0', text: 'The managed purge (autopilot purge phase, the purge job and `gbrain pages purge-deleted`) submits nothing for a source whose writer needs recovery (reported `writer_not_active` with its state and reason) and parks a page after five failed purges (doctor `purge_parked_pages`: actor agent on the CLI, host_admin remotely). The cycle purge phase reports warn, not fail, for either. `gbrain pages purge-deleted --retry-parked` retries parked pages once; it obeys `--older-than` (a parked page younger than the cutoff is not retried) and the rename-recovery hold, and its preview, its consent text (which names the parked count) and its run come from one selector.' },
{ since: '0.60.276.0', text: '`gbrain repair content` / `repair slug-conflicts` now clears a frontmatter_slug_conflict hold deterministically (remove_slug) when the only other change autoFixFrontmatter would make is a style-only NESTED_QUOTES re-quote of a valid JSON-style tag or alias array. Only the slug: line is removed; the array is left as written and listed as style_only in the preview, the run result and the content_repair receipt. Such holds used to stay still_invalid and needed `repair frontmatter --include-ambiguous`. When the lane still cannot clear a hold because the frontmatter needs other fixes, the still_invalid message now names those fix codes (for example NULL_BYTES).' },
- { since: '0.60.276.0', text: 'New doctor check `sync_overwritten_db_edits` warns when an incremental managed sync published a committed file edit over a page that was also edited in the database since its last import, with no `file_drift` hold (the bug #6887 fixes): the database edit survives only in the page\'s history. It counts the pages per source from page history and write receipts (also after receipt compaction) and warns only when the records prove it; findings it cannot prove are counted as unknown. New explicit-only repair `gbrain repair overwritten-edits --source <id>` previews each page with a diff, and `--apply --expect <hash>` restores the edit as a new revision through a database-only `revert_version` bound to the previewed revision (a page that moved is `changed_since_preview`); it never rewrites the committed file, and holds that file `file_drift` when it differs from the restored page.' },
+ // #6865 (GBRA-122): `since` is a placeholder equal to the branch's VERSION, restamped when the merge slot is called.
+ { since: '0.60.277.0', text: 'A managed `gbrain sync` now removes a stray frontmatter `slug:` line by itself when the slug it names has no page and no file (#6865, the content-repair lane\'s deterministic `absent_page` rule): right after the sync releases its drain lease, each such held file is rewritten without that one line, imported under the slug its path gives, its `frontmatter_slug_conflict` hold cleared and the edit committed as `gbrain: repair frontmatter slug in <path>` with the `gbrain-repair:` trailer, through the same coordinated repair write the maintenance run already used; the declared slug becomes an alias of the page so links written against it keep resolving. At most 200 files and 60 s per sync; the result\'s `slug_lines_removed` counts them and the rest. A line naming an existing page (with a file or database-only, checked again inside the write), a hold the lane already judged, a file edited since sync held it, a source with an unfinished sync, and a sync submitted by a remote job or agent are left held. Preview what the lane would do with `gbrain repair content --source <id> --no-llm`; opt out with `gbrain config set sync.slug_conflicts.auto_remove false` (or pause the whole lane with `fences.repair.enabled false`); undo one edit with `git revert` of its commit and a sync, which holds the file again (the alias stays, so the restored line then names the file\'s own page and needs a hand edit). Nothing runs at upgrade. Slug-conflict hold status now follows what the lane found: "decide which page keeps the slug" appears only when the line names a live page, a hold with no verdict yet never escalates to a person, and a verdict an older gbrain recorded is rechecked once by the next sync or maintenance run instead of being listed for a person.' },
+ // #6803 wave (projection queue, held embedding budgets, bounded doctor/status reads, extraction nudge). `since` is the branch VERSION until the merge-slot stamp.
+ { since: '0.60.278.0', text: '`gbrain sync --status` now prints the `gbrain sync status` envelope (with a one-line hint) instead of running a full sync of the source, which nothing used to stop because no sync path read the flag. `gbrain sync --preview` and `--check`, which sync never read either, now refuse with `invalid_params` and a `--dry-run` fix; `--dry-run` is unchanged.' },
+ { since: '0.60.278.0', text: 'A plain non-interactive CLI `gbrain doctor --json` (stderr not a terminal, no `--budget-ms`, `--tier`, `--fix` or remediation flag) now caps its check run at `doctor.default_budget_ms` (90000 ms; file plane; connect and migrations are not counted) and prints one stderr line saying so; checks past it report health unknown, and the JSON gains `tier`, `complete`, `unknown_sections`, `elapsed_ms` and `budget_ms`. `--budget-ms 0` turns it off for one run and `gbrain config set doctor.default_budget_ms 0` for good. `gbrain config set` now accepts `doctor.entry_budget_ms` and `doctor.orphan_ratio.full_scan_max_pages`.' },
+ { since: '0.60.278.0', text: 'Doctor entries now stop their database statements at their own budget on every tier (Postgres cancels the statement; PGLite refuses the next one), so a slow check no longer keeps a backend running after the report. The cheap incident checks (`persistence_capacity`, `managed_sync_not_moving`, `managed_sync_blocked`, `text_projection_readiness`, `partial_embedding` and `links_extraction_lag`, now its own entry) run right after the ops sections, the frontmatter and fence scans report partial results at the deadline, `--only <check> --budget-ms N` gives that check the whole N, and a check past its budget names which budget (`details.limit`) and prints that rerun.' },
+ { since: '0.60.278.0', text: '`gbrain sync status` and write and sync receipts wait at most 1.5 s for the shared capacity snapshot and read capacity as unknown for that call when it is late, without clearing or re-announcing a background pause; a snapshot fetch that timed out is no longer cached for a minute. Doctor now computes the capacity forecast once per run instead of twice.' },
+ { since: '0.60.278.0', text: '`gbrain projections drain` now seals image pages the importer already attested safe (one image chunk written at or after the safe-chunk fence, unchanged since) in place, keyless, with no chunk write or provider call, so image search ranks them again; every other image page stays queued and out of search until its importer re-imports it (`gbrain embed --stale --images --dry-run`, then the paid run). Its `--json` gains `limited`, `sealed`, `sealed_with_visual`, `sealed_text_only`, `statistics_refreshed` and `remaining_by_class`, and under a resident PGLite owner it prints an exclusive stop, drain and start step instead of only refusing. The resident drains text only and probes at most 500 queued rows per tick.' },
+ { since: '0.60.278.0', text: 'Doctor `text_projection_readiness` counts the queue by class (`pending`, `sealable`, `reimport`, `protected`, `archived`, `failed`, `as_of`): it warns on pending, sealable, reimport and failed rows, with `gbrain projections drain --limit <n>` (asks first) or the paid importer as the fix, and reports protected-OCR and archived-source images as by design (search reports the `projection_by_design` stage for them instead of `projection_pending`). On a PGLite resident it can move from ok to warn; on Postgres it can move from warn to ok. Embed paths no longer queue `embedding_recovery` rows for image pages, `gbrain embed --stale --images` skips sealable pages and reports `ocr_required`, and a read-only notice after upgrading names `gbrain projections drain --dry-run` when image rows are queued.' },
+ { since: '0.60.278.0', text: '`gbrain embed --stale` and the embed-backfill job report `budget_limited` (pages held for approval or at their per-page cap, by source) and print one line instead of saying nothing; it is never a failure. Doctor `partial_embedding` is its own entry (`--only oversized_pages` no longer emits it) and its fix is a per-source approve, `gbrain embed --held --source <id> --max-usd <N>` with a concrete N, with every other source in `details.by_source`. `gbrain embed --held --dry-run` lists every source and exits 0 on a multi-source brain; `--held --max-usd` without `--source` there refuses with `invalid_params`. Receipts name `gbrain embed --held --dry-run --source <id>` instead of `gbrain reindex --held`, which does not exist.' },
+ { since: '0.60.278.0', text: 'An explicit `--max-usd N` on `gbrain embed --slugs` or `--held` now releases a held page on a free embedding provider too (#6847); it used to reprint the hold. Free-recipe models cost $0 in the per-page ledger, printed approve commands carry a concrete N (a paid N includes the 1.5x headroom and $0.25 floor), a free provider\'s approve asks for no paid or egress consent, and an approval when embeddings cannot run or the paid model has no price is refused before the hold is released. `--yes` still never releases a hold.' },
+ { since: '0.60.278.0', text: '`gbrain extract --stale --source <id>` now refuses with `invalid_params` naming `--source-id <id>` instead of running brain-wide; `--source fs` exits 2 `invalid_params` (it exited 1), and `--source db` refuses as ambiguous when a source is named `db`. Rendered extract fixes pin `--source-id`. The end-of-sync extraction nudge stays silent when doctor `links_extraction_lag` would not warn (attendance-blocked meetings no longer count), names both `gbrain extract --stale` and `gbrain extract --stale --catch-up` with estimates, and becomes a run-it-yourself step above two minutes; `extract --stale` JSON gains `actionable`, `attendance_blocked`, `mention_due` and `complete`; the per-source "still owe extraction" line counts only pages that sync imported; and an owner-delegated plain `extract --stale` keeps the 30-minute budget (`--catch-up` is carried through).' },
++ // #6712 follow-up (#6891): `since` is a placeholder equal to the branch's VERSION, restamped when the merge slot is called.
++ { since: '0.60.278.0', text: 'New doctor check `sync_overwritten_db_edits` warns when an incremental managed sync published a committed file edit over a page that was also edited in the database since its last import, with no `file_drift` hold (the bug #6887 fixes): the database edit survives only in the page\'s history. It counts the pages per source from page history and write receipts (also after receipt compaction) and warns only when the records prove it; findings it cannot prove are counted as unknown. New explicit-only repair `gbrain repair overwritten-edits --source <id>` previews each page with a diff, and `--apply --expect <hash>` restores the edit as a new revision through a database-only `revert_version` bound to the previewed revision (a page that moved is `changed_since_preview`); it never rewrites the committed file, and holds that file `file_drift` when it differs from the restored page.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --cc src/core/doctor-categories.ts
index 3a04fedd45,400338d8bf..54adaec038
--- a/src/core/doctor-categories.ts
+++ b/src/core/doctor-categories.ts
@@@ -202,8 -202,8 +202,10 @@@ export const BRAIN_CHECK_NAMES: Readonl
'rename_identity_downgrades',
// #6609: live pages of a classic checkout whose recorded file a full sync would not find (doctor/checks/missing-recorded-files.ts).
'missing_recorded_files',
+ // #6865: committed files of a managed Git source with no page and no hold, from the stored detector result (doctor/checks/unindexed-files.ts).
+ 'unindexed_files',
+ // #6712: live pages whose database-only edit an incremental sync overwrote without a hold (doctor/checks/overwritten-edits.ts).
+ 'sync_overwritten_db_edits',
'unified_multimodal_coverage',
'unverified_extractions',
'voice_gate_health',
diff --cc test/fixtures/goldens/doctor/json-pglite-degraded.json
index d4d68e74c7,dd99f0cbe0..d1a493bc11
--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json
+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json
@@@ -2681,20 -2692,82 +2692,96 @@@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "details": {
+ "docs": "docs/guides/repair.md#unindexed-files",
+ "sources": [
+ {
+ "source_id": "default",
+ "state": "missing"
+ }
+ ]
+ },
+ "elapsed_ms": "<volatile>",
+ "fix": {
+ "actor": "agent",
+ "argv": [
+ "gbrain",
+ "sources",
+ "retry-held",
+ "default",
+ "--unindexed",
+ "--brain",
+ "host"
+ ],
+ "command": "gbrain sources retry-held default --unindexed --brain host",
+ "consent": [],
+ "docs": "https://github.com/garrytan/gbrain/blob/master/docs/guides/repair.md#unindexed-files",
+ "next": "run",
+ "requires_exclusive": false,
+ "then": {
+ "actor": "agent",
+ "argv": [
+ "gbrain",
+ "sync",
+ "--source",
+ "default",
+ "--no-pull",
+ "--brain",
+ "host"
+ ],
+ "command": "gbrain sync --source default --no-pull --brain host",
+ "consent": [],
+ "docs": "https://github.com/garrytan/gbrain/blob/master/docs/guides/repair.md#unindexed-files",
+ "next": "run",
+ "requires_exclusive": false,
+ "verify": {
+ "argv": [
+ "gbrain",
+ "doctor",
+ "--only",
+ "unindexed_files",
+ "--json",
+ "--brain",
+ "host"
+ ]
+ },
+ "why": "The sync re-screens the scheduled files of default: each one that passes imports, each one that refuses is recorded as a hold that gbrain sources status default lists."
+ },
+ "verify": {
+ "argv": [
+ "gbrain",
+ "doctor",
+ "--only",
+ "unindexed_files",
+ "--json",
+ "--brain",
+ "host"
+ ]
+ },
+ "why": "Finds the committed files of default with no page and no hold (bounded; it continues an incomplete scan), schedules them for a re-screen and stores the result this check reads."
+ },
+ "message": "Unindexed files are not known for default (not computed yet). The maintenance phase unindexed_files computes them on each run and continues an incomplete scan; to compute them now, run gbrain sources retry-held <id> --unindexed.",
+ "name": "unindexed_files",
+ "readiness_state": "unknown",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "details": {
+ "count": 0,
+ "docs": "docs/guides/repair.md#overwritten-edits",
+ "sources": [],
+ "truncated": false,
+ "unknown": 0
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No page shows a database edit that a sync import overwrote.",
+ "name": "sync_overwritten_db_edits",
+ "status": "ok"
+ },
{
"category": "meta",
"details": {
@@@ -2813,7 -2886,7 +2900,7 @@@
{
"category": "brain",
"elapsed_ms": "<volatile>",
-- "message": "No retrieval-affecting files changed in working tree.",
++ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/projection-readiness.ts, src/core/search/safe-chunks.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
diff --cc test/fixtures/goldens/doctor/json-pglite-fresh.json
index f59197e387,9bdacda882..af6f3c3153
--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json
@@@ -2726,20 -2737,82 +2737,96 @@@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "details": {
+ "docs": "docs/guides/repair.md#unindexed-files",
+ "sources": [
+ {
+ "source_id": "default",
+ "state": "missing"
+ }
+ ]
+ },
+ "elapsed_ms": "<volatile>",
+ "fix": {
+ "actor": "agent",
+ "argv": [
+ "gbrain",
+ "sources",
+ "retry-held",
+ "default",
+ "--unindexed",
+ "--brain",
+ "host"
+ ],
+ "command": "gbrain sources retry-held default --unindexed --brain host",
+ "consent": [],
+ "docs": "https://github.com/garrytan/gbrain/blob/master/docs/guides/repair.md#unindexed-files",
+ "next": "run",
+ "requires_exclusive": false,
+ "then": {
+ "actor": "agent",
+ "argv": [
+ "gbrain",
+ "sync",
+ "--source",
+ "default",
+ "--no-pull",
+ "--brain",
+ "host"
+ ],
+ "command": "gbrain sync --source default --no-pull --brain host",
+ "consent": [],
+ "docs": "https://github.com/garrytan/gbrain/blob/master/docs/guides/repair.md#unindexed-files",
+ "next": "run",
+ "requires_exclusive": false,
+ "verify": {
+ "argv": [
+ "gbrain",
+ "doctor",
+ "--only",
+ "unindexed_files",
+ "--json",
+ "--brain",
+ "host"
+ ]
+ },
+ "why": "The sync re-screens the scheduled files of default: each one that passes imports, each one that refuses is recorded as a hold that gbrain sources status default lists."
+ },
+ "verify": {
+ "argv": [
+ "gbrain",
+ "doctor",
+ "--only",
+ "unindexed_files",
+ "--json",
+ "--brain",
+ "host"
+ ]
+ },
+ "why": "Finds the committed files of default with no page and no hold (bounded; it continues an incomplete scan), schedules them for a re-screen and stores the result this check reads."
+ },
+ "message": "Unindexed files are not known for default (not computed yet). The maintenance phase unindexed_files computes them on each run and continues an incomplete scan; to compute them now, run gbrain sources retry-held <id> --unindexed.",
+ "name": "unindexed_files",
+ "readiness_state": "unknown",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "details": {
+ "count": 0,
+ "docs": "docs/guides/repair.md#overwritten-edits",
+ "sources": [],
+ "truncated": false,
+ "unknown": 0
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No page shows a database edit that a sync import overwrote.",
+ "name": "sync_overwritten_db_edits",
+ "status": "ok"
+ },
{
"category": "meta",
"details": {
@@@ -2858,7 -2931,7 +2945,7 @@@
{
"category": "brain",
"elapsed_ms": "<volatile>",
-- "message": "No retrieval-affecting files changed in working tree.",
++ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/projection-readiness.ts, src/core/search/safe-chunks.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
diff --cc test/fixtures/goldens/doctor/registry-build-checks.json
index 667ff02e3f,02c3cbe703..a74bf22b3f
--- a/test/fixtures/goldens/doctor/registry-build-checks.json
+++ b/test/fixtures/goldens/doctor/registry-build-checks.json
@@@ -857,10 -857,10 +857,14 @@@
"category": "brain",
"name": "missing_recorded_files"
},
+ {
+ "category": "brain",
+ "name": "unindexed_files"
+ },
+ {
+ "category": "brain",
+ "name": "sync_overwritten_db_edits"
+ },
{
"category": "meta",
"name": "sync_config_keys"