Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

docs: move on-commit sync to its own guide so llms-full.txt stays within budget

garrytan1a22911be387
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 23436f1799..988f9e75f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,7 @@ To turn it on, run `gbrain config set sync.on_commit true` on the brain host. Th
- New `src/core/serve-head-watcher.ts`, started next to the movement watch in `gbrain serve` and `gbrain serve --http`. With `sync.on_commit` on it polls `git rev-parse HEAD` in the checkout of each managed source this host owns every 3 s (`GBRAIN_SERVE_HEAD_POLL_MS`, 1 to 30 s), with an `fs.watch` on the git directory that only brings the next poll forward, debounces 3 s (`GBRAIN_SERVE_HEAD_DEBOUNCE_MS`) and starts one managed sync through the existing `startDelegatedSync` as this host's CLI writer. It never starts beside a running delegated sync or a held drain lease, skips a commit the source has already synced, resumes a resumable stop up to three times, never writes into the checkout or `.git`, and logs each distinct error once. With the setting off it makes no git call.
- New `src/core/persistence/sync-freshness.ts`: commit→searchable and commit→embedded p50/p95 per managed source from existing columns (the commit's committer time from git, `persistence_requests.completed_at` of committed `managed_sync_import` receipts, `content_chunks.embedded_at`). Commit→embedded counts only a receipt that is still the page's current revision, and only an embedding at or after its write, so a later revision never rewrites an earlier sample. First syncs and working-tree entries are not counted; a run that spans several commits is dated by its newest. No schema change.
+- New guide `docs/guides/on-commit-sync.md` (linked from the `sync.*` tunables in `docs/guides/live-sync.md`; indexed in `llms.txt` but not inlined in `llms-full.txt`, which master had within 233 bytes of its 800,000-byte budget).
- New config keys `sync.on_commit` and `sync.freshness_target_seconds` (tunables in `src/core/sync-config-keys.ts`).
- New doctor check `managed_sync_latency` (`src/commands/doctor/checks/managed-sync-latency.ts`); the doctor goldens are regenerated for it. With grading on it also warns when the synced commits are not in this host's git checkout (the latency cannot be measured), and `doctor --source` grades only that source.
- Tests: `test/serve-head-watcher.test.ts` (debounce, single flight, follow-up, resume cap, error handling, stop), `test/serve-head-watcher-managed.serial.test.ts` (a real managed source on PGLite and Postgres: a commit becomes searchable with no manual sync), `test/serve-http-head-watcher.serial.test.ts` (the watcher starts with `gbrain serve --http` and its poll interval is cleared on shutdown), `test/sync-freshness-6858.test.ts` (percentiles, exclusions, doctor thresholds, the additive `sync status --json` block). The two database tests are listed in `test/postgres-unit-arms.txt`.
diff --git a/docs/guides/live-sync.md b/docs/guides/live-sync.md
index b3c1661ca3..0195de7d21 100644
--- a/docs/guides/live-sync.md
+++ b/docs/guides/live-sync.md
@@ -124,7 +124,7 @@ Timing knobs the drain uses:
- **Tunables** you set and keep: `sync.bulk_size`, `sync.lanes`, `sync.exclude`, `sync.include_hidden`,
`sync.include_working_tree`, `sync.holds`, `sync.write_through`, `sync.cost_gate_min_usd`, `sync.on_commit`,
- `sync.freshness_target_seconds` ([On-commit sync](#on-commit-sync)).
+ `sync.freshness_target_seconds` ([on-commit sync](on-commit-sync.md)).
- **Rollback keys**, the way back a notice or migration promised: `sync.job_drain`, `sync.foreground_priority`,
`sync.federated_v2`, `sync.waive_batch`, `sync.bulk`. Each one set to `false` restores the earlier behavior, and
stays honored until at least 2027-01-14 (`CONFIG_ROLLBACK_WINDOWS` in `src/core/wire-skew.ts`). They are not
@@ -209,48 +209,6 @@ Two more tips:
A shell loop around `gbrain sync --source <id> --no-pull` until it prints
`synced` also works; each run drains as far as its deadline allows.
-## On-commit sync
-
-On a managed brain, `gbrain serve` can sync a source as soon as a commit lands
-in its checkout, instead of waiting for the next scheduled sync. It is off by
-default; turn it on with:
-
-```bash
-gbrain config set sync.on_commit true
-```
-
-The serve reads the flag every 30 seconds, so no restart is needed in either
-direction. While it is on, the stdio `gbrain serve` polls `git rev-parse HEAD`
-in the checkout of every managed source this host owns, every 3 seconds
-(`GBRAIN_SERVE_HEAD_POLL_MS`, 1 to 30 s), with a file watch on the git
-directory that only brings the next poll forward. When HEAD has stopped moving
-for 3 seconds (`GBRAIN_SERVE_HEAD_DEBOUNCE_MS`) and differs from what the
-source last synced, the serve runs one managed sync (`--no-pull`) as this
-host's CLI writer. A sync that is already running, here or in another process,
-is never doubled: the commit waits and gets one more sync when that one ends.
-A sync that stops resumable is resumed up to three times. Nothing is written
-into the checkout or `.git`, and an idle poll costs one git call per checkout.
-Both `gbrain serve` and `gbrain serve --http` run the watcher.
-
-For a small page, expect a commit to be searchable in about 5 to 15 seconds:
-up to 3 s to notice, the 3 s debounce, then the page write. Embedding follows
-the sync's own embedding path, so commit→embedded is longer.
-
-Each managed source's freshness over the last 24 hours shows in
-`gbrain sync status --source <id>` (the `freshness` block in `--json`) and
-in `gbrain status`: p50 and p95 of commit→searchable (from the commit's
-committer time to the page write's `completed_at`) and commit→embedded (to
-the page's last chunk embedding, counted only while that write is still the
-page's current revision and only for an embedding after the write). A first sync and working-tree entries are not
-counted, and a run that spans several commits is dated by its newest. Doctor
-`managed_sync_latency` warns when p95 commit→searchable is over
-`sync.freshness_target_seconds` (default 300) and fails over one hour; it
-grades only a brain with `sync.on_commit` on or a target set, and otherwise
-reports the numbers. With grading on, it also warns when the synced commits are
-not in this host's git checkout, so their latency cannot be measured.
-`gbrain doctor --source <id>` grades only that source. A stopped or stalled sync is reported by doctor
-`managed_sync_not_moving`, not by this check.
-
## Implementation
### Prerequisite: a reachable direct connection
diff --git a/docs/guides/on-commit-sync.md b/docs/guides/on-commit-sync.md
new file mode 100644
index 0000000000..33da865cea
--- /dev/null
+++ b/docs/guides/on-commit-sync.md
@@ -0,0 +1,44 @@
+# On-commit sync
+
+On a managed brain, `gbrain serve` can sync a source as soon as a commit lands
+in its checkout, instead of waiting for the next scheduled sync. It is off by
+default; turn it on with:
+
+```bash
+gbrain config set sync.on_commit true
+```
+
+The serve reads the flag every 30 seconds, so no restart is needed in either
+direction. While it is on, the serve polls `git rev-parse HEAD` in the checkout
+of every managed source this host owns, every 3 seconds
+(`GBRAIN_SERVE_HEAD_POLL_MS`, 1 to 30 s), with a file watch on the git directory
+that only brings the next poll forward. When HEAD has stopped moving for 3
+seconds (`GBRAIN_SERVE_HEAD_DEBOUNCE_MS`) and differs from what the source last
+synced, the serve runs one managed sync (`--no-pull`) as this host's CLI writer.
+A sync that is already running, here or in another process, is never doubled:
+the commit waits and gets one more sync when that one ends. A sync that stops
+resumable is resumed up to three times. Nothing is written into the checkout or
+`.git`, and an idle poll costs one git call per checkout. Both `gbrain serve`
+and `gbrain serve --http` run the watcher.
+
+For a small page, expect a commit to be searchable in about 5 to 15 seconds: up
+to 3 s to notice, the 3 s debounce, then the page write. Embedding follows the
+sync's own embedding path, so commit→embedded is longer.
+
+Each managed source's freshness over the last 24 hours shows in `gbrain sync
+status --source <id>` (the `freshness` block in `--json`) and in `gbrain
+status`: p50 and p95 of commit→searchable (from the commit's committer time to
+the page write's `completed_at`) and commit→embedded (to the page's last chunk
+embedding, counted only while that write is still the page's current revision
+and only for an embedding after the write). A first sync and working-tree
+entries are not counted, and a run that spans several commits is dated by its
+newest. Doctor `managed_sync_latency` warns when p95 commit→searchable is over
+`sync.freshness_target_seconds` (default 300) and fails over one hour; it grades
+only a brain with `sync.on_commit` on or a target set, and otherwise reports the
+numbers. With grading on, it also warns when the synced commits are not in this
+host's git checkout, so their latency cannot be measured. `gbrain doctor
+--source <id>` grades only that source. A stopped or stalled sync is reported by
+doctor `managed_sync_not_moving`, not by this check.
+
+The rest of managed sync (backlogs, holds, the drain) is in
+[live sync](live-sync.md).
diff --git a/llms-full.txt b/llms-full.txt
index 86be4fba80..497fefe791 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -6730,7 +6730,7 @@ Timing knobs the drain uses:
- **Tunables** you set and keep: `sync.bulk_size`, `sync.lanes`, `sync.exclude`, `sync.include_hidden`,
`sync.include_working_tree`, `sync.holds`, `sync.write_through`, `sync.cost_gate_min_usd`, `sync.on_commit`,
- `sync.freshness_target_seconds` ([On-commit sync](#on-commit-sync)).
+ `sync.freshness_target_seconds` ([on-commit sync](on-commit-sync.md)).
- **Rollback keys**, the way back a notice or migration promised: `sync.job_drain`, `sync.foreground_priority`,
`sync.federated_v2`, `sync.waive_batch`, `sync.bulk`. Each one set to `false` restores the earlier behavior, and
stays honored until at least 2027-01-14 (`CONFIG_ROLLBACK_WINDOWS` in `src/core/wire-skew.ts`). They are not
@@ -6815,48 +6815,6 @@ Two more tips:
A shell loop around `gbrain sync --source <id> --no-pull` until it prints
`synced` also works; each run drains as far as its deadline allows.
-## On-commit sync
-
-On a managed brain, `gbrain serve` can sync a source as soon as a commit lands
-in its checkout, instead of waiting for the next scheduled sync. It is off by
-default; turn it on with:
-
-```bash
-gbrain config set sync.on_commit true
-```
-
-The serve reads the flag every 30 seconds, so no restart is needed in either
-direction. While it is on, the stdio `gbrain serve` polls `git rev-parse HEAD`
-in the checkout of every managed source this host owns, every 3 seconds
-(`GBRAIN_SERVE_HEAD_POLL_MS`, 1 to 30 s), with a file watch on the git
-directory that only brings the next poll forward. When HEAD has stopped moving
-for 3 seconds (`GBRAIN_SERVE_HEAD_DEBOUNCE_MS`) and differs from what the
-source last synced, the serve runs one managed sync (`--no-pull`) as this
-host's CLI writer. A sync that is already running, here or in another process,
-is never doubled: the commit waits and gets one more sync when that one ends.
-A sync that stops resumable is resumed up to three times. Nothing is written
-into the checkout or `.git`, and an idle poll costs one git call per checkout.
-Both `gbrain serve` and `gbrain serve --http` run the watcher.
-
-For a small page, expect a commit to be searchable in about 5 to 15 seconds:
-up to 3 s to notice, the 3 s debounce, then the page write. Embedding follows
-the sync's own embedding path, so commit→embedded is longer.
-
-Each managed source's freshness over the last 24 hours shows in
-`gbrain sync status --source <id>` (the `freshness` block in `--json`) and
-in `gbrain status`: p50 and p95 of commit→searchable (from the commit's
-committer time to the page write's `completed_at`) and commit→embedded (to
-the page's last chunk embedding, counted only while that write is still the
-page's current revision and only for an embedding after the write). A first sync and working-tree entries are not
-counted, and a run that spans several commits is dated by its newest. Doctor
-`managed_sync_latency` warns when p95 commit→searchable is over
-`sync.freshness_target_seconds` (default 300) and fails over one hour; it
-grades only a brain with `sync.on_commit` on or a target set, and otherwise
-reports the numbers. With grading on, it also warns when the synced commits are
-not in this host's git checkout, so their latency cannot be measured.
-`gbrain doctor --source <id>` grades only that source. A stopped or stalled sync is reported by doctor
-`managed_sync_not_moving`, not by this check.
-
## Implementation
### Prerequisite: a reachable direct connection
diff --git a/llms.txt b/llms.txt
index 0acbf67801..f2f8a208d7 100644
--- a/llms.txt
+++ b/llms.txt
@@ -39,6 +39,7 @@ Repo: https://github.com/garrytan/gbrain
- [docs/guides/retrieval-feedback.md](https://raw.githubusercontent.com/garrytan/gbrain/master/docs/guides/retrieval-feedback.md): Use-attributed retrieval feedback: answer ids, `rate_answer` / `gbrain rate` (whole answer or single pages), how ratings move page weights and ranking (bounded ±λ), citation learning, revision handling, who may teach the brain, `gbrain feedback status|reset`, config keys and every refusal code.
- [docs/guides/pinned-questions.md](https://raw.githubusercontent.com/garrytan/gbrain/master/docs/guides/pinned-questions.md): Pinned questions: cited answers kept current from your notes (`gbrain questions pin|list|status|refresh|unpin`, `questions_*` MCP tools), read-time staleness, receipts and blocked reasons, owner-private visibility, consent for paid refresh, the standing_questions phase and the dream.auto_think migration.
- [docs/guides/live-sync.md](https://raw.githubusercontent.com/garrytan/gbrain/master/docs/guides/live-sync.md): Incremental markdown sync setup.
+- [docs/guides/on-commit-sync.md](https://raw.githubusercontent.com/garrytan/gbrain/master/docs/guides/on-commit-sync.md): Opt-in on-commit sync in gbrain serve (sync.on_commit) and the per-source commit→searchable/embedded latency.
- [docs/guides/shared-checkout-git.md](https://raw.githubusercontent.com/garrytan/gbrain/master/docs/guides/shared-checkout-git.md): Committing and pushing when several agents share one brain checkout: `gbrain git commit-push` / `scripts/brain-commit-push.sh` (writer lock, path-scoped commit, in-memory merge, fast-forward-only advance), the outcome table, conflict resolution with --resolve, recovering a stuck rebase, the lock contract for host daemons, and the git commands never to run there.
- [docs/guides/sync-unblock-runbook.md](https://raw.githubusercontent.com/garrytan/gbrain/master/docs/guides/sync-unblock-runbook.md): Operator-agent loop for a managed catch-up on a live checkout: gbrain sync status --json (cursor, committed_last_10m, each hold and the last error with class / safe_actions / needs_human), gbrain sync unblock --apply, and the decision table (page / connection / systemic) behind them.
- [docs/guides/cron-schedule.md](https://raw.githubusercontent.com/garrytan/gbrain/master/docs/guides/cron-schedule.md): Recurring job scheduling.
diff --git a/scripts/llms-config.ts b/scripts/llms-config.ts
index fa1a10eb6f..2a055cef87 100644
--- a/scripts/llms-config.ts
+++ b/scripts/llms-config.ts
@@ -173,6 +173,12 @@ export const SECTIONS: DocSection[] = [
description: "Incremental markdown sync setup.",
path: "docs/guides/live-sync.md",
},
+ {
+ title: "docs/guides/on-commit-sync.md",
+ description: "Opt-in on-commit sync in gbrain serve (sync.on_commit) and the per-source commit→searchable/embedded latency.",
+ path: "docs/guides/on-commit-sync.md",
+ includeInFull: false,
+ },
{
title: "docs/guides/shared-checkout-git.md",
description:
diff --git a/src/commands/doctor/checks/managed-sync-latency.ts b/src/commands/doctor/checks/managed-sync-latency.ts
index 066af2b750..06c135021c 100644
--- a/src/commands/doctor/checks/managed-sync-latency.ts
+++ b/src/commands/doctor/checks/managed-sync-latency.ts
@@ -16,7 +16,7 @@ import { readManagedMode } from '../../../core/persistence/managed-mode.ts';
import { FRESHNESS_FAIL_SECONDS, formatLatency, readFreshnessTarget, readSyncFreshness, type SourceFreshness } from '../../../core/persistence/sync-freshness.ts';
import { SYNC_ON_COMMIT_KEY } from '../../../core/sync-config-keys.ts';
-const DOCS = 'docs/guides/live-sync.md#on-commit-sync';
+const DOCS = 'docs/guides/on-commit-sync.md';
const p95 = (f: SourceFreshness) => f.commit_to_searchable.p95_seconds ?? 0;
const line = (f: SourceFreshness) => `${f.source_id} (p95 ${formatLatency(f.commit_to_searchable.p95_seconds)}, p50 ${formatLatency(f.commit_to_searchable.p50_seconds)}, ${f.commit_to_searchable.samples} page(s))`;
diff --git a/test/fixtures/goldens/doctor/content-pglite-json.json b/test/fixtures/goldens/doctor/content-pglite-json.json
index b11ac4b388..da1839fe48 100644
--- a/test/fixtures/goldens/doctor/content-pglite-json.json
+++ b/test/fixtures/goldens/doctor/content-pglite-json.json
@@ -2287,7 +2287,7 @@
{
"category": "brain",
"details": {
- "docs": "docs/guides/live-sync.md#on-commit-sync",
+ "docs": "docs/guides/on-commit-sync.md",
"fail_seconds": 3600,
"graded": false,
"on_commit": false,
diff --git a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
index 96596b1ab2..6b14eacae2 100644
--- a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
@@ -2411,7 +2411,7 @@
{
"category": "brain",
"details": {
- "docs": "docs/guides/live-sync.md#on-commit-sync",
+ "docs": "docs/guides/on-commit-sync.md",
"fail_seconds": 3600,
"graded": false,
"on_commit": false,
@@ -6402,7 +6402,7 @@
{
"category": "brain",
"details": {
- "docs": "docs/guides/live-sync.md#on-commit-sync",
+ "docs": "docs/guides/on-commit-sync.md",
"fail_seconds": 3600,
"graded": false,
"on_commit": false,
diff --git a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
index 18e88d4430..26561d15f6 100644
--- a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
@@ -2415,7 +2415,7 @@
{
"category": "brain",
"details": {
- "docs": "docs/guides/live-sync.md#on-commit-sync",
+ "docs": "docs/guides/on-commit-sync.md",
"fail_seconds": 3600,
"graded": false,
"on_commit": false,
@@ -6407,7 +6407,7 @@
{
"category": "brain",
"details": {
- "docs": "docs/guides/live-sync.md#on-commit-sync",
+ "docs": "docs/guides/on-commit-sync.md",
"fail_seconds": 3600,
"graded": false,
"on_commit": false,
diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.json
index c7010edd5d..f3ae001d17 100644
--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json
+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json
@@ -2038,7 +2038,7 @@
{
"category": "brain",
"details": {
- "docs": "docs/guides/live-sync.md#on-commit-sync",
+ "docs": "docs/guides/on-commit-sync.md",
"fail_seconds": 3600,
"graded": false,
"on_commit": false,
diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.json
index 7b20371e3f..caebdce647 100644
--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json
@@ -2094,7 +2094,7 @@
{
"category": "brain",
"details": {
- "docs": "docs/guides/live-sync.md#on-commit-sync",
+ "docs": "docs/guides/on-commit-sync.md",
"fail_seconds": 3600,
"graded": false,
"on_commit": false,
diff --git a/test/fixtures/goldens/doctor/json-postgres-fresh.json b/test/fixtures/goldens/doctor/json-postgres-fresh.json
index 006e765e1d..47c7792fd8 100644
--- a/test/fixtures/goldens/doctor/json-postgres-fresh.json
+++ b/test/fixtures/goldens/doctor/json-postgres-fresh.json
@@ -2098,7 +2098,7 @@
{
"category": "brain",
"details": {
- "docs": "docs/guides/live-sync.md#on-commit-sync",
+ "docs": "docs/guides/on-commit-sync.md",
"fail_seconds": 3600,
"graded": false,
"on_commit": false,