Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

docs(sync): #6712 PR 4b the pass in the operator docs: convergence class glossary, status reasons, sync.admission, mass-delete valve, episodes, held file-drift Decisions, keep_db in the pass, KEY_FILES for sync-pass-run/row/readers

garrytan3c0d28393449
diff --git a/AGENTS.md b/AGENTS.md
index 7fcb85970d..7aa11956b6 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -198,9 +198,10 @@ writing or reviewing an operation, consult `src/core/operations.ts` for the cont
- **Keep a managed catch-up moving without a human** (a live checkout where
other agents commit while `gbrain sync` drains thousands of pages): a page
that moves under the run is held (`concurrent_write`, `worktree_dirty`), a
- dropped connection is retried, and a relaunch resumes the frozen manifest.
- The operator loop is `gbrain sync status --source <id> --json` (`state`
- and `reason`, cursor, `committed_last_10m`, each hold and the last error
+ dropped connection is retried, and a relaunch starts a pass that admits only
+ what is still unsettled. The operator loop is
+ `gbrain sync status --source <id> --json` (`state` and `reason`, the
+ newest pass in `convergence`, `committed_last_10m`, each hold and the last error
with `class` / `safe_actions` / `needs_human`), then, when nothing moved and
`needs_human` is false, `gbrain sync unblock --source <id> --apply` and
the sync it prints; when `needs_human` is true, relay `next.user_message`
diff --git a/docs/architecture/key-files/canonical-reconciliation.md b/docs/architecture/key-files/canonical-reconciliation.md
index c1271d8bd6..88ad9c457f 100644
--- a/docs/architecture/key-files/canonical-reconciliation.md
+++ b/docs/architecture/key-files/canonical-reconciliation.md
@@ -21,6 +21,9 @@
- `src/core/persistence/sync-classify.ts` — the managed-sync level classifier (#6712 PR 4, design v3.2 §2.3): pure (no I/O), total, ordered, first match over one path's facts (`SyncPathState`: mode, `T[p]`, the level `L`, presence, `Dp`, the page and its import record, the attestation of its revision, hold, deletion marker, baseline blob, open work). Rows in order: `held`, `spelling`, `untracked`, `kept`, `delete`, `delete_drift`, `gone`, `deleted_same`, `deleted_edited`, `legacy_same`, `dirty`, `matched`, `adopt`, `reparse`, `db_ahead` (sub-labels `pending`/`db_only`/`unproven`; keep_db writes only `db_only` on a clean committed path; an open full obligation skips `db_only`/`unproven`), `import`, `legacy_unverified`, `keep_db`, `drift` (side `both` or `unknown`); then the overlay (unsettled with open work is `in_flight`). `syncClassAction` is the glossary tag (`none`, `owner`, `repair`); `syncPassKind` decides `idle`, `hold_only` or `full` from the converged state and every obligation. Tests: `test/sync-classify-6712.test.ts` (each row, and the cross product against a reference model built from the state space).
- `src/core/persistence/sync-pass.ts` — the read-only shadow of the level-triggered pass (#6712 PR 4a): `readShadowLevel` reads one managed source's level (`T` via `readTreeLevel`, `X`, working-mode untracked files, `Dp` for committed candidates only or every path in working mode, pages keyset on `pages.id` with the import record by a LATERAL primary-key probe and the revision's attestation in the same statement, holds and retry rows, open requests and pending Git effects, deletion markers) and classifies every path with `sync-classify.ts`; it writes and admits nothing. Postgres reads share one `REPEATABLE READ, READ ONLY` transaction; PGLite runs bounded 2,000-row statements. A company-brain source returns null (it keeps its frozen manifest). `shadowConvergence` wraps it in the receipt, `dryRunConvergence` backs `gbrain sync --dry-run --json`'s `convergence` (with the read-only screen), `statusConvergence` backs `sync status --detail` and doctor, and `idleTickProbe` times the idle tick's reads for the bench (`scripts/bench/sync-convergence.ts`). Tests: `test/sync-pass-shadow-6712.test.ts`.
- `src/core/persistence/sync-convergence.ts` — the convergence receipt (#6712 PR 4a, schema `convergence/1`, always `dry_run: true`): per-class `counts` and `classes` with action tags (`in_flight`, `keep_db_pending` beyond 200 per pass, and `deletes_withheld` when #2828's valve trips are classes too), predicted `decisions` by side after `readOnlySameContentScreen` (the dry run's `sameContentAtOrigin`: a screening request through `prepareManagedSyncMutation(..., { unsaved: true })`, at most 200 paths; equal content is `same_content_noops`, unscreened is `screen_unknown`), `would_hold`, `db_ahead` by prefix, `legacy_unverified`, `legacy_pageless`, `deletes` with the valve verdict and set hash, up to 20 samples per non-matched class, timings and statement count. `--redact-paths` replaces paths with sha256 prefixes and drops slugs.
+- `src/core/persistence/sync-pass-run.ts` — the live level-triggered pass of a managed, non-company source (#6712 PR 4b, design v3.2 §2.2, §3.1–§3.5, §8, §9), run under the source's drain lease. `runSyncPass` retires an unfinished legacy cursor first (its options seed the episode), pins the pass row (`sync.admission`, `HEAD`, the mode; the row is written with the lease token), decides the kind (`idle` stamps only `last_sync_at` as `up_to_date`; `hold_only`; `full`), then runs at most `PASS_MAX_ROUNDS` (4) rounds: read and classify the level (`sync-pass.ts`), admit `C_k = unsettled − S` in batches of at most `PASS_BATCH_MAX` (10,000; deletes, then imports) through sync-run.ts's cursor machinery on an in-memory batch, and add each settled `(path, level)` to `S` (never admitted twice in one pass). With nothing unsettled and nothing in flight it stamps through `applyPassCheckpoint`; four rounds without converging stop `resumable` / `not_converged`. Every stop records its outcome, stop reason, `settled` and `remaining` on the pass row (a stop mid-batch counts the entries its batch passed); a blocked page refusal is replayed with no new request while nothing that decided it changed. Tests: `test/sync-pass-live-6712.test.ts`, `test/sync-pass-completion-6712.test.ts`, `test/sync-pass-outcomes-6712.test.ts`.
+- `src/core/persistence/sync-pass-row.ts` — the pass row and the rows beside it (#6712 PR 4b, design §3.4), free of heavy imports so doctor, status, the lease, compaction and GC read it without loading the pass. `managed-sync-pass` (fingerprint `<source>:<incarnation>`) holds `obligations` (baseline, episode, cost, the converged state, mismatch and not-converged streaks, page faults, a blocked request to replay) and `telemetry` (the newest pass's kind, round, outcome, stop reason, candidates, settled, remaining, counts, timings). `writePassRow` writes it at pin under `assertDrainLease` and afterwards only `WHERE lease_token = $token`. Beside it: `sync-origin-deleted` (deletion markers), `sync-deletes-withheld` (the mass-delete trip) and `sync-pass-cost` (one reservation per group); `SYNC_PASS_ROW_OPS` lists the ops the checkpoint GC keeps for a live incarnation. `passHealth` is the one health rule (`blocked`, `not_converged`, `settle_mismatch`, `open_stalled`, `nothing_pending`); `SETTLE_MISMATCH_STREAK` and `NOT_CONVERGED_REPORT_STREAK` are 3.
+- `src/core/persistence/sync-pass-readers.ts` — the pass row as the former cursor readers see it (#6712 PR 4b, design §3.7): doctor's movement, git-holds and terminal-failure checks, the drain backlog (`readManagedSyncBacklog`), the blocked-run reader and `sources status` read a non-company source's pass row through `readPassReadings` (`passHealth` plus the checkout HEAD from a hardened `rev-parse` on this host; no checkout means `head: null` and the recorded converged target is trusted). `passResumeArgs` is the plain sync that continues the pass, with the open episode's inherited options; `passStopCode` and `passStuckSince` name a stuck pass. Company sources and unretired legacy cursors keep their cursor arm in each reader. Tests: `test/sync-pass-readers-6712.test.ts`, `test/sync-pass-reader-gaps-6712.test.ts`.
- `src/core/persistence/sync-pass-apply.ts` — what a live pass round does besides admitting one-sided imports and deletes (#6712 PR 4b, design v3.2 §2.5–§2.7, §3.1, §5): holds with side and state for the two-sided and deleted rows (`file_drift` with `side`, `tombstone_edited`, `purged_differs`, `file_gone`), the `settle_mismatch` hold after three passes at one level, arm-1 adoption of a record without a revision on `fileSame`, the bounded legacy sweep (500 per round) that records equal legacy pages on the first full round, the mass-delete valve (one `sync-deletes-withheld` record; imports and the stamp proceed), `keep_db` admission (200 per pass), deletion-marker retirement in full rounds, and the remote ending (`reconcile_host_required`: one-sided work commits, drift stays unsettled with no hold). Entry points: `applyPassRound`, `finishPassApply`, `summarizeRound`. Tests: `test/sync-pass-completion-6712.test.ts`.
- `src/core/persistence/sync-pass-episode.ts` — pass episodes and cost (#6712 PR 4b, design §6, §7): `episodeClosure` closes an episode by inclusion or at the configured selection (a narrower episode never stamps `chunker_version`; a widened one releases its extra paths), `passCostDecision` defers paid embedding when the envelope is unknown or spent, and `reservePassCost` writes one `sync-pass-cost` row per admitted group (fingerprint `<source>:<incarnation>:<episode_or_pass_id>:<group_id>`, insert-once) inside the group's admission transaction, so a kill keeps the reservation and a replay adds nothing. Tests: `test/sync-pass-completion-6712.test.ts`.
- `src/core/persistence/sync-pass-status.ts` — the live `convergence` block of `gbrain sync status` (#6712 PR 4b, design §9, `dry_run: false`): built from the pass row (one primary-key read), the withheld-delete record and `syncAdmissionStatus`, plus `passStatusState`, which keeps a source off `synced` while its newest pass is open or ended unconverged (reasons `pass_unfinished`, `not_converged`, `settle_mismatch`, `deletes_withheld`, `selection_scoped`, `admission_paused`). Tests: `test/sync-pass-completion-6712.test.ts`.
diff --git a/docs/guides/live-sync.md b/docs/guides/live-sync.md
index 81e1cf76ad..f30e8f3571 100644
--- a/docs/guides/live-sync.md
+++ b/docs/guides/live-sync.md
@@ -23,6 +23,20 @@ command drains the whole backlog:
gbrain sync --source <id> --no-pull --json
```
+A managed source that is not a company brain syncs by a **level-triggered
+pass**: under the source's drain lease it pins `HEAD`, compares the whole tree
+with what the database absorbed (the pages and their import records) and
+admits only the paths that are not settled, in batches of at most 10,000 and
+at most four rounds. A pass with nothing unsettled and nothing in flight
+stamps `last_commit`. A killed pass loses nothing: the next plain sync reads the
+level again and admits only what is still unsettled, so a reset, a lost run or
+an out-of-band change converges without a flag. Its progress is the
+`convergence` block of `gbrain sync status --json` (`round`, `candidates`,
+`settled`, `remaining`, `classes`); the cursor fields there are null. A
+company-brain source keeps its cursor and frozen manifest. The pass's status
+reasons, `sync.admission`, the mass-delete valve and episodes are in the
+[sync unblock runbook](sync-unblock-runbook.md#the-pass-outcomes-and-status-reasons).
+
Managed sync never pulls: the checkout is fast-forwarded by
`gbrain sources refresh <id>`, never by sync. Sync then catches the index up
to whatever the checkout holds. The CLI implies `--no-pull` on a managed brain
@@ -88,8 +102,11 @@ The run ends in exactly one outcome:
| Outcome | Exit | Meaning | What to do |
| --- | --- | --- | --- |
-| `synced` | 0 | The cursor reached its target. | Nothing. |
-| `resumable` | 0 | A deadline, `--timeout` or Ctrl-C stopped it; the cursor and accepted writes are intact. | Rerun `next.command`; safe in a loop. |
+| `synced` | 0 | The pass converged and stamped (a company-brain source: the cursor reached its target). A pass at a selection other than the configured one adds `selection_scoped` and does not advance `last_commit`. | Nothing. |
+| `resumable` | 0 | A deadline, `--timeout` or Ctrl-C stopped it; accepted writes are intact. | Rerun `next.command`; safe in a loop. |
+| `resumable` / `not_converged` | 0 | The pass used its four rounds while another writer kept changing the level; everything it admitted stands. | Rerun `next.command`. After three in a row `next` is a report (`gbrain doctor --json`), not another sync. |
+| `resumable` / `admission_paused` | 0 | `sync.admission` is `imports_only` or `classify_only`. | Ask the user; `gbrain config set sync.admission normal` ends the pause. |
+| `blocked` / `reconcile_host_required` or `grant_scope` | 1 | A remote caller or a partial grant admitted what it could; the rest (holds, markers, keep_db writes, the stamp) needs the owner host. | Tell the user to run `gbrain sync --source <id> --no-pull` on the brain host. |
| `resumable` / `preparation_abandoned` | 0 | A write this process's own writer holds was still preparing past its allowance (its budget plus 30 s) and cannot be cancelled in-process, so the sync exited to end it; `drain.stall.step` says where. | Rerun `next.command`; safe in a loop. The next pass holds the entry if it stalls again. |
| `blocked` | 1 | A page failed or the writer needs intervention. | Follow `next.why`, then run `next.command`. See [drain stops](write-refusals.md#managed-sync-drain-stops). |
| `blocked` / `drain_stalled` | 1 | The head write made no progress (no commit, no step advance) for the whole window. With a live owner on this host the drain waits until the 600 s ceiling (printing `stalled <N>s on <step>` with the owner's pid and kind meanwhile) and stops with `cause: owner_wedged_here`, the owner `{kind, pid, nonce}` and `retry_after_ms` to the ceiling; a lapsed claim stops at once as `owner_missing`. | Before the ceiling: wait `retry_after_ms`, then rerun `next.command` (`safe_to_loop` is true). Past it, or with a wedged owner: restart the named owner process, `gbrain sources retry-held <id>`, then the same sync. `gbrain sources writer status --source <id> --json` ends the claim in a `next_action` that says which. See [drain stops](write-refusals.md#drain-stalled). |
@@ -396,9 +413,10 @@ would need the moved file as evidence, which is what the sync route provides.
Concurrent runs are safe. Two syncs on the same commit no-op because content
hashes match. If both a cron and `--watch` fire simultaneously, no conflict.
-Long syncs also survive being killed: progress checkpoints into the database
-as files drain, so a killed or aborted run resumes from where it stopped, and
-the sync bookmark only advances on true completion. A progress-aware stall
+Long syncs also survive being killed: every published page keeps its
+receipt and import record, so the next plain sync admits only what is still
+unsettled (a company-brain cursor resumes where it stopped), and the sync
+bookmark only advances when a pass converges. A progress-aware stall
watchdog (`GBRAIN_SYNC_STALL_ABORT_SECONDS`, default 900, `0` disables) aborts
a run that stops making forward progress and releases the per-source lock so
the next `gbrain sync` picks up from the checkpoint. The checkpoint cadence
diff --git a/docs/guides/repair.md b/docs/guides/repair.md
index fb9fed5cd8..dc2faa6900 100644
--- a/docs/guides/repair.md
+++ b/docs/guides/repair.md
@@ -1391,6 +1391,36 @@ such a page refuses and names the same route, and a held deletion's next step
in `gbrain sources status` is the `--prefer database` preview. `--all-drifted`
does not select missing files.
+<a id="file-drift-held"></a>**Held drift, one Decision at a time** (#6712). A managed sync holds a
+two-sided change as `file_drift` with a `side` (`both`: the file and the page
+both changed since the last import; `unknown`: the page has no import record
+to tell; `deleted`: one side is a deletion) and, for a deleted side, a
+`state`: `tombstone_edited` (the page was deleted and the file was edited),
+`purged_differs` (a purged page's file differs from what was purged) or
+`file_gone` (the file was deleted and the page changed). `gbrain sources status
+<id> --json` lists each held file with both. `--held` selects those holds:
+
+```bash
+gbrain repair file-drift --source <id> --held --side both --prefer file # preview
+gbrain repair file-drift --source <id> --held --side deleted --state tombstone_edited --prefer database
+gbrain repair file-drift --source <id> --held --side both --prefer file --apply --expect <hash>
+```
+
+One preview resolves one Decision, so a selection that spans several sides or
+deleted states refuses [`file_drift_mixed_selection`](error-codes.md#file_drift_mixed_selection),
+and a deleted side refuses without `--state`
+([`file_drift_state_required`](error-codes.md#file_drift_state_required)):
+the two `--prefer` values do opposite things in each state.
+
+| State | `--prefer database` | `--prefer file` |
+|---|---|---|
+| `tombstone_edited` | Keeps the deletion and removes the file. | Restores the page and imports the file. |
+| `purged_differs` | Removes the file. | Imports the file as a new page. |
+| `file_gone` | Recreates the file from the page. | Soft-deletes the page (the mass-delete valve applies). |
+
+`both` and `unknown` resolve as `--slug` does above. `--only` / `--skip` narrow
+the held set by file path, and the preview lists each page's action.
+
The audit gives every drifted page one class: `structurally_additive`,
`additive_with_suggestions`, `review_required`, `formatting_only` or `error`.
`--all-drifted` refuses a selection that mixes classes (the message counts
@@ -1419,17 +1449,16 @@ storage:
- concepts/
```
-On the canonical owner host the resident consumer of `gbrain serve`,
-`gbrain jobs work` or `gbrain autopilot` then reconciles each drifted page
-under those prefixes with the database copy winning, the same resolution
-`--prefer database` previews (reconcile's protections and backups apply). It
-submits one request per drifted page, at most 10 every 10 minutes, never
-twice for the same drift (the request id is derived from the page revision
-and file bytes), and stops before an admission that would cross 90% of the
-write-quota stop line. Prefixes match page slugs by whole path segments, like
-`db_tracked` and `db_only`. Nothing else reads the policy: another host, a
-short-lived command, and remote or caller writes keep refusing
-`source_changed` until the page is reconciled. Doctor `maintenance_write_drift`
+The managed sync pass then writes the database copy back to the file for
+each page under those prefixes whose database copy changed since its last
+import (whether or not the file changed too), the same resolution `--prefer database` previews (reconcile's protections and
+backups apply). It does so only in committed mode and for a clean file: the write is
+bound to the bytes the pass froze, and a file with an uncommitted edit is
+held instead. A pass admits at most 200 such writes; the rest wait as
+`keep_db_pending` and go first in the next pass. Prefixes match page slugs by
+whole path segments, like `db_tracked` and `db_only`. A remote caller's sync
+never writes them, and outside a sync a short-lived command or a caller
+write keeps refusing `source_changed` until the page is reconciled. Doctor `maintenance_write_drift`
echoes each declared policy (`keep_db_policy`: prefixes, how many of the
drifted pages it checked match, their receipt cost). Remove the block to turn
the policy off.
@@ -1955,7 +1984,7 @@ the repair is what changes them).
| Busy (waits as `sync_in_progress`) | Why |
| --- | --- |
| A file or page a queued, running or recovering write names, or a finished write whose recovery is still open; both endpoints of a rename | The write is still publishing it. |
-| A file still ahead in the running sync's frozen manifest (from the cursor's index on) | The sync admits it later with the raw hash it reads then; a repair that changed the bytes first would make that entry refuse (`source_changed`). |
+| A file still ahead in a company-brain sync's frozen manifest, or a legacy cursor's that no pass has retired yet (from the cursor's index on) | The sync admits it later with the raw hash it reads then; a repair that changed the bytes first would make that entry refuse (`source_changed`). A live pass adds nothing here: it freezes and admits under the drain lease and re-checks each candidate's revision, so only its open requests (the row above) are busy. |
| Every candidate, when the busy set cannot be read (a failed query, a cursor whose manifest is missing) | The check fails closed; the hold's text says so. |
The busy set is read when the plan is made, again when each item is applied
diff --git a/docs/guides/sync-unblock-runbook.md b/docs/guides/sync-unblock-runbook.md
index 3d5a3e4f79..aaf77e1c6b 100644
--- a/docs/guides/sync-unblock-runbook.md
+++ b/docs/guides/sync-unblock-runbook.md
@@ -3,10 +3,12 @@
A managed catch-up on a live checkout (`gbrain sync --source <id> --no-pull`,
thousands of pages, other agents committing to the brain repo every few
minutes) finishes unattended. A page that moves under the run is held, not
-fatal; a dropped database connection is retried, not fatal; a relaunch resumes
-the frozen manifest at its stored cursor instead of re-freezing it. What is
-left for an operator is one loop over two commands, and this page is the
-decision table behind them.
+fatal; a dropped database connection is retried, not fatal; a relaunch starts
+a new pass that reads the source's level again and admits only what is still
+unsettled, so nothing already settled is written twice (a company-brain source
+keeps its cursor and resumes its frozen manifest). What is left for an
+operator is one loop over two commands, and this page is the decision table
+behind them.
**Say to your agent:** *"Keep my brain's catch-up moving and tell me only when
a page needs my decision."*
@@ -17,7 +19,7 @@ a page needs my decision."*
gbrain doctor --only serve_build_drift --json # first: on a warning, restart serve and workers and stop here
gbrain sync status --source <id> --json # every N minutes (read-only)
gbrain sync unblock --source <id> --apply --json # when committed_last_10m is 0 and needs_human is false
-gbrain sync <next.argv...> # the sync unblock (or status) names: the cursor's own options
+gbrain sync <next.argv...> # the sync unblock (or status) names, with an open episode's inherited options
```
**Say to your agent:** *"Repair the files sync held and get the catch-up
@@ -28,10 +30,15 @@ moving again; ask me only about the ones gbrain will not decide by itself."*
command it prints before anything else, and stop until it reads ok
([serve build drift](troubleshooting.md#serve-build-drift)).
1. Read `status`. `state` (`synced` | `resumable` | `blocked`) and `reason`
- say where the source stands; `cursor` is where the run stands
- (`index/total`, the `pinned_target` commit, `last_advance_at`);
- `committed_last_10m` is the signal that data is moving (a live process with
- a flat cursor is not progress). `holds` and `last_error` each carry the
+ say where the source stands. Where the run stands is `convergence` for a
+ managed source synced by the live pass (its newest pass: `pass_id`,
+ `outcome`, `stop_reason`, `round`, `candidates`, `settled`, `remaining`,
+ `classes`; see [the pass](#the-pass-outcomes-and-status-reasons)); there
+ `run_id`, `cursor`, `rate_pages_per_min` and `eta_seconds` are null because
+ no cursor exists. A company-brain source keeps `cursor` (`index/total`, the
+ `pinned_target` commit, `last_advance_at`). `committed_last_10m` is the
+ signal that data is moving (a live process with a flat pass is not
+ progress). `holds` and `last_error` each carry the
triple below, plus `category` and `public_category`. `oldest_blocker` and
`recovery` are bounded live probes that need no cursor; when one times out
the state is `resumable` / `status_unknown`, never `synced`. A plain status
@@ -54,8 +61,9 @@ moving again; ask me only about the ones gbrain will not decide by itself."*
refuses every repair-class hold instead, as releases before #6377 did.
3. Run that sync. It re-screens the scheduled files, imports each one that now
passes and holds again what still fails; the rest of the source is never
- blocked. A cursor an older release left blocked on a
- page fault converts in place (same run, no rediscovery).
+ blocked. An unfinished cursor an older release left is retired by the next
+ pass: the pass waits for the requests it already admitted, keeps its
+ processing options for the episode, and settles the rest from the level.
4. If `needs_human` is true, stop looping and page a person with the slug and
`human_reason` from `status` (`next.user_message` is written for relay).
@@ -265,6 +273,9 @@ the next plain sync.
## Why the manifest is not re-frozen any more
+This section is about company-brain sources and legacy cursors, the only
+runs that still freeze a manifest; a pass keeps no manifest to lose.
+
The frozen manifest always lived in the cursor (`op_checkpoints`, op
`managed-sync`). What threw it away was the failure ledger: every run death
wrote a row, and the retry read the row and rediscovered from index 0
@@ -313,12 +324,88 @@ days, so a soak can show that sync keeps moving on its own.
Each line has one count per kind and a `total`; `by_day` lists both line
totals for each day that recorded anything. Fields are only ever added.
-## Dry-run convergence classes
-
-`sync --dry-run --json` adds a read-only `convergence` receipt. Class actions:
-- `none`: settled.
-- `owner`: sync finishes it.
-- `repair`: a person decides.
+## The pass: outcomes and status reasons
+
+A managed source that is not a company brain syncs by a level-triggered pass:
+under the source's drain lease it pins `HEAD`, reads the whole level (the
+tree, the index, the pages and their import records) and admits only the
+paths that are not settled, in at most four rounds. A pass with nothing
+unsettled and nothing in flight stamps `last_commit`. Every plain sync
+compares the whole tree with what the database absorbed, so a reset or a lost
+run converges on the next plain sync with no flag.
+
+| Status `reason` | `state` | What it means | `next` |
+|---|---|---|---|
+| `pass_unfinished` | resumable | The newest pass is open or stopped at a deadline. | The plain sync (`resume_argv`); safe to loop. |
+| `not_converged` | resumable | The pass used its four rounds while another writer kept changing the level. Everything it admitted stands. | The plain sync; after three such passes in a row `next` is `gbrain doctor --json` and a report, because another sync will not change it. |
+| `settle_mismatch` | resumable | A path keeps settling without reading settled. The next pass re-admits it once; after three passes at one level it is a `settle_mismatch` hold that needs a person. | The plain sync, then report the hold. |
+| `deletes_withheld` | blocked | The pass's deletes crossed the mass-delete threshold (#2828). It wrote one withheld record and synced everything else; no per-page hold is written. | Ask the user: restore the checkout if it is wrong, or run `GBRAIN_ALLOW_MASS_RECONCILE=1 gbrain sync --source <id>` on the brain host when the deletion is intended. `gbrain sync --source <id> --dry-run --json` lists the set and its hash. |
+| `admission_paused` | resumable | `sync.admission` is `imports_only` or `classify_only`. | Ask the user to run `gbrain config set sync.admission normal` when the pause is over; it is never lifted automatically. |
+| `selection_scoped` | synced | The pass converged at a selection other than the source's configured one (a CLI `--exclude`, say) and did not advance `last_commit`. | None; the next plain sync runs the configured selection. |
+
+The run's own JSON (`outcome`, `drain.stop_reason`) adds three stops a status
+read never shows as its reason: `grant_scope` (a grant that covers only part of
+the source admitted what it can see), `reconcile_host_required` (a remote
+caller admitted its one-sided work; holds, markers, keep_db writes and the
+stamp need the owner host) and `reconcile_read_incomplete` (a Git listing did
+not finish, so the pass wrote nothing). All three end `blocked` with
+`tell_user_to_run` or `report`; see
+[drain stops](write-refusals.md#managed-sync-drain-stops).
+
+**`sync.admission`** (`normal` | `imports_only` | `classify_only`) is the
+owner's brake on what sync writes, brain-wide. `imports_only` admits no
+deletes and no keep_db writes (they wait as paused deletes and
+`paused_keep_db`); `classify_only` reads and classifies and writes only the
+pass row. It is read at the pin and in every group's admission, and a delete
+or keep_db write already admitted re-reads it when it publishes, so nothing
+destructive lands after the change takes effect (`admission.effective` in
+`sync status`). Doctor `sync_admission_restricted` warns while it is not
+`normal`.
+
+**Episodes.** A `--full`, a pass that admits under `--no-embed`,
+`--no-extract` or `--no-schema-pack`, and a legacy cursor the pass retires
+open an episode on the pass row: the selection and the processing opt-outs it
+ran with. Later plain syncs inherit those opt-outs
+(`convergence.episode.inherited`) until the episode closes, which happens
+when a converged pass covers its paths or runs at the configured selection.
+There is no command to abandon an episode: the plain sync always finishes
+it, and a `--full` continues until every path it covers is settled.
+
+<a id="dry-run-convergence-classes"></a>
+## Convergence classes
+
+`convergence.classes` (in `sync status` and in `gbrain sync --dry-run
+--json`) counts the paths of the newest round by class, each with an
+`action`: who finishes it.
+
+- `none`, nothing to do: `matched` (the page is what the file says),
+ `adopt` (the import record is updated to the file without a page write),
+ `kept` (the commit no longer has a file that is still on disk, so its page
+ stays), `untracked` (a file on disk the commit does not have, with no
+ page), `gone` (no file and no live page), `deleted_same` and `legacy_same` (a deleted page whose file is
+ unchanged), and `db_ahead` (the page changed in the database and the file
+ did not; the sub-labels `pending`, `db_only` and `unproven` are
+ informational, and `gbrain repair file-drift --prefer database` writes one
+ back to its file if the owner wants it).
+- `owner`, sync finishes it by itself: `in_flight` (admitted, not yet
+ published), `import`, `reparse` (an unchanged file whose page is imported
+ again because its parser or schema pack changed, its origin moved, or an
+ open episode covers it), `delete`, `keep_db` and `keep_db_pending` (at most 200
+ DB-wins writes per pass; the rest wait for the next pass),
+ `legacy_unverified` (the legacy sweep checks it), and `paused_keep_db`
+ (which waits for the owner's `sync.admission` change, as paused deletes
+ do).
+- `repair`, a person decides: `held` (by code, with its triple above),
+ `drift`, `delete_drift` and `deleted_edited` (two-sided changes, held
+ `file_drift` with `side` and `state`), `dirty` (an uncommitted edit in
+ committed mode), `spelling` (files whose names differ only by case or
+ separator spelling), and
+ `deletes_withheld`.
+
+Dirtiness is read only for candidates: in committed mode the pass reads a
+file's working copy (`Dp`) only when the path would otherwise be admitted, so
+`dirty` counts only those, and a file whose page already matches its commit
+reads `matched` even when its working copy is edited.
## See also
diff --git a/docs/guides/write-refusals.md b/docs/guides/write-refusals.md
index 17a3a478d0..a56219cbc1 100644
--- a/docs/guides/write-refusals.md
+++ b/docs/guides/write-refusals.md
@@ -202,7 +202,7 @@ with each file and fix the ones that need no guessing."*
| <a id="legacy_slug_conflict"></a><a id="legacy_slug_conflict-explicit_id_conflict"></a>`legacy_slug_conflict` (`explicit_id_conflict`) | The file has no page at its slug, and several live pages an older gbrain imported before the current slug fold (a space, an emoji, an accent or a trailing dash in the slug; no recorded file) fold to that slug (#6727). Exactly one such page is taken over by the file: the next sync imports into it (same page id, links, timeline and aliases) and records the file as its origin, instead of creating a second page. With several, sync cannot tell which page is the file's, so it holds the file and the rest of the source syncs. It holds the file the same way when the one match has a slug sync cannot write as it stands (capital letters, from a gbrain that predates lowercase slugs; the importer lowercases), rather than creating a second page beside it. With reason `explicit_id_conflict` (#6729), the one match carries an explicit frontmatter `id` that differs from the file's, so it is a different document and is not taken over. With `sync.holds=fail` the run stops with `page_identity_changed`. Twins an older sync already created are not merged by this. | Ask the user which page is the file's (`gbrain sync status --source <source> --json` names every candidate slug). Remove each other one with `gbrain delete --source <source> -- '<slug>'` (soft delete, recoverable for 72 h), or rename the file if none of them is its page; with one match under a slug with capitals, which no command can address yet, keep the file held or rename it to a name that folds to another slug (it then imports as a new page beside the old one, which keeps its links). For `explicit_id_conflict`: give the file the page's `id` if it is the same document; otherwise rename the file or delete the old page. Then `gbrain sync --source <source> --no-pull`. The hold re-screens on every sync. |
| <a id="rename_held"></a><a id="rename_held-rename_source_changed"></a>`rename_held` (`rename_source_changed`) | A renamed file's hold cleared, but the page it was renamed from changed after the rename was recorded, so the page did not move. | `gbrain repair frontmatter --source <source> --include-ambiguous` proposes re-binding the rename to the old page's current revision; apply after the user agrees. Or restore the old file name. |
| <a id="concurrent_write"></a>`concurrent_write` | Managed sync was importing a newer Git version of the file while a database-only write (write-through off, a sandboxed or derived write) committed a different version of the same page, so the two diverge (#6194). The proof is the page's revision itself: it was written by a committed non-sync request for that page. Neither version was overwritten: the page keeps the database version, the file is held and the rest of the source syncs. Since #6340 a page that moved with no such request to name is held the same way (the hold records `page_revision` and `expected_revision` instead of a competing request), and so is a page that changed, was deleted or was re-bound in the database between the manifest freeze and the entry's turn; a page that still holds exactly what the file would import is re-bound to its new revision and passed. | `gbrain sources status <source>` names the page and the competing request. Preview with `gbrain sources reconcile <source> <slug> --preview`, decide with the user which content wins, apply the resolved preview, then `gbrain sources retry-held <source>` and `gbrain sync --source <source> --no-pull` re-screen the file. A new commit of the file re-screens it too. |
-| <a id="file_drift"></a>`file_drift` | Managed sync would have imported a file over a database version of its page that sync never saw (#6712). Every import records its provenance (the bytes left on disk, the page revision it wrote, the parser); a page that moved since that record (a database-only write, write-through off) while its file did not change, or, in a tree walk (first sync, `--full`, an unreachable checkpoint), a page whose file and revision both moved or that has no usable record (an upgraded brain: none, a pre-PR 0 record, a partial one), is imported only when the import changes nothing, a sync request wrote its current revision, or its writer's write-through wrote that revision to the file. Otherwise the file is held, the page keeps the database version and the rest of the source syncs. The hold names `sides` (`database`, `both`, `unknown`) and the database request that wrote the page when there was one. Pages under `storage.keep_db` prefixes are never held: the entry is skipped and the keep_db worker reconciles the page from the database. Holds of this code never escalate; with `sync.holds=fail` the run stops with `file_drift` instead of holding. | `gbrain sources status <source>` names the page. Preview `gbrain repair file-drift --source <source> --slug <slug> --prefer database` (keep the database copy, rewrite the file) or `--prefer file` (import the file), decide with the user, apply it with the plan hash, then `gbrain sync --source <source> --no-pull`. A changed file or page revision re-screens the hold by itself. |
+| <a id="file_drift"></a>`file_drift` | Managed sync would have imported a file over a database version of its page that sync never saw (#6712). Every import records its provenance (the bytes left on disk, the page revision it wrote, the parser); a page that moved since that record (a database-only write, write-through off) while its file did not change, or, in a tree walk (first sync, `--full`, an unreachable checkpoint), a page whose file and revision both moved or that has no usable record (an upgraded brain: none, a pre-PR 0 record, a partial one), is imported only when the import changes nothing, a sync request wrote its current revision, or its writer's write-through wrote that revision to the file. Otherwise the file is held, the page keeps the database version and the rest of the source syncs. The hold names `sides` (`database`, `both`, `unknown`) and the database request that wrote the page when there was one; a hold the live pass writes also names its Decision, `side` (`both`, `unknown`, `deleted`) and, for a deleted side, `state` (`tombstone_edited`, `purged_differs`, `file_gone`). Pages under `storage.keep_db` prefixes whose file is clean in committed mode are not held: the pass writes the database copy back to the file (at most 200 per pass, the rest the next pass); an uncommitted edit there is held. Holds of this code never escalate; with `sync.holds=fail` the run stops with `file_drift` instead of holding. | `gbrain sources status <source>` names the page. Preview `gbrain repair file-drift --source <source> --slug <slug> --prefer database` (keep the database copy, rewrite the file) or `--prefer file` (import the file), decide with the user, apply it with the plan hash, then `gbrain sync --source <source> --no-pull`. Held pages of one Decision resolve together with [`--held --side <side> [--state <state>]`](repair.md#file-drift-held). A changed file or page revision re-screens the hold by itself. |
| <a id="parser_regression"></a>`parser_regression` | With `GBRAIN_SYNC_PARSER_REGRESSION=hold`, a file whose exact bytes imported under an earlier gbrain is now refused. This is a gbrain bug. | Report it with the gbrain version, the file and the code; upgrade or pin the last good version. After a fixed gbrain is installed, `gbrain sources retry-held <source>` and then `gbrain sync --source <source> --no-pull` re-screen it. |
| <a id="settle_mismatch"></a>`settle_mismatch` | A live managed sync pass settled this file at the same level in three consecutive passes, but the next round never classified it settled (#6712). Instead of re-importing it every pass, sync held it at that level and stamped the rest of the source. The hold records the level and `meta.mismatch_streak`. The file is usually fine: a path that keeps coming back unsettled points to a broken writer, a stuck effect or a damaged record. | Run `gbrain doctor --json` and `gbrain sources writer status --source <source> --json` (both read-only), fix or report what they name with the gbrain version, then `gbrain sources retry-held <source>` and `gbrain sync --source <source> --no-pull`. A mismatch that comes back is held again after three passes. |
| <a id="preparation_stalled-hold"></a>`preparation_stalled` | The write for this file could not finish *preparing* within its attempt limit, so the sync held the file and kept going. The file is fine: no repair applies, and it is not imported until it is retried. Full reference: [`preparation_stalled`](#preparation_stalled). | `gbrain sources writer status --source <source> --json` (read-only), fix what it names, then `gbrain sources retry-held <source>` and the same sync with its options. Runbook: [catch-up stuck / held N files](troubleshooting.md#catch-up-stuck). |
diff --git a/llms-full.txt b/llms-full.txt
index 7955d12176..0ca705985d 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -1946,9 +1946,10 @@ writing or reviewing an operation, consult `src/core/operations.ts` for the cont
- **Keep a managed catch-up moving without a human** (a live checkout where
other agents commit while `gbrain sync` drains thousands of pages): a page
that moves under the run is held (`concurrent_write`, `worktree_dirty`), a
- dropped connection is retried, and a relaunch resumes the frozen manifest.
- The operator loop is `gbrain sync status --source <id> --json` (`state`
- and `reason`, cursor, `committed_last_10m`, each hold and the last error
+ dropped connection is retried, and a relaunch starts a pass that admits only
+ what is still unsettled. The operator loop is
+ `gbrain sync status --source <id> --json` (`state` and `reason`, the
+ newest pass in `convergence`, `committed_last_10m`, each hold and the last error
with `class` / `safe_actions` / `needs_human`), then, when nothing moved and
`needs_human` is false, `gbrain sync unblock --source <id> --apply` and
the sync it prints; when `needs_human` is true, relay `next.user_message`
@@ -6632,6 +6633,20 @@ command drains the whole backlog:
gbrain sync --source <id> --no-pull --json
```
+A managed source that is not a company brain syncs by a **level-triggered
+pass**: under the source's drain lease it pins `HEAD`, compares the whole tree
+with what the database absorbed (the pages and their import records) and
+admits only the paths that are not settled, in batches of at most 10,000 and
+at most four rounds. A pass with nothing unsettled and nothing in flight
+stamps `last_commit`. A killed pass loses nothing: the next plain sync reads the
+level again and admits only what is still unsettled, so a reset, a lost run or
+an out-of-band change converges without a flag. Its progress is the
+`convergence` block of `gbrain sync status --json` (`round`, `candidates`,
+`settled`, `remaining`, `classes`); the cursor fields there are null. A
+company-brain source keeps its cursor and frozen manifest. The pass's status
+reasons, `sync.admission`, the mass-delete valve and episodes are in the
+[sync unblock runbook](sync-unblock-runbook.md#the-pass-outcomes-and-status-reasons).
+
Managed sync never pulls: the checkout is fast-forwarded by
`gbrain sources refresh <id>`, never by sync. Sync then catches the index up
to whatever the checkout holds. The CLI implies `--no-pull` on a managed brain
@@ -6697,8 +6712,11 @@ The run ends in exactly one outcome:
| Outcome | Exit | Meaning | What to do |
| --- | --- | --- | --- |
-| `synced` | 0 | The cursor reached its target. | Nothing. |
-| `resumable` | 0 | A deadline, `--timeout` or Ctrl-C stopped it; the cursor and accepted writes are intact. | Rerun `next.command`; safe in a loop. |
+| `synced` | 0 | The pass converged and stamped (a company-brain source: the cursor reached its target). A pass at a selection other than the configured one adds `selection_scoped` and does not advance `last_commit`. | Nothing. |
+| `resumable` | 0 | A deadline, `--timeout` or Ctrl-C stopped it; accepted writes are intact. | Rerun `next.command`; safe in a loop. |
+| `resumable` / `not_converged` | 0 | The pass used its four rounds while another writer kept changing the level; everything it admitted stands. | Rerun `next.command`. After three in a row `next` is a report (`gbrain doctor --json`), not another sync. |
+| `resumable` / `admission_paused` | 0 | `sync.admission` is `imports_only` or `classify_only`. | Ask the user; `gbrain config set sync.admission normal` ends the pause. |
+| `blocked` / `reconcile_host_required` or `grant_scope` | 1 | A remote caller or a partial grant admitted what it could; the rest (holds, markers, keep_db writes, the stamp) needs the owner host. | Tell the user to run `gbrain sync --source <id> --no-pull` on the brain host. |
| `resumable` / `preparation_abandoned` | 0 | A write this process's own writer holds was still preparing past its allowance (its budget plus 30 s) and cannot be cancelled in-process, so the sync exited to end it; `drain.stall.step` says where. | Rerun `next.command`; safe in a loop. The next pass holds the entry if it stalls again. |
| `blocked` | 1 | A page failed or the writer needs intervention. | Follow `next.why`, then run `next.command`. See [drain stops](write-refusals.md#managed-sync-drain-stops). |
| `blocked` / `drain_stalled` | 1 | The head write made no progress (no commit, no step advance) for the whole window. With a live owner on this host the drain waits until the 600 s ceiling (printing `stalled <N>s on <step>` with the owner's pid and kind meanwhile) and stops with `cause: owner_wedged_here`, the owner `{kind, pid, nonce}` and `retry_after_ms` to the ceiling; a lapsed claim stops at once as `owner_missing`. | Before the ceiling: wait `retry_after_ms`, then rerun `next.command` (`safe_to_loop` is true). Past it, or with a wedged owner: restart the named owner process, `gbrain sources retry-held <id>`, then the same sync. `gbrain sources writer status --source <id> --json` ends the claim in a `next_action` that says which. See [drain stops](write-refusals.md#drain-stalled). |
@@ -7005,9 +7023,10 @@ would need the moved file as evidence, which is what the sync route provides.
Concurrent runs are safe. Two syncs on the same commit no-op because content
hashes match. If both a cron and `--watch` fire simultaneously, no conflict.
-Long syncs also survive being killed: progress checkpoints into the database
-as files drain, so a killed or aborted run resumes from where it stopped, and
-the sync bookmark only advances on true completion. A progress-aware stall
+Long syncs also survive being killed: every published page keeps its
+receipt and import record, so the next plain sync admits only what is still
+unsettled (a company-brain cursor resumes where it stopped), and the sync
+bookmark only advances when a pass converges. A progress-aware stall
watchdog (`GBRAIN_SYNC_STALL_ABORT_SECONDS`, default 900, `0` disables) aborts
a run that stops making forward progress and releases the per-source lock so
the next `gbrain sync` picks up from the checkpoint. The checkpoint cadence
@@ -7298,10 +7317,12 @@ Source: https://raw.githubusercontent.com/garrytan/gbrain/master/docs/guides/syn
A managed catch-up on a live checkout (`gbrain sync --source <id> --no-pull`,
thousands of pages, other agents committing to the brain repo every few
minutes) finishes unattended. A page that moves under the run is held, not
-fatal; a dropped database connection is retried, not fatal; a relaunch resumes
-the frozen manifest at its stored cursor instead of re-freezing it. What is
-left for an operator is one loop over two commands, and this page is the
-decision table behind them.
+fatal; a dropped database connection is retried, not fatal; a relaunch starts
+a new pass that reads the source's level again and admits only what is still
+unsettled, so nothing already settled is written twice (a company-brain source
+keeps its cursor and resumes its frozen manifest). What is left for an
+operator is one loop over two commands, and this page is the decision table
+behind them.
**Say to your agent:** *"Keep my brain's catch-up moving and tell me only when
a page needs my decision."*
@@ -7312,7 +7333,7 @@ a page needs my decision."*
gbrain doctor --only serve_build_drift --json # first: on a warning, restart serve and workers and stop here
gbrain sync status --source <id> --json # every N minutes (read-only)
gbrain sync unblock --source <id> --apply --json # when committed_last_10m is 0 and needs_human is false
-gbrain sync <next.argv...> # the sync unblock (or status) names: the cursor's own options
+gbrain sync <next.argv...> # the sync unblock (or status) names, with an open episode's inherited options
```
**Say to your agent:** *"Repair the files sync held and get the catch-up
@@ -7323,10 +7344,15 @@ moving again; ask me only about the ones gbrain will not decide by itself."*
command it prints before anything else, and stop until it reads ok
([serve build drift](troubleshooting.md#serve-build-drift)).
1. Read `status`. `state` (`synced` | `resumable` | `blocked`) and `reason`
- say where the source stands; `cursor` is where the run stands
- (`index/total`, the `pinned_target` commit, `last_advance_at`);
- `committed_last_10m` is the signal that data is moving (a live process with
- a flat cursor is not progress). `holds` and `last_error` each carry the
+ say where the source stands. Where the run stands is `convergence` for a
+ managed source synced by the live pass (its newest pass: `pass_id`,
+ `outcome`, `stop_reason`, `round`, `candidates`, `settled`, `remaining`,
+ `classes`; see [the pass](#the-pass-outcomes-and-status-reasons)); there
+ `run_id`, `cursor`, `rate_pages_per_min` and `eta_seconds` are null because
+ no cursor exists. A company-brain source keeps `cursor` (`index/total`, the
+ `pinned_target` commit, `last_advance_at`). `committed_last_10m` is the
+ signal that data is moving (a live process with a flat pass is not
+ progress). `holds` and `last_error` each carry the
triple below, plus `category` and `public_category`. `oldest_blocker` and
`recovery` are bounded live probes that need no cursor; when one times out
the state is `resumable` / `status_unknown`, never `synced`. A plain status
@@ -7349,8 +7375,9 @@ moving again; ask me only about the ones gbrain will not decide by itself."*
refuses every repair-class hold instead, as releases before #6377 did.
3. Run that sync. It re-screens the scheduled files, imports each one that now
passes and holds again what still fails; the rest of the source is never
- blocked. A cursor an older release left blocked on a
- page fault converts in place (same run, no rediscovery).
+ blocked. An unfinished cursor an older release left is retired by the next
+ pass: the pass waits for the requests it already admitted, keeps its
+ processing options for the episode, and settles the rest from the level.
4. If `needs_human` is true, stop looping and page a person with the slug and
`human_reason` from `status` (`next.user_message` is written for relay).
@@ -7415,6 +7442,7 @@ Every hold and error has three fields, from one table
| `purged_content` | page | none | yes | always: only the owner clears a purge tombstone |
| `write_gate_rejected` | page | none | yes | always: write_gate.external_mode=reject is the user's setting |
| `legacy_slug_conflict` | page | none | yes | always: only a person decides which legacy page the file takes over |
+| `settle_mismatch` | page | none | yes | always: the pass cannot tell why the path does not settle |
| `revision_conflict` | page | retry | no | the same path fails again after a rerun |
| `page_identity_changed` | page | retry | no | the same path fails again after a rerun |
| `pinned_git_worktree_conflict` | page | retry | no | the same path fails again after a rerun |
@@ -7559,6 +7587,9 @@ the next plain sync.
## Why the manifest is not re-frozen any more
+This section is about company-brain sources and legacy cursors, the only
+runs that still freeze a manifest; a pass keeps no manifest to lose.
+
The frozen manifest always lived in the cursor (`op_checkpoints`, op
`managed-sync`). What threw it away was the failure ledger: every run death
wrote a row, and the retry read the row and rediscovered from index 0
@@ -7607,12 +7638,88 @@ days, so a soak can show that sync keeps moving on its own.
Each line has one count per kind and a `total`; `by_day` lists both line
totals for each day that recorded anything. Fields are only ever added.
-## Dry-run convergence classes
+## The pass: outcomes and status reasons
-`sync --dry-run --json` adds a read-only `convergence` receipt. Class actions:
-- `none`: settled.
-- `owner`: sync finishes it.
-- `repair`: a person decides.
+A managed source that is not a company brain syncs by a level-triggered pass:
+under the source's drain lease it pins `HEAD`, reads the whole level (the
+tree, the index, the pages and their import records) and admits only the
+paths that are not settled, in at most four rounds. A pass with nothing
+unsettled and nothing in flight stamps `last_commit`. Every plain sync
+compares the whole tree with what the database absorbed, so a reset or a lost
+run converges on the next plain sync with no flag.
+
+| Status `reason` | `state` | What it means | `next` |
+|---|---|---|---|
+| `pass_unfinished` | resumable | The newest pass is open or stopped at a deadline. | The plain sync (`resume_argv`); safe to loop. |
+| `not_converged` | resumable | The pass used its four rounds while another writer kept changing the level. Everything it admitted stands. | The plain sync; after three such passes in a row `next` is `gbrain doctor --json` and a report, because another sync will not change it. |
+| `settle_mismatch` | resumable | A path keeps settling without reading settled. The next pass re-admits it once; after three passes at one level it is a `settle_mismatch` hold that needs a person. | The plain sync, then report the hold. |
+| `deletes_withheld` | blocked | The pass's deletes crossed the mass-delete threshold (#2828). It wrote one withheld record and synced everything else; no per-page hold is written. | Ask the user: restore the checkout if it is wrong, or run `GBRAIN_ALLOW_MASS_RECONCILE=1 gbrain sync --source <id>` on the brain host when the deletion is intended. `gbrain sync --source <id> --dry-run --json` lists the set and its hash. |
+| `admission_paused` | resumable | `sync.admission` is `imports_only` or `classify_only`. | Ask the user to run `gbrain config set sync.admission normal` when the pause is over; it is never lifted automatically. |
+| `selection_scoped` | synced | The pass converged at a selection other than the source's configured one (a CLI `--exclude`, say) and did not advance `last_commit`. | None; the next plain sync runs the configured selection. |
+
+The run's own JSON (`outcome`, `drain.stop_reason`) adds three stops a status
+read never shows as its reason: `grant_scope` (a grant that covers only part of
+the source admitted what it can see), `reconcile_host_required` (a remote
+caller admitted its one-sided work; holds, markers, keep_db writes and the
+stamp need the owner host) and `reconcile_read_incomplete` (a Git listing did
+not finish, so the pass wrote nothing). All three end `blocked` with
+`tell_user_to_run` or `report`; see
+[drain stops](write-refusals.md#managed-sync-drain-stops).
+
+**`sync.admission`** (`normal` | `imports_only` | `classify_only`) is the
+owner's brake on what sync writes, brain-wide. `imports_only` admits no
+deletes and no keep_db writes (they wait as paused deletes and
+`paused_keep_db`); `classify_only` reads and classifies and writes only the
+pass row. It is read at the pin and in every group's admission, and a delete
+or keep_db write already admitted re-reads it when it publishes, so nothing
+destructive lands after the change takes effect (`admission.effective` in
+`sync status`). Doctor `sync_admission_restricted` warns while it is not
+`normal`.
+
+**Episodes.** A `--full`, a pass that admits under `--no-embed`,
+`--no-extract` or `--no-schema-pack`, and a legacy cursor the pass retires
+open an episode on the pass row: the selection and the processing opt-outs it
+ran with. Later plain syncs inherit those opt-outs
+(`convergence.episode.inherited`) until the episode closes, which happens
+when a converged pass covers its paths or runs at the configured selection.
+There is no command to abandon an episode: the plain sync always finishes
+it, and a `--full` continues until every path it covers is settled.
+
+<a id="dry-run-convergence-classes"></a>
+## Convergence classes
+
+`convergence.classes` (in `sync status` and in `gbrain sync --dry-run
+--json`) counts the paths of the newest round by class, each with an
+`action`: who finishes it.
+
+- `none`, nothing to do: `matched` (the page is what the file says),
+ `adopt` (the import record is updated to the file without a page write),
+ `kept` (the commit no longer has a file that is still on disk, so its page
+ stays), `untracked` (a file on disk the commit does not have, with no
+ page), `gone` (no file and no live page), `deleted_same` and `legacy_same` (a deleted page whose file is
+ unchanged), and `db_ahead` (the page changed in the database and the file
+ did not; the sub-labels `pending`, `db_only` and `unproven` are
+ informational, and `gbrain repair file-drift --prefer database` writes one
+ back to its file if the owner wants it).
+- `owner`, sync finishes it by itself: `in_flight` (admitted, not yet
+ published), `import`, `reparse` (an unchanged file whose page is imported
+ again because its parser or schema pack changed, its origin moved, or an
+ open episode covers it), `delete`, `keep_db` and `keep_db_pending` (at most 200
+ DB-wins writes per pass; the rest wait for the next pass),
+ `legacy_unverified` (the legacy sweep checks it), and `paused_keep_db`
+ (which waits for the owner's `sync.admission` change, as paused deletes
+ do).
+- `repair`, a person decides: `held` (by code, with its triple above),
+ `drift`, `delete_drift` and `deleted_edited` (two-sided changes, held
+ `file_drift` with `side` and `state`), `dirty` (an uncommitted edit in
+ committed mode), `spelling` (files whose names differ only by case or
+ separator spelling), and
+ `deletes_withheld`.
+
+Dirtiness is read only for candidates: in committed mode the pass reads a
+file's working copy (`Dp`) only when the path would otherwise be admitted, so
+`dirty` counts only those, and a file whose page already matches its commit
+reads `matched` even when its working copy is edited.
## See also
diff --git a/src/commands/sync/args.ts b/src/commands/sync/args.ts
index 56fc57c564..ff7eb3d23a 100644
--- a/src/commands/sync/args.ts
+++ b/src/commands/sync/args.ts
@@ -206,7 +206,7 @@ Classic brains / advanced (classic sync, processing opt-outs, one-off repair):
Subcommands:
gbrain sync status --source <id> [--json]
- Where a managed catch-up stands: cursor, pages
+ Where a managed catch-up stands: pass or cursor, pages
committed in the last 10 minutes, each hold and the
last error with class / safe_actions / needs_human,
and the next action (for an operator agent's loop).
diff --git a/src/commands/sync/operator.ts b/src/commands/sync/operator.ts
index 80397a0a17..4c8a0ad7d1 100644
--- a/src/commands/sync/operator.ts
+++ b/src/commands/sync/operator.ts
@@ -24,8 +24,10 @@ export function printSyncStatusHelp(): void {
console.log(`Usage: gbrain sync status --source <id> [--detail] [--json]
Where a managed catch-up stands and what to do next, for an operator agent:
-the cursor (index/total, pinned target, last advance), pages committed in the
-last 10 minutes, every held file and the last recorded failure, each with
+the newest sync pass (convergence: outcome, round, candidates, settled,
+remaining, classes) or, for a company-brain source, the cursor (index/total,
+pinned target, last advance), pages committed in the last 10 minutes, every
+held file and the last recorded failure, each with
class page | connection | systemic
safe_actions retry | retry_when_clean | repair | reconcile | upgrade | none
needs_human whether a person has to decide or act (human_reason says why)
@@ -45,6 +47,16 @@ needs_human is false, run \`gbrain sync unblock --source <id> --apply\`, then
the sync it prints; when needs_human is true, page a person with the slug it
names; when a *_read field is not_read and you need it, run its fix.
+convergence.classes counts the newest round's paths by class, each with an
+action (who finishes it):
+ none matched, adopt, kept, untracked, gone, deleted_same, legacy_same, db_ahead
+ owner sync finishes it: in_flight, import, reparse, delete, keep_db,
+ keep_db_pending, legacy_unverified, paused_keep_db
+ repair a person decides: held, drift, delete_drift, deleted_edited, dirty,
+ spelling, deletes_withheld
+Committed mode reads a file's working-copy dirtiness only for candidates, so
+dirty counts only paths sync would otherwise admit.
+
Decision table: docs/guides/sync-unblock-runbook.md
`);
}