Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

sync trigger: no_resident is a notice, not an exit 3

garrytanc74a28978aff
diff --git a/docs/architecture/key-files/commit-notifier.md b/docs/architecture/key-files/commit-notifier.md
index a4f72f00d1..0ea9e23cf1 100644
--- a/docs/architecture/key-files/commit-notifier.md
+++ b/docs/architecture/key-files/commit-notifier.md
@@ -6,7 +6,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `src/core/commit-notifier.ts` — the notifier core, pure over its seams (store, git reads, the runner). One loop per resident: claims the host lease every heartbeat (`GBRAIN_NOTIFIER_HEARTBEAT_MS`, default 10 s, lease two heartbeats; PGLite has no lease and the brain's holder owns), re-reads `sync.on_commit` and `sync.on_commit.sources` every 30 s (`parseOnCommit` is the one parser), lists the host's sources every 60 s, reads HEAD every poll (`GBRAIN_NOTIFIER_POLL_MS`, 3 s; a watch only nudges), and scans wanted markers every 15 s or on a nudge, with the flag off too. Starts on the leading edge of a quiet HEAD move (no rebase/merge/cherry-pick marker, no `index.lock`), then a 400 ms trailing window (`GBRAIN_NOTIFIER_QUIET_MS`). Per-source single flight under a host cap, least recently started first. Keeps a source due across refused starts, failed or blocked runs and resumable stops; retries at `RETRY_BACKOFF_MS` (5 s, 15 s, 1 min, 5 min) and reports `notifier_stalled` past the last tier without progress; `operator_blocked` waits for HEAD to move. Checks the fence before each start. Every decision is recorded (`decisions`) for tests; state and coverage rows are written on change only. Managed sources never take pull markers. Tests: `test/serve-head-watcher.test.ts` (memory store, `test/helpers/notifier-memory-store.ts`).
- `src/core/notifier/store.ts` — the durable rows (migration `v261-commit-notifier.ts`): `sync_wanted_markers` (source + intent freshness|pull|full, `generation` bumped on every upsert, `first_due_at` kept), `sync_notifier_leases` (one owner per host, fence bumped on takeover, release expires it now), `sync_notifier_sources` (state, retry schedule, last error and trace path, classic syncer host, coverage record). A drainer deletes only `WHERE generation =` the value it read (`clearMarker`, `settleMarkers`); freshness is due while `wanted_head IS DISTINCT FROM last_commit` (no ancestry assumption). `recordLocalSyncer` runs where `writeSyncAnchor` advances `last_commit`: records the syncer host and prunes satisfied markers (the CLI's re-check). `missingTable` lets callers on a pre-v261 brain read "nothing monitored".
- `src/core/notifier/resident.ts` + `src/core/notifier/detect.ts` — production seams and the one start path for every resident (`startResidentNotifier`: serve, serve --http through `src/core/serve-head-watcher.ts`, `gbrain jobs work`, the autopilot daemon). Never awaits: the first pass runs in the background. `GBRAIN_NOTIFIER=0` turns it off per process. Lists managed sources whose worktree this host owns and classic sources whose recorded syncer is this host (or `GBRAIN_NOTIFIER_CLASSIC_SOURCES`), skipping the rest with a reason. Starts syncs through the in-process delegated runner. Trace per source at `<gbrain home>/notifier/<source>.jsonl`. `detect.ts` resolves `--absolute-git-dir` / `--git-common-dir` (linked worktrees) and the quiet predicate. Tests: `test/pathological/s-notifier-classic-serve.test.ts`, `test/pathological/s-notifier-residents.test.ts`.
-- `src/core/notifier/nudge.ts` + `src/core/notifier/handoff.ts` + `src/commands/sync/trigger.ts` — submitters and drainers of wanted markers. `recordTriggerMarker` picks the intent (managed: freshness at the checkout HEAD; classic: pull) and `recordSyncNudge` answers the versioned, acknowledged `sync_nudge` IPC kind (`src/core/context/sync-ipc.ts`, `resolve-ipc.ts`, bound in `src/mcp/resolve-ipc-binding.ts`). `handoff.ts` is the post-run re-check of the `sync` job handler and the serve's delegated runner: read before the run, settle after, at most one follow-up (a queued job with `maxWaiting: 1`, or a nudge); a lock-busy skip records a marker and completes. `gbrain sync trigger` answers queued / coalesced (`maxPending: 1`) / nudged / no_resident (exit 3); on PGLite a live serve takes it over IPC (`maybeTriggerThroughServe` in `src/commands/sync-delegate.ts`, which also records a busy delegated sync). The GitHub push webhook (`submitGitHubPush` in `src/commands/serve-http-webhooks.ts`) records the pushed sha first; a managed source answers 409 `refresh_required`. Tests: `test/pathological/s-notifier-marker-handoff.test.ts`.
+- `src/core/notifier/nudge.ts` + `src/core/notifier/handoff.ts` + `src/commands/sync/trigger.ts` — submitters and drainers of wanted markers. `recordTriggerMarker` picks the intent (managed: freshness at the checkout HEAD; classic: pull) and `recordSyncNudge` answers the versioned, acknowledged `sync_nudge` IPC kind (`src/core/context/sync-ipc.ts`, `resolve-ipc.ts`, bound in `src/mcp/resolve-ipc-binding.ts`). `handoff.ts` is the post-run re-check of the `sync` job handler and the serve's delegated runner: read before the run, settle after, at most one follow-up (a queued job with `maxWaiting: 1`, or a nudge); a lock-busy skip records a marker and completes. `gbrain sync trigger` answers queued / coalesced (`maxPending: 1`) / nudged, exit 0, with the `no_resident` notice when no resident watches the source; on PGLite a live serve takes it over IPC (`maybeTriggerThroughServe` in `src/commands/sync-delegate.ts`, which also records a busy delegated sync). The GitHub push webhook (`submitGitHubPush` in `src/commands/serve-http-webhooks.ts`) records the pushed sha first; a managed source answers 409 `refresh_required`. Tests: `test/pathological/s-notifier-marker-handoff.test.ts`.
- `src/core/notifier/status.ts` — what users and agents see, from rows only (no git call): `readSourceFreshness` feeds the `freshness` entry of search and query responses (`src/core/ops/search.ts` `buildRetrievalResponseMeta`; current, behind, syncing, unknown, not_monitored), and `readNotifierBlock` / `formatNotifierBlock` the notifier block for sync status and doctor (resident or none with the `gbrain sync --source <id> --no-pull` fix; remote callers get no trace path, pid or host id). An owner is live by its unexpired lease (Postgres) or a running pid on this host (PGLite). Tests: `test/pathological/s-notifier-freshness-status.test.ts`.
## Autopilot and the jobs worker
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.md
index c6c1c6c999..58ecd50781 100644
--- a/docs/guides/error-codes.md
+++ b/docs/guides/error-codes.md
@@ -2471,16 +2471,6 @@ More: [docs/guides/write-refusals.md#no_pricing](../../docs/guides/write-refusal
More: [docs/guides/google-connect.md#troubleshooting](../../docs/guides/google-connect.md#troubleshooting)
-### no_resident
-
-<a id="no_resident"></a>
-
-| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
-|---|---|---|---|---|---|---|
-| A sync request (gbrain sync trigger) was recorded as a wanted marker, but no resident process (gbrain serve, gbrain jobs work or the autopilot daemon) runs on this brain to sync it. | On PGLite only the process that holds the database can sync, and none does; the marker is kept, so the next resident or sync drains it and nothing is lost. | Run gbrain sync --source <id> --no-pull now, or start gbrain serve (no service is installed for you); the recorded request is drained by the next resident. | agent | `gbrain doctor --json` | 3 | no |
-
-More: [docs/guides/on-commit-sync.md#no-resident](../../docs/guides/on-commit-sync.md#no-resident)
-
### no_routing_eval
<a id="no_routing_eval"></a>
diff --git a/docs/guides/on-commit-sync.md b/docs/guides/on-commit-sync.md
index 4d4c5a7642..60e8a9e22c 100644
--- a/docs/guides/on-commit-sync.md
+++ b/docs/guides/on-commit-sync.md
@@ -80,7 +80,9 @@ a sync is finishing is still served.
- gbrain sync trigger --source <id> [--json] records the request and answers
queued (a job was queued; stdout keeps job_id=N), coalesced (a job for the
source is already waiting or running), nudged (a running gbrain serve on
- PGLite took it and its notifier starts the sync) or no_resident.
+ PGLite took it and its notifier starts the sync); exit 0. When no resident
+ watches the source the answer also carries resident: null and the notice
+ no_resident with its fix.
- A GitHub push for a classic source queues one sync per source; a second push
while that job waits joins it and the newer commit is kept.
- gbrain sync while a serve on the same PGLite brain is already syncing records
@@ -116,7 +118,8 @@ requests. Doctor `commit_notifier` reads the same record: with sync.on_commit on
it warns for a source no resident watches or a stalled notifier, and with it off
it warns only when a recorded request waits with no resident.
-Search and query responses carry a freshness entry per source (current, behind,
+Once sync.on_commit is on, or a resident has observed a source, search and
+query responses carry a freshness entry per source (current, behind,
syncing, unknown or not_monitored, with the observed HEAD, when it was observed,
the detection mode and the held-file count). not_monitored means no resident is
watching the source: nothing will sync a new commit until one starts.
@@ -124,10 +127,12 @@ watching the source: nothing will sync a new commit until one starts.
<a id="no-resident"></a>
## no_resident
-gbrain sync trigger recorded the request, but no resident runs on this brain to
-sync it. Run gbrain sync --source <id> --no-pull now, or start gbrain serve (or
-gbrain jobs work, or the autopilot daemon); the first resident that starts drains
-the recorded request. No service is installed for you.
+A notice, not an error: gbrain sync trigger recorded the request (and queued a
+job, or the serve took it) and exits 0, but no resident watches the source, so
+the recorded request waits. Run gbrain sync --source <id> --no-pull now, or
+start gbrain serve (or gbrain jobs work, or the autopilot daemon); the first
+resident that starts drains the recorded request. No service is installed for
+you.
<a id="notifier-stalled"></a>
## notifier_stalled
diff --git a/src/commands/sync-delegate.ts b/src/commands/sync-delegate.ts
index 6579d04548..1a389ea12f 100644
--- a/src/commands/sync-delegate.ts
+++ b/src/commands/sync-delegate.ts
@@ -646,8 +646,9 @@ function pick<T extends object, K extends keyof T>(source: T, keys: readonly K[]
/**
* GBRA-133 PR 2a: `gbrain sync trigger` while a live serve holds the PGLite brain. The request is recorded as a wanted
* marker through the serve (sync_nudge, acknowledged) and its notifier starts the sync: action nudged, exit 0. A serve
- * running without a notifier (GBRAIN_NOTIFIER=0) records it too and answers no_resident (exit 3 with the fix).
- * Returns false off PGLite or when no serve holds the brain (the engine path records the marker: queued or no_resident).
+ * running without a notifier (GBRAIN_NOTIFIER=0) records it too; the outcome then carries resident: null and the
+ * no_resident notice with the fix. Returns false off PGLite or when no serve holds the brain (the engine path records
+ * the marker and queues the job).
* The owner-delegated sync paths in cli/main.ts skip `sync trigger`, which they would refuse as an unknown sync option.
*/
export async function maybeTriggerThroughServe(config: { engine?: string; database_path?: string; database_url?: string } | null, args: string[]): Promise<boolean> {
@@ -670,9 +671,10 @@ export async function maybeTriggerThroughServe(config: { engine?: string; databa
if (resp.error === 'unknown_source') { serr(`Source "${sourceId}" not found. List with: gbrain sources list`); await setVerdict(1); return true; }
return refuse(`refused the request (${resp.error ?? 'unknown error'}).`);
}
- const { finishTrigger } = await import('./sync/trigger.ts');
+ const { printTriggerOutcome } = await import('./sync/trigger.ts');
const m = resp.marker;
- await finishTrigger({ action: resp.notifier ? 'nudged' : 'no_resident', source_id: m.source_id, intent: m.intent, wanted_head: m.wanted_head, marker_generation: m.generation }, json);
- if (resp.notifier) await setVerdict(0);
+ printTriggerOutcome({ action: 'nudged', source_id: m.source_id, intent: m.intent, wanted_head: m.wanted_head, marker_generation: m.generation,
+ resident: resp.notifier ? { kind: resp.resident ?? 'serve', pid: holder.pid } : null }, json);
+ await setVerdict(0);
return true;
}
diff --git a/src/commands/sync/trigger.ts b/src/commands/sync/trigger.ts
index d122251872..dc5dc22e87 100644
--- a/src/commands/sync/trigger.ts
+++ b/src/commands/sync/trigger.ts
@@ -1,7 +1,11 @@
/** `gbrain sync trigger`: ask for a sync of one source without waiting for it (GBRA-133 PR 2a). */
import type { BrainEngine } from '../../core/engine.ts';
+import { cliRenderContext, renderNotice, type Notice } from '../../core/agent-output.ts';
-export type TriggerAction = 'queued' | 'nudged' | 'coalesced' | 'no_resident';
+export type TriggerAction = 'queued' | 'nudged' | 'coalesced';
+
+/** The resident that syncs the source (its notifier drains the marker), or null when none is running. */
+export interface TriggerResident { kind: string; pid: number | null }
export interface TriggerOutcome {
action: TriggerAction;
@@ -10,6 +14,7 @@ export interface TriggerOutcome {
wanted_head: string | null;
marker_generation: number;
job_id?: number;
+ resident: TriggerResident | null;
}
const USAGE = 'Usage: gbrain sync trigger --source <id> [--priority high|normal|low] [--json]';
@@ -23,17 +28,17 @@ its checkout's HEAD; pull for a classic source), so it is never lost while
another sync runs: whoever drains the source re-checks the marker afterwards.
Outcomes (stdout keeps job_id=N whenever a job is queued; --json prints
-{action, job_id?, wanted_head, ...}):
- queued a sync job was queued (Postgres; a jobs worker or autopilot runs it)
+{action, job_id?, wanted_head, resident, ...}):
+ queued a sync job was queued (a jobs worker or autopilot runs it)
coalesced a sync job for this source is already waiting or running; the
marker makes it (or the notifier) run once more if needed
nudged the running gbrain serve recorded the request and its notifier
starts the sync (PGLite)
- no_resident the request is recorded, but nothing on this brain will sync it
- until a resident starts; exit 3 with the fix
- gbrain sync --source <id> --no-pull
-Exit 0 for queued, coalesced and nudged; 3 for no_resident.
+When no resident (gbrain serve, gbrain jobs work or the autopilot daemon)
+watches the source, the outcome carries resident: null and the notice
+no_resident with the fix gbrain sync --source <id> --no-pull (one stderr line,
+or notice in --json). Exit 0 for every outcome.
See also:
gbrain sources webhook set <id> Set up GitHub-signed push webhook
@@ -41,24 +46,39 @@ See also:
`);
}
+/** The no_resident notice: the request is recorded, but nothing watches the source to run it on its own. */
+export function noResidentNotice(sourceId: string): Notice {
+ return {
+ code: 'no_resident', kind: 'degraded',
+ why: `No resident (gbrain serve, gbrain jobs work or the autopilot daemon) watches source ${sourceId}; the request is recorded and runs when one starts, or when a sync reaches it.`,
+ fix: { argv: ['gbrain', 'sync', '--source', sourceId, '--no-pull'], consent: [], actor: 'agent', requires_exclusive: false,
+ why: 'Syncs the checkout HEAD now; the recorded request clears once last_commit reaches it.' },
+ };
+}
+
export function printTriggerOutcome(o: TriggerOutcome, json: boolean): void {
- if (json) { console.log(JSON.stringify(o)); return; }
+ const notice = o.resident ? null : noResidentNotice(o.source_id);
+ if (json) {
+ console.log(JSON.stringify({ ...o, ...(notice ? { notice: renderNotice(notice, cliRenderContext()) } : {}) }));
+ return;
+ }
const head = o.wanted_head ? o.wanted_head.slice(0, 8) : 'upstream';
if (o.job_id !== undefined) console.log(`job_id=${o.job_id}`);
else console.log(`action=${o.action}`);
const line: Record<TriggerAction, string> = {
queued: `queued sync job ${o.job_id} for ${o.source_id} (${o.intent}, wanted ${head})`,
coalesced: `a sync job for ${o.source_id} is already waiting or running (job ${o.job_id}); the request is recorded and runs once more if that job does not reach ${head}`,
- nudged: `the running serve recorded the request for ${o.source_id} (${o.intent}, wanted ${head}) and its notifier starts the sync`,
- no_resident: `recorded the request for ${o.source_id} (${o.intent}, wanted ${head}), but no resident (gbrain serve, gbrain jobs work or the autopilot daemon) runs on this brain to sync it. Run: gbrain sync --source ${o.source_id} --no-pull`,
+ nudged: `the running serve recorded the request for ${o.source_id} (${o.intent}, wanted ${head})${o.resident ? ' and its notifier starts the sync' : ''}`,
};
console.error(`[sync trigger] ${line[o.action]}`);
+ if (notice) console.error(`[gbrain notice no_resident] ${notice.why} Run: ${notice.fix!.argv!.join(' ')}`);
}
/**
- * The engine path: Postgres queues a job (single flight per source through maxPending 1; the wanted marker replaces
- * the old 30 s idempotency bucket), PGLite records the marker and reports no_resident (a live serve would have taken
- * the request over its IPC socket before this process could open the brain, commands/sync-delegate.ts).
+ * The engine path: records the marker and queues a job on either engine (single flight per source through maxPending
+ * 1; the marker replaces the old 30 s idempotency bucket). On PGLite a live serve would have taken the request over its
+ * IPC socket before this process could open the brain (commands/sync-delegate.ts). The outcome names the source's
+ * resident, or none with the no_resident notice.
*/
export async function runSyncTrigger(engine: BrainEngine, args: string[]): Promise<void> {
if (args.includes('--help') || args.includes('-h')) return printSyncTriggerHelp();
@@ -84,7 +104,6 @@ export async function runSyncTrigger(engine: BrainEngine, args: string[]): Promi
}
const { marker, managed } = recorded;
const base = { source_id: marker.source_id, intent: marker.intent, wanted_head: marker.wanted_head, marker_generation: marker.generation };
- if (engine.kind === 'pglite') return finishTrigger({ action: 'no_resident', ...base }, json);
const { MinionQueue } = await import('../../core/minions/queue.ts');
const job = await new MinionQueue(engine).add('sync', {
sourceId: marker.source_id,
@@ -95,20 +114,7 @@ export async function runSyncTrigger(engine: BrainEngine, args: string[]): Promi
}, { priority, maxPending: 1 });
const { attachMarkerJob } = await import('../../core/notifier/store.ts');
await attachMarkerJob(engine, marker.source_id, marker.intent, marker.generation, job.id);
- await finishTrigger({ action: job.coalesced ? 'coalesced' : 'queued', ...base, job_id: job.id }, json);
-}
-
-/** Prints the outcome; no_resident also carries the error envelope (--json) and exits 3 with the fix. */
-export async function finishTrigger(o: TriggerOutcome, json: boolean): Promise<void> {
- if (o.action !== 'no_resident') return printTriggerOutcome(o, json);
- if (json) {
- const { opError } = await import('../../core/ops/contract.ts');
- const error = opError('no_resident', `No resident process syncs source ${o.source_id}; the request is recorded and waits for one.`,
- `Run gbrain sync --source ${o.source_id} --no-pull now, or start gbrain serve; the recorded request is drained by the next resident.`,
- { fix: { argv: ['gbrain', 'sync', '--source', o.source_id, '--no-pull'], consent: [], actor: 'agent', requires_exclusive: false,
- why: 'Syncs the checkout HEAD now; the recorded marker clears once last_commit reaches it.' } });
- console.log(JSON.stringify({ ...o, error: error.toJSON() }));
- } else printTriggerOutcome(o, false);
- const { setCliExitVerdict } = await import('../../core/cli-force-exit.ts');
- setCliExitVerdict(3);
+ const { readNotifierBlock } = await import('../../core/notifier/status.ts');
+ const live = (await readNotifierBlock(engine, marker.source_id).catch(() => null))?.resident ?? null;
+ printTriggerOutcome({ action: job.coalesced ? 'coalesced' : 'queued', ...base, job_id: job.id, resident: live ? { kind: live.kind, pid: live.pid } : null }, json);
}
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 009f1c0713..220cd43fec 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -962,8 +962,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.311.0', text: 'The dream `consolidate` phase no longer promotes a cluster in which two typed facts state the same metric, unit and period for the same effective time (an original amount and its correction recorded on one day, or the same statement twice). It used to keep the higher-confidence one as the take and close the other at its own instant, a zero-length validity that silently marked a real fact superseded. Such a cluster is now left unchanged: the phase reports `warn` with `details.clusters_held_same_instant` and `details.same_instant_clusters`, each with the fact ids and a next step (ask which statement is current, then `gbrain forget` the other). Facts an earlier run closed this way are listed by `gbrain repair consolidate-ties`, which reopens exactly the previewed ones on `--apply --expect <hash>`; nothing changes on upgrade.' },
// GBRA-133 PR 2a (commit triggers that never drop a commit). `since` is restamped at the merge slot.
{ since: '0.60.309.0', text: 'With `sync.on_commit` on, the commit watcher now runs in every resident (gbrain serve, serve --http, gbrain jobs work and the autopilot daemon; one owns it per host), watches classic sources last synced on this host as well as managed ones, starts a sync as soon as a quiet HEAD moves (the fixed 3 s debounce is now a 400 ms trailing window, `GBRAIN_NOTIFIER_QUIET_MS`), and keeps a source due across failed or refused starts with retries at 5 s, 15 s, 1 min and 5 min (`notifier_stalled` after that). `GBRAIN_NOTIFIER=0` turns it off per process; `sync.on_commit.sources` excludes sources.' },
- { since: '0.60.309.0', text: 'A sync request is now recorded before it runs and is never dropped: `gbrain sync trigger` answers queued, coalesced, nudged or no_resident (exit 3, with `--json`), a second GitHub push while the first job waits joins it instead of being ignored for 30 s, and requests are drained by residents even with `sync.on_commit` off. A push for a managed source answers 409 `refresh_required` with the `gbrain sources refresh` fix instead of queueing a sync that cannot import it.' },
- { since: '0.60.309.0', text: 'Search and query responses carry a `freshness` entry per source (current, behind, syncing, unknown or not_monitored, the observed HEAD and time, the detection mode and the held-file count), read from the notifier\'s record without a git call.' },
+ { since: '0.60.309.0', text: 'A sync request is now recorded before it runs and is never dropped: `gbrain sync trigger` answers queued, coalesced or nudged (with `--json`; still `job_id=N` on stdout when a job is queued, exit 0) and adds the notice `no_resident` with the fix when nothing watches the source, a second GitHub push while the first job waits joins it instead of being ignored for 30 s, and requests are drained by residents even with `sync.on_commit` off. A push for a managed source answers 409 `refresh_required` with the `gbrain sources refresh` fix instead of queueing a sync that cannot import it.' },
+ { since: '0.60.309.0', text: 'Search and query responses carry a `freshness` entry per source (current, behind, syncing, unknown or not_monitored, the observed HEAD and time, the detection mode and the held-file count), read from the notifier\'s record without a git call, once `sync.on_commit` is on or a resident has observed a source (otherwise search output is unchanged).' },
{ since: '0.60.309.0', text: 'The autopilot daemon dispatches a freshness sync when a checkout\'s HEAD differs from the commit its source last synced, at the next tick instead of after the 5-minute wall-clock interval (which stays as the backstop), once per HEAD and never in the middle of a rebase or merge; classic and managed sources alike. With `sync.on_commit` on, the daemon also reads every checkout\'s HEAD between ticks (every 3 s, git only; `GBRAIN_AUTOPILOT_HEAD_PROBE_MS`) and queues the sync within seconds.' },
{ since: '0.60.309.0', text: 'On Postgres, `gbrain jobs work` starts a persistence consumer at boot (#7002), so queued persistence effects drain after a `serve` stops even while the worker is idle. It joins the existing election: with `persistence.single_consumer` on it waits beside a live owner and takes over when that owner stops; with the switch off (the default) a worker beside a `serve` runs its own full consumer, as every resident process already does, and doctor `two_consumers_on_host` lists it. A queued sync job now wakes an idle worker at once: LISTEN on a direct session (one extra connection), a 1 s sync-queue read behind a transaction pooler; `GBRAIN_WORKER_SYNC_WAKE=0` turns it off.' },
{ since: '0.60.309.0', text: '`gbrain autopilot --status` grades a running daemon from its own schedule (#7003): the daemon writes `autopilot.heartbeat.json` beside its lock with its next tick, so a healthy daemon on a long adaptive sleep no longer reads `stale` (exit 1); a missing or outdated sidecar falls back to the interval-flag rule. `--status --json` adds `stale_after_source` (`daemon` or `flag`) and `next_tick_at`.' },
diff --git a/src/core/error-registry.ts b/src/core/error-registry.ts
index 2ae4496e4d..18d5b23e79 100644
--- a/src/core/error-registry.ts
+++ b/src/core/error-registry.ts
@@ -288,7 +288,6 @@ export const CODES = {
full_resync_required: { class: 'retryable', summary: "The catalog cursor is invalid or expired." },
gate_failed: { class: 'caller', summary: "The eval gate found retrieval regressions or correctness below its thresholds." },
ghost_mass_delete_refused: { class: 'consent', summary: "gbrain repair ghost-pages refused to soft-delete more than half of a source's file-backed pages; nothing was changed.", why: "The sync mass-delete valve (#2828) applied to ghost pages: that many missing canonical files almost always means the checkout is the wrong path, unmounted or half-cloned, not that the files were deleted.", docs: 'docs/guides/repair.md#ghost-pages', suggestion: 'Check the source checkout on its owner host first. If removing these pages is genuinely intended, ask the user, then rerun the same apply command with GBRAIN_ALLOW_MASS_RECONCILE=1.', fix: { argv: ['gbrain', 'sources', 'writer', 'status', '--source', '{source_id}', '--json'], consent: [], actor: 'agent', why: "Read-only: shows the source's canonical root and owner host, to check the checkout before anything is removed.", requires_exclusive: false } },
- no_resident: { class: 'unavailable', actor: 'agent', exit: 3, summary: "A sync request (gbrain sync trigger) was recorded as a wanted marker, but no resident process (gbrain serve, gbrain jobs work or the autopilot daemon) runs on this brain to sync it.", why: "On PGLite only the process that holds the database can sync, and none does; the marker is kept, so the next resident or sync drains it and nothing is lost.", docs: 'docs/guides/on-commit-sync.md#no-resident', suggestion: 'Run gbrain sync --source <id> --no-pull now, or start gbrain serve (no service is installed for you); the recorded request is drained by the next resident.' },
notifier_stalled: { class: 'retryable', actor: 'agent', summary: "The commit notifier kept a source due through every retry tier (5 s, 15 s, 1 min, 5 min) without the sync making progress; it keeps retrying every 5 minutes.", why: "A commit-triggered sync failed or was refused the same way on every attempt, so the commit is still not searchable; the notifier block in gbrain sync status names the last error and the trace file with every attempt.", docs: 'docs/guides/on-commit-sync.md#notifier-stalled', suggestion: 'Run gbrain sync --source <id> --no-pull in the foreground to see the error, fix its cause, then read gbrain sync status --source <id> --json (the notifier block) to confirm the source is current.' },
origin_twin_mass_merge_refused: { class: 'consent', summary: "gbrain repair origin-twins refused to merge duplicate-origin twins amounting to more than half of a source's file-backed pages; nothing was changed.", why: "The sync mass-delete valve (#2828) applied to origin twins (#6948): that many twins at once almost always means a re-import under other slugs or the wrong checkout, not a backlog.", docs: 'docs/guides/repair.md#origin-twins', suggestion: 'Check the source and its checkout first. If merging these pages is genuinely intended, ask the user, then rerun the same apply command with GBRAIN_ALLOW_MASS_RECONCILE=1.' },
ghost_storage_unknown: { class: 'unavailable', summary: "Ghost pages of a source cannot be classified because its canonical checkout cannot be read reliably; nothing was listed or changed.", why: "A page is never reported or removed as a ghost while its file may only be unreadable: a missing or non-directory root (storage_unavailable), or a stat error, an invalid gbrain.yml or an inconclusive page check (ambiguous_storage), fails closed.", reasons: ['storage_unavailable', 'ambiguous_storage'], docs: 'docs/guides/repair.md#ghost-pages', suggestion: 'Inspect the source checkout on its owner host (writer status shows its root), fix it, then preview gbrain repair ghost-pages --source <id> again.', fix: { argv: ['gbrain', 'sources', 'writer', 'status', '--source', '{source_id}', '--json'], consent: [], actor: 'agent', why: "Read-only: shows the source's canonical root and owner host.", requires_exclusive: false } },
@@ -765,6 +764,7 @@ export const NOTICE_CODES = {
migrations_pending: { kind: 'safety', summary: 'Schema migrations are pending or failed to apply on this brain.' },
sync_retry_failed_deprecated: { kind: 'coaching', summary: '`gbrain sync --retry-failed` is a deprecated alias for a plain sync, accepted for two releases: a plain sync retries a failure the previous run recorded by itself. Drop the flag.' },
sync_tail_degraded: { kind: 'degraded', summary: 'A managed sync ended synced, but its post-checkpoint tail (planner statistics, link extraction for the imported pages) failed, was cut off at its budget or did not start before the run\'s deadline; the step stays scheduled for the next sync, and the fix runs it now (`gbrain extract --stale --source-id <id>`, or doctor for the statistics).' },
+ no_resident: { kind: 'degraded', summary: 'gbrain sync trigger recorded the request (and queued a job or nudged the serve), but no resident (gbrain serve, gbrain jobs work or the autopilot daemon) watches the source, so the recorded request waits until one starts or a sync reaches it; the fix syncs the checkout HEAD now (`gbrain sync --source <id> --no-pull`). docs/guides/on-commit-sync.md#no-resident' },
no_worker: { kind: 'degraded', summary: 'A job was queued but no worker is running to execute it; it waits until a worker runs.' },
config_write_shadowed: { kind: 'degraded', summary: '`gbrain config set chat_model|expansion_model` stored the value in the database, but a models.* config key, an environment variable (GBRAIN_MODEL, GBRAIN_CHAT_MODEL, GBRAIN_EXPANSION_MODEL) or the config.json pin outranks it, so the model in use does not change; `shadowed_by` names it (never its value) and the fix clears it (`gbrain config unset <models key>`, `gbrain config unset <key> --file`, or the user unsets the variable).' },
unknown_param: { kind: 'info', summary: 'The call passed a parameter the tool does not declare; it was ignored.' },
diff --git a/test/pathological/s-notifier-marker-handoff.test.ts b/test/pathological/s-notifier-marker-handoff.test.ts
index 7b8d97c3da..89ecfb8136 100644
--- a/test/pathological/s-notifier-marker-handoff.test.ts
+++ b/test/pathological/s-notifier-marker-handoff.test.ts
@@ -12,7 +12,8 @@
* - a dry run stays read-only (no marker read, cleared or written);
* - the push webhook coalesces a second push into the waiting job and keeps the newer sha; a managed push answers
* refresh_required (409) with the gbrain sources refresh fix and queues nothing;
- * - sync trigger --json reports queued / coalesced (Postgres) and no_resident with exit 3 (PGLite, no serve).
+ * - sync trigger --json reports queued then coalesced on either engine (stdout keeps job_id=N, exit 0), and with no
+ * resident watching the source adds resident: null and the no_resident notice with its fix.
* Real git, real store, real handler, real delegated runner. PGLite always, Postgres when DATABASE_URL is set.
*/
import { describe, expect, test } from 'bun:test';
@@ -182,20 +183,17 @@ for (const { backend, databaseUrl } of pathologicalArms()) {
});
}, 120_000);
- test('sync trigger --json: queued then coalesced on Postgres; no_resident with exit 3 on PGLite without a serve', async () => {
+ test('sync trigger --json: queued then coalesced, exit 0; with no resident it adds resident: null and the no_resident notice', async () => {
await classicBrain(databaseUrl, async ({ engine }) => {
_resetCliExitVerdictForTests();
try {
const one = await quietly(() => runSyncTrigger(engine, ['--source', SOURCE, '--json']));
+ expect(one.out).toHaveLength(1);
const a = JSON.parse(one.out.at(-1)!);
- if (engine.kind === 'pglite') {
- expect(a).toMatchObject({ action: 'no_resident', source_id: SOURCE, intent: 'pull' });
- expect(a.error.fix).toBeDefined();
- expect(JSON.stringify(a.error)).toContain('--no-pull');
- expect(currentExitCode()).toBe(3);
- expect((await readMarkers(engine, [SOURCE])).map(m => m.intent)).toEqual(['pull']);
- return;
- }
+ expect(a.resident).toBeNull();
+ expect(a.notice).toMatchObject({ code: 'no_resident' });
+ expect(JSON.stringify(a.notice)).toContain('--no-pull');
+ expect((await readMarkers(engine, [SOURCE])).map(m => [m.intent, m.job_id])).toEqual([['pull', a.job_id]]);
const two = await quietly(() => runSyncTrigger(engine, ['--source', SOURCE, '--json']));
const b = JSON.parse(two.out.at(-1)!);
expect(a).toMatchObject({ action: 'queued', source_id: SOURCE, intent: 'pull' });
@@ -203,7 +201,8 @@ for (const { backend, databaseUrl } of pathologicalArms()) {
expect(b).toMatchObject({ action: 'coalesced', job_id: a.job_id, marker_generation: a.marker_generation + 1 });
expect(currentExitCode()).toBe(0);
const text = await quietly(() => runSyncTrigger(engine, ['--source', SOURCE]));
- expect(text.out).toContain(`job_id=${a.job_id}`);
+ expect(text.out).toEqual([`job_id=${a.job_id}`]);
+ expect(text.err.filter(l => l.startsWith('[gbrain notice no_resident]'))).toHaveLength(1);
} finally { _resetCliExitVerdictForTests(); }
});
}, 120_000);