Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Reconcile review fixes: bind the publish to the checked upstream, publish only checkouts gbrain cloned, run in the daemon on every engine, skip sync-off and missing sources
garrytan5f68d4cc4ad6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fce4bbe2c4..78479e750d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,14 +12,14 @@ identifiers and attribution are available in the pre-removal Git revision## [Unreleased]-**Every source checkout now converges on its remote by itself: `gbrain sources git-reconcile`, run by autopilot each tick.** One idempotent call brings every source checkout on the host level with its upstream. A checkout that is only behind fast-forwards; one with local commits publishes them merged with the upstream in memory (the same secret scan and rewritten-upstream refusal as refresh, never a rebase or force-push); a managed checkout goes through `gbrain sources refresh` and its Git durability rule. A level checkout costs one fetch and reports `in_sync`, and callers on the same checkout take turns, so any agent, cron or hook can call it as often and as concurrently as it likes. Autopilot runs it each tick in a bounded child process, so a slow push never stalls the daemon; `autopilot.git_pull false` skips it, and `sources.refresh_publish_diverged false` leaves local commits `unpublished` while checkouts behind still fast-forward. Exit 0 means level, 1 that a checkout needs the user, 4 that a retry can fix it.+**Every source checkout now converges on its remote by itself: `gbrain sources git-reconcile`, run by autopilot each tick.** One idempotent call brings every source checkout on the host level with its upstream. A checkout that is only behind fast-forwards. A checkout gbrain cloned for the source (a recorded remote URL, the source folder at the repository root) publishes its local commits merged with the upstream in memory: the same secret scan and rewritten-upstream refusal as refresh, bound to the upstream it checked so a force-push in between refuses, never a rebase or force-push. Any other checkout, such as a source folder inside a repository gbrain did not clone, reports its local commits `unpublished` unless `sources.refresh_publish_diverged` is `true`. A managed checkout goes through `gbrain sources refresh` and its Git durability rule. Sources with sync turned off are skipped unless named. A level checkout costs one fetch and reports `in_sync`, and callers on the same checkout take turns, so any agent, cron or hook can call it as often and as concurrently as it likes. Autopilot runs it each tick on every engine, its pulls and publishes in bounded child processes, so a slow push never stalls the daemon; `autopilot.git_pull false` skips it, and `sources.refresh_publish_diverged false` leaves local commits `unpublished` while checkouts behind still fast-forward. Exit 0 means level, 1 that a checkout needs the user, 4 that a retry can fix it.-- `src/core/git/reconcile.ts` (new): one checkout under its own reconcile lock (outermost; no other path takes it, so it cannot deadlock a publish); fetch with the tracking ref's move logged, then fast-forward, publish with `scanSecrets`, or refuse `upstream_rewritten`; a fetch that loses the tracking-ref race to a concurrent fetch retries.+- `src/core/git/reconcile.ts` (new): one checkout under its own reconcile lock (outermost; no other path takes it, so it cannot deadlock a publish); fetch with the tracking ref's move logged, then a `gbrain git commit-push --pull` child, a `--push-only --scan-secrets --expect-remote <checked upstream>` child (a remote that moved in between is fetched and checked for a rewrite again), or `upstream_rewritten`; a fetch that loses the tracking-ref race to a concurrent fetch retries.- `src/core/git/upstream-history.ts` (new): the rewritten-upstream check, moved out of `src/core/persistence/worktree-refresh.ts` so refresh and reconcile share it.- `src/commands/sources-git-reconcile.ts` (new), `src/commands/sources.ts`: the command, grouping sources by checkout; a managed checkout waits out a running refresh up to `--wait`.-- `src/commands/autopilot-git-reconcile.ts` (new), `src/commands/autopilot-daemon.ts`: the per-tick child, bounded at 15 minutes and logged.+- `src/commands/autopilot-git-reconcile.ts` (new), `src/commands/autopilot-daemon.ts`: the per-tick reconcile in the daemon, logged.- Docs and skills: `docs/guides/live-sync.md`, `docs/guides/shared-checkout-git.md`, `docs/guides/cron-schedule.md` (allow minutes for fetch and push calls), `skills/cron-scheduler/SKILL.md` (the managed cron line runs `sources git-reconcile`).-- Tests: `test/sources-git-reconcile.test.ts` (level, stranded, behind, diverged, conflict, secret, rewritten upstream, eight concurrent callers while another clone pushes, managed with durability on and off, no checkout, publishing off), `test/autopilot-git-reconcile.test.ts` (the daemon's event loop keeps ticking during the child; a refusal is reported; a hung child is killed).+- Tests: `test/sources-git-reconcile.test.ts` (level, stranded, behind, diverged, conflict, secret, rewritten upstream, a force-push between the check and the push, eight concurrent callers while another clone pushes, managed with durability on and off and publishing off, no checkout, publishing off, a checkout gbrain did not clone, sync off, a missing folder), `test/autopilot-git-reconcile.test.ts` (the daemon's event loop keeps ticking during a publish child; a refusal is reported with no value printed; a hung child is killed).**A diverged managed checkout now publishes its local commits on refresh by default when Git durability is on, after a secret scan of those commits.** Commits a script made with plain `git commit` in a managed checkout used to strand there whenever the remote moved: every `gbrain sources refresh` refused `refresh_diverged` and asked the user, unless `sources.refresh_publish_diverged` was set to `true`. With the setting unset, a worktree whose Git durability is on (`gbrain sources writer git-durability <source> --enable`, or the legacy hook) now publishes them itself: the local commits merged with the upstream in memory, never a rebase or force-push, then the fast-forward. The publish child scans, under its publish lock and for the exact commits it pushes, what they add: commit messages, added lines (including a value a later commit removed) and merge-commit conflict resolutions. A value that looks like a secret, or added text too large to scan, refuses the new `publish_secret_found` naming the file, line, rule and commit, never the value, with nothing pushed. The rewritten-upstream refusal and the `--expect-remote` bound are unchanged. `false` turns it off; `true` still publishes with durability off.diff --git a/docs/guides/live-sync.md b/docs/guides/live-sync.mdindex 96144b7f06..ff6a4ce497 100644--- a/docs/guides/live-sync.md+++ b/docs/guides/live-sync.md@@ -699,17 +699,22 @@ vars — incident-time escape hatches, not everyday knobs.of) still refuses `refresh_diverged`, and `--dry-run` never publishes.`gbrain sources git-reconcile` does this for every source checkout on the- host at once: a managed checkout goes through the refresh above, any other- checkout with an upstream publishes its local commits the same way (secret- scan, rewrite check, merge in memory) and fast-forwards when it is only- behind. A level checkout costs one fetch and reports `in_sync`, so any agent,+ host at once: a managed checkout goes through the refresh above; a checkout+ gbrain cloned for the source (a recorded remote URL, the source folder at the+ repository root) publishes its local commits the same way (secret scan,+ rewrite check, merge in memory, bound to the upstream it checked so a+ force-push in between refuses) and fast-forwards when it is only behind. Any+ other checkout, such as a source folder inside a repository gbrain did not+ clone, only fast-forwards and reports its local commits `unpublished` unless+ `sources.refresh_publish_diverged` is `true`; `false` leaves every checkout's+ local commits `unpublished`. A source with sync turned off is skipped unless+ named. A level checkout costs one fetch and reports `in_sync`, so any agent,cron or hook can call it as often and as concurrently as it likes; callerson one checkout take turns and end with the same upstream. Autopilot runs it- each tick in a bounded child process (`autopilot.git_pull false` skips it),- and `sources.refresh_publish_diverged false` leaves local commits- `unpublished` while checkouts behind still fast-forward. Exit 0 means every- checkout is level, 1 that one needs the user (the result names the refusal),- 4 that a retry can fix it.+ each tick, its pulls and publishes in bounded child processes+ (`autopilot.git_pull false` skips it). Exit 0 means every checkout is level+ or left unpublished, 1 that one needs the user (the result names the+ refusal), 4 that a retry can fix it.**Say to your agent:** *"Bring my notes source up to date with its remote."*diff --git a/llms-full.txt b/llms-full.txtindex 4e2a24e307..5a19fbaca2 100644--- a/llms-full.txt+++ b/llms-full.txt@@ -7704,17 +7704,22 @@ vars — incident-time escape hatches, not everyday knobs.of) still refuses `refresh_diverged`, and `--dry-run` never publishes.`gbrain sources git-reconcile` does this for every source checkout on the- host at once: a managed checkout goes through the refresh above, any other- checkout with an upstream publishes its local commits the same way (secret- scan, rewrite check, merge in memory) and fast-forwards when it is only- behind. A level checkout costs one fetch and reports `in_sync`, so any agent,+ host at once: a managed checkout goes through the refresh above; a checkout+ gbrain cloned for the source (a recorded remote URL, the source folder at the+ repository root) publishes its local commits the same way (secret scan,+ rewrite check, merge in memory, bound to the upstream it checked so a+ force-push in between refuses) and fast-forwards when it is only behind. Any+ other checkout, such as a source folder inside a repository gbrain did not+ clone, only fast-forwards and reports its local commits `unpublished` unless+ `sources.refresh_publish_diverged` is `true`; `false` leaves every checkout's+ local commits `unpublished`. A source with sync turned off is skipped unless+ named. A level checkout costs one fetch and reports `in_sync`, so any agent,cron or hook can call it as often and as concurrently as it likes; callerson one checkout take turns and end with the same upstream. Autopilot runs it- each tick in a bounded child process (`autopilot.git_pull false` skips it),- and `sources.refresh_publish_diverged false` leaves local commits- `unpublished` while checkouts behind still fast-forward. Exit 0 means every- checkout is level, 1 that one needs the user (the result names the refusal),- 4 that a retry can fix it.+ each tick, its pulls and publishes in bounded child processes+ (`autopilot.git_pull false` skips it). Exit 0 means every checkout is level+ or left unpublished, 1 that one needs the user (the result names the+ refusal), 4 that a retry can fix it.**Say to your agent:** *"Bring my notes source up to date with its remote."*diff --git a/scripts/core-world-reads-baseline.tsv b/scripts/core-world-reads-baseline.tsvindex e294e2edc3..44aa65b7e0 100644--- a/scripts/core-world-reads-baseline.tsv+++ b/scripts/core-world-reads-baseline.tsv@@ -444,6 +444,7 @@ src/core/git/commit-push.ts fs_import 1 W7: filesystem boundary moves to the locsrc/core/git/commit-push.ts module_collection 1 W6: per-engine state, or mark as a constant tablesrc/core/git/commit-push.ts process_env 7 W6: settings plane out of the coresrc/core/git/commit-push.ts spawn_import 1 W7: process-wide effects move to src/cli+src/core/git/reconcile.ts process_env 2 W6: settings plane out of the core; the commit-push child inherits this process environment (GBRAIN_HOME, Git credentials) and resolves its CLI from it, like refresh's publish childsrc/core/git/upstream-history.ts fs_import 1 W7: filesystem boundary moves to the local app; reads the tail of the checkout reflog to tell a rewritten upstream from a fast-forward (lifted out of worktree-refresh.ts)src/core/github-app-token.ts fs_import 1 W7: filesystem boundary moves to the local appsrc/core/github-source.ts fs_import 2 W7: filesystem boundary moves to the local appdiff --git a/src/commands/autopilot-daemon.ts b/src/commands/autopilot-daemon.tsindex 8cecf77a20..5751974c0f 100644--- a/src/commands/autopilot-daemon.ts+++ b/src/commands/autopilot-daemon.ts@@ -331,7 +331,7 @@ export async function runAutopilotDaemon(engine: BrainEngine, args: string[]): Pif (noWorker && useMinionsDispatch) await probeNoWorkerPeer(engine, state, baseInterval);if (!(await (await import('../core/persistence/automatic-sync-policy.ts')).automaticGitPullDisabled(engine))) {- const reconciled = await (await import('./autopilot-git-reconcile.ts')).reconcileGitInChild();+ const reconciled = await (await import('./autopilot-git-reconcile.ts')).autopilotReconcile(engine);for (const line of reconciled.lines) (reconciled.ok ? console.log : console.error)(`[autopilot] git-reconcile: ${line}`);if (configurationBlocked()) continue;}diff --git a/src/commands/autopilot-git-reconcile.ts b/src/commands/autopilot-git-reconcile.tsindex b76bd6425a..01fc74c379 100644--- a/src/commands/autopilot-git-reconcile.ts+++ b/src/commands/autopilot-git-reconcile.ts@@ -1,27 +1,22 @@/**- * Autopilot's reconcile: each daemon tick runs `gbrain sources git-reconcile --json` in a bounded child, so every source- * checkout on this host converges on its upstream without anyone calling it. The publish inside is synchronous (fetches,- * pushes and lock waits block for minutes); in a child it never stalls the daemon's event loop, its lease renewals or its- * heartbeat. A failure is logged and the tick goes on: the next tick retries, and a refusal that needs the user (a- * conflict, a secret, a rewritten upstream) is reported the same way `gbrain sources git-reconcile` reports it.+ * Autopilot's reconcile: each daemon tick runs `gbrain sources git-reconcile` over the sources whose sync is on, in this+ * process, so it works on every engine (a PGLite daemon holds the data directory, and a child could not open it). It+ * never blocks the daemon's event loop, its lease renewals or its heartbeat: Git reads and fetches are bounded async+ * children, and every pull and publish (synchronous Git work) runs in a bounded `gbrain git commit-push` child, a managed+ * checkout's through `gbrain sources refresh`. A failure is logged and the tick goes on; the next tick retries.*/-import { execFileBounded } from '../core/bounded-child-exec.ts';-import { CHILD_ENV, resolveChildCliInvocation } from '../core/minions/job-isolation.ts';+import type { BrainEngine } from '../core/engine.ts';+import { reconcileSources } from './sources-git-reconcile.ts';-export const AUTOPILOT_RECONCILE_TIMEOUT_MS = 900_000;+export interface AutopilotReconcileOutcome { ok: boolean; lines: string[] }-export interface AutopilotReconcileOutcome { ok: boolean; exit: number | null; lines: string[] }--export async function reconcileGitInChild(timeoutMs = AUTOPILOT_RECONCILE_TIMEOUT_MS): Promise<AutopilotReconcileOutcome> {- const cli = resolveChildCliInvocation(process.env, process.execPath, process.argv[1], () => null);- if (!cli) return { ok: false, exit: null, lines: [`could not locate the gbrain CLI to reconcile Git checkouts; set ${CHILD_ENV.childCliOverride} to its path`] };- const child = await execFileBounded(cli.cmd, [...cli.argsPrefix, 'sources', 'git-reconcile', '--json', '--wait', '60'],- { timeout: timeoutMs, termGraceMs: 10_000, maxBuffer: 4 * 1024 * 1024, env: process.env });- const exit = child.error ? (typeof child.error.code === 'number' ? child.error.code : null) : 0;- let doc: { results?: Array<{ sources?: string[]; root?: string; status?: string; error?: { code?: string; message?: string } }> } | null = null;- try { doc = JSON.parse(String(child.stdout).trim()); } catch { /* reported below */ }- if (!doc?.results) return { ok: false, exit, lines: [`sources git-reconcile ${exit === null ? 'did not finish' : `exited ${exit}`}: ${String(child.stderr).trim().slice(0, 300) || 'no output'}`] };- const lines = doc.results.filter(r => r.status !== 'in_sync' && r.status !== 'no_repo' && r.status !== 'no_upstream')- .map(r => `${(r.sources ?? []).join(', ') || r.root}: ${r.status}${r.error ? ` ${r.error.code}: ${r.error.message}` : ''}`);- return { ok: exit === 0, exit, lines };+export async function autopilotReconcile(engine: BrainEngine, opts: { childTimeoutMs?: number } = {}): Promise<AutopilotReconcileOutcome> {+ try {+ const results = await reconcileSources(engine, { waitMs: 0, ...(opts.childTimeoutMs ? { childTimeoutMs: opts.childTimeoutMs } : {}) });+ const lines = results.filter(r => r.status !== 'in_sync' && r.status !== 'no_repo' && r.status !== 'no_upstream')+ .map(r => `${r.sources.join(', ') || r.root}: ${r.status}${r.error ? ` ${r.error.code}: ${r.error.message}` : r.reason ? ` (${r.reason})` : ''}`);+ return { ok: !results.some(r => r.status === 'needs_user' || r.status === 'failed'), lines };+ } catch (error) {+ return { ok: false, lines: [`sources git-reconcile failed: ${error instanceof Error ? error.message : String(error)}`] };+ }}diff --git a/src/commands/sources-git-reconcile.ts b/src/commands/sources-git-reconcile.tsindex 5bf4b88a0d..a0b356517a 100644--- a/src/commands/sources-git-reconcile.ts+++ b/src/commands/sources-git-reconcile.ts@@ -14,7 +14,11 @@ import type { BrainEngine } from '../core/engine.ts';import { setCliExitVerdict } from '../core/cli-force-exit.ts';import { reconcileCheckout, fetchLevel, gitReader, withReconcileLock, type CheckoutReconcileStatus } from '../core/git/reconcile.ts';import { isTruthy } from '../core/connectors/config-keys.ts';+import { existsSync, realpathSync } from 'node:fs';import { classifyGitCheckout } from '../core/git-checkout.ts';+import { gitTopLevel } from '../core/persistence/git-gap.ts';+import { sourceConfigHasRemoteUrl } from '../core/sources-load.ts';+import { isSyncDisabledConfig } from '../core/sync-policy.ts';import { OperationError } from '../core/ops/contract.ts';import { existingHostIdFor } from '../core/persistence/identity.ts';import { getWorktreeBinding, managedPersistenceEnabled } from '../core/persistence/ownership.ts';@@ -32,12 +36,13 @@ export interface SourceReconcile {error?: { code: string; message: string; suggestion?: string; fix?: unknown };}-export interface ReconcileOptions { sourceIds?: string[]; dryRun?: boolean; waitMs?: number; sleep?: (ms: number) => Promise<void> }+export interface ReconcileOptions { sourceIds?: string[]; dryRun?: boolean; waitMs?: number; sleep?: (ms: number) => Promise<void>; childTimeoutMs?: number }-async function reconcileManaged(engine: BrainEngine, sourceId: string, root: string, opts: ReconcileOptions): Promise<Omit<SourceReconcile, 'sources' | 'root' | 'managed'>> {+async function reconcileManaged(engine: BrainEngine, sourceId: string, root: string, publish: boolean, opts: ReconcileOptions): Promise<Omit<SourceReconcile, 'sources' | 'root' | 'managed'>> {const level = await fetchLevel(root, gitReader(root));if (!level) return { status: 'no_upstream', ahead: 0, behind: 0 };if (!level.ahead && !level.behind) return { status: 'in_sync', ahead: 0, behind: 0, sha: level.target };+ if (level.ahead && !publish) return { status: 'unpublished', ahead: level.ahead, behind: level.behind, sha: level.target, reason: `automatic publishing is off (${REFRESH_PUBLISH_DIVERGED_KEY} false)` };if (opts.dryRun) return { status: level.ahead ? 'published' : 'fast_forwarded', ahead: level.ahead, behind: level.behind, sha: level.target, reason: 'dry run: nothing changed' };const sleep = opts.sleep ?? ((ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms)));const deadline = Date.now() + (opts.waitMs ?? 300_000);@@ -56,33 +61,42 @@ async function reconcileManaged(engine: BrainEngine, sourceId: string, root: str}export async function reconcileSources(engine: BrainEngine, opts: ReconcileOptions = {}): Promise<SourceReconcile[]> {- const listed = (await listSources(engine)).filter(s => s.local_path && (!opts.sourceIds?.length || opts.sourceIds.includes(s.id)));+ const explicit = !!opts.sourceIds?.length;+ const listed = (await listSources(engine)).filter(s => s.local_path && (!explicit || opts.sourceIds!.includes(s.id)));const unknown = (opts.sourceIds ?? []).filter(id => !listed.some(s => s.id === id));if (unknown.length) throw new OperationError('unknown_source', `No source with a local checkout named ${unknown.join(', ')}.`, 'gbrain sources list shows each source and its local path.');+ const configs = new Map((await engine.executeRaw<{ id: string; config: unknown }>('SELECT id, config FROM sources')).map(row => [row.id, row.config]));const managed = await managedPersistenceEnabled(engine);const configured = (await engine.getConfig(REFRESH_PUBLISH_DIVERGED_KEY))?.trim();- const publish = !configured || isTruthy(configured);- const groups = new Map<string, { sources: string[]; root: string; managed: boolean }>();+ const publishSetting = configured ? isTruthy(configured) : null;+ const groups = new Map<string, { sources: string[]; root: string; managed: boolean; cloned: boolean }>();for (const source of listed) {+ if (!explicit && isSyncDisabledConfig(configs.get(source.id))) continue;const binding = managed ? await getWorktreeBinding(engine, source.id, existingHostIdFor(engine)) : null;const root = binding?.local_path ?? source.local_path!;- if (classifyGitCheckout(root) === 'not_git') continue;+ if (!existsSync(root) || classifyGitCheckout(root) === 'not_git') continue;const key = binding ? `worktree:${binding.worktree_id}` : `path:${root}`;- const group = groups.get(key) ?? { sources: [], root, managed: !!binding };+ const cloned = sourceConfigHasRemoteUrl(configs.get(source.id)) && gitTopLevel(root) === realpathSync(root);+ const group = groups.get(key) ?? { sources: [], root, managed: !!binding, cloned };group.sources.push(source.id);+ group.cloned &&= cloned;groups.set(key, group);}if (!groups.size) return [{ sources: [], root: '', managed: false, status: 'no_repo', ahead: 0, behind: 0 }];const out: SourceReconcile[] = [];for (const group of groups.values()) {try {+ const { cloned, ...entry } = group;+ const publish = group.managed ? publishSetting !== false : publishSetting ?? cloned;const result = group.managed- ? await withReconcileLock(group.root, opts.waitMs ?? 300_000, () => reconcileManaged(engine, group.sources[0], group.root, opts))- : await reconcileCheckout(group.root, { dryRun: opts.dryRun, publish, ...(opts.waitMs !== undefined ? { waitMs: opts.waitMs } : {}) });- out.push({ ...group, ...result });+ ? await withReconcileLock(group.root, opts.waitMs ?? 300_000, () => reconcileManaged(engine, group.sources[0], group.root, publish, opts))+ : await reconcileCheckout(group.root, { dryRun: opts.dryRun, publish, ...(opts.waitMs !== undefined ? { waitMs: opts.waitMs } : {}), ...(opts.childTimeoutMs ? { childTimeoutMs: opts.childTimeoutMs } : {}),+ ...(publishSetting === null && !cloned ? { unpublishedReason: `gbrain did not clone this checkout for the source (no recorded remote, or the source folder is not the repository root); publish it with gbrain git commit-push --push-only --scan-secrets --path ${group.root}, or set ${REFRESH_PUBLISH_DIVERGED_KEY} true to publish such checkouts automatically` } : {}) });+ out.push({ ...entry, ...result });} catch (error) {if (!(error instanceof OperationError)) throw error;- out.push({ ...group, status: RETRYABLE.has(error.code) ? 'failed' : 'needs_user', ahead: 0, behind: 0,+ const { cloned: _cloned, ...entry } = group;+ out.push({ ...entry, status: RETRYABLE.has(error.code) ? 'failed' : 'needs_user', ahead: 0, behind: 0,error: { code: error.code, message: error.message, ...(error.suggestion ? { suggestion: error.suggestion } : {}), ...(error.fix ? { fix: error.fix } : {}) } });}}diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 8fefceee88..c64c89f30d 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1486,7 +1486,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.614.0', id: 'refresh_barrier_aborted_refresh_sync_gst1853', text: 'While a checkout\'s last `gbrain sources refresh` ended without completing (aborted, abandoned, or rolled back after its process died), every refresh run on the owner host, including one refused `refresh_diverged`, now ends by running the managed `--no-pull` sync of each source behind the checkout HEAD, listed in its `synced` (a refusal\'s message names them). With `persistence.refresh_barrier` on, a write held behind that refresh for a commit sync had not imported is therefore decided in that run instead of waiting for a later refresh: a `put_page` with `expected_revision` ends `revision_conflict`, a blind one lands and names what it replaced in `supersedes`, and a `remember` or `add_timeline_entry` applies on top.' },{ since: '0.60.608.0', id: 'refresh_barrier_later_write_gst1623', text: 'With `persistence.refresh_barrier` on, a write that waited behind a refresh or an import (other than a `remember` or `add_timeline_entry`, which still applies on top) now ends `revision_conflict` instead of applying when a later write to the same page committed first, which a consumer from an older release can cause; read the page again and resubmit with a new `request_id`. A write held again and again behind imports now expires once it has waited four wait limits (at least 4 hours) since its admission, even when each hold is shorter than one wait limit. With the barrier on or off, a plain-git commit that lands on the start commit right before a refresh merges makes git refuse the fast-forward, and the refresh now ends `refresh_source_changed` with the fence lifted and the commit kept, instead of leaving the checkout `recovery_required`; one that lands right after the merge is recorded and synced.' },{ since: '0.60.616.0', id: 'refresh_publish_diverged_default_gbra386', text: 'A diverged managed checkout now publishes its local commits on `gbrain sources refresh` by default when the worktree\'s Git durability is on: `sources.refresh_publish_diverged` unset now means on there (it used to mean off), merged with the upstream in memory, never rebased or forced. Every automatic publish first scans what the local commits add (messages, added lines, merge resolutions) and refuses the new `publish_secret_found` naming the file, line and rule, never the value, when one looks like a secret; `gbrain git commit-push --push-only --scan-secrets` runs the same gate. Unset with durability not on still refuses, naming `gbrain sources writer git-durability <source> --enable`; `false` turns it off.' },- { since: '0.60.616.0', id: 'autopilot_git_reconcile_gbra386', text: 'Autopilot now runs the new `gbrain sources git-reconcile` each tick in a bounded child process: every source checkout on the host with an upstream publishes its local commits (secret scan, rewrite check, merged with the upstream in memory, never rebased or forced) and fast-forwards when it is only behind; a managed checkout goes through `gbrain sources refresh`, with its Git durability rule. A refusal is logged and retried next tick. `autopilot.git_pull false` skips it; `sources.refresh_publish_diverged false` leaves local commits unpublished.' },+ { since: '0.60.616.0', id: 'autopilot_git_reconcile_gbra386', text: 'Autopilot now runs the new `gbrain sources git-reconcile` each tick: every source checkout on the host with an upstream fast-forwards when it is only behind, and one gbrain cloned for the source publishes its local commits (secret scan, rewrite check bound to the push, merged with the upstream in memory, never rebased or forced); a managed checkout goes through `gbrain sources refresh`, with its Git durability rule. A checkout gbrain did not clone keeps its local commits unless `sources.refresh_publish_diverged` is `true`, and a source with sync off is skipped. A refusal is logged and retried next tick. `autopilot.git_pull false` skips it; `sources.refresh_publish_diverged false` leaves local commits unpublished.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/cli-flag-registry.generated.ts b/src/core/cli-flag-registry.generated.tsindex dddfd8bbf9..f0783292e6 100644--- a/src/core/cli-flag-registry.generated.ts+++ b/src/core/cli-flag-registry.generated.ts@@ -21,7 +21,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {'append': ['--brain', '--expect-tail', '--expected-revision', '--file', '--force', '--help', '--json', '--region', '--request-id', '--separator', '--source'],'apply-migrations': ['--accept-reviewed-inventory', '--acknowledge-no-backup', '--apply', '--apply-rewrites', '--backup-confirmed', '--brain', '--break-lock', '--confirm-quiesced', '--content-root', '--dry-run', '--export-db-only', '--export-source', '--force', '--force-all', '--force-orchestrator', '--force-retry', '--force-schema', '--help', '--host-dir', '--http', '--install', '--json', '--legacy-lock', '--list', '--locks', '--migrate-only', '--migration', '--mode', '--no-autopilot-install', '--non-interactive', '--only', '--path', '--prefer-postgres', '--probe', '--repo', '--require-db', '--skip-verify', '--source', '--statement-timeout', '--uninstall', '--url', '--yes'],'auth': ['--add', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--all', '--all-new', '--allowed-operations', '--apply', '--attest-actor', '--attest-ops', '--attest-sources', '--before', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--budget-usd-per-day', '--category', '--cleanup-dead-local-locks', '--client', '--code', '--confirm-quiesced', '--confirm-relocated-root', '--days', '--delegated-namespace', '--delegated-slug-prefixes', '--disable', '--dry-run', '--enable', '--enable-dcr-insecure', '--expect', '--expected-epoch', '--expected-state', '--federated-read', '--fix', '--force', '--grant-types', '--group-by', '--help', '--id', '--if-version', '--json', '--limit', '--manifest', '--max-concurrent', '--may-act-for', '--member', '--members', '--migrate-legacy', '--min-trust', '--no-pull', '--operation', '--operations', '--origin', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--private-pages', '--probe', '--profile', '--read-sources', '--redirect-uri', '--refresh-operations', '--repair', '--replace', '--request-id', '--reset-default', '--retire', '--scopes', '--self-transfer', '--shared-skills', '--since', '--slug-prefixes', '--source', '--source-ids', '--sources', '--state', '--surface', '--takes-holders', '--token', '--token-endpoint-auth-method', '--token-ttl', '--unsettle', '--usage', '--wait', '--warn-only', '--yes'],- 'autopilot': ['--apply', '--batch', '--brain', '--channel', '--check', '--dimensions', '--dir', '--drain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--exit-code', '--expect', '--explain', '--ff-only', '--force', '--force-retry', '--from-pages', '--help', '--inject-bootstrap', '--inline', '--install', '--interval', '--is-ancestor', '--json', '--markdown', '--max-cost', '--max-rss', '--max-runtime', '--max-usd', '--migrate-only', '--model', '--no-autopilot-install', '--no-bun-floor-check', '--no-embed', '--no-embed-cache', '--no-inject', '--no-restart', '--no-worker', '--non-interactive', '--now', '--once', '--only', '--output', '--params', '--pause', '--phase', '--quiet', '--reader-mode', '--reason', '--refresh-cache', '--refs', '--remediation-plan', '--repo', '--restart-only', '--resume', '--retry-global', '--slot-a-model', '--slot-b-model', '--slot-c-model', '--source', '--stale', '--status', '--stop-mcp', '--swap-only', '--tags', '--target', '--trust', '--uninstall', '--user', '--verify', '--version', '--wait', '--yes'],+ 'autopilot': ['--apply', '--batch', '--brain', '--channel', '--check', '--dimensions', '--dir', '--drain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--exit-code', '--expect', '--explain', '--ff-only', '--force', '--force-retry', '--from-pages', '--help', '--inject-bootstrap', '--inline', '--install', '--interval', '--is-ancestor', '--json', '--markdown', '--max-cost', '--max-rss', '--max-runtime', '--max-usd', '--migrate-only', '--model', '--no-autopilot-install', '--no-bun-floor-check', '--no-embed', '--no-embed-cache', '--no-inject', '--no-restart', '--no-worker', '--non-interactive', '--now', '--once', '--only', '--output', '--params', '--pause', '--phase', '--quiet', '--reader-mode', '--reason', '--refresh-cache', '--refs', '--remediation-plan', '--repo', '--restart-only', '--resume', '--retry-global', '--slot-a-model', '--slot-b-model', '--slot-c-model', '--source', '--stale', '--status', '--stop-mcp', '--swap-only', '--tags', '--target', '--trust', '--uninstall', '--user', '--verify', '--version', '--yes'],'backfill': ['--batch-size', '--brain', '--concurrency', '--dry-run', '--fresh', '--help', '--json', '--keep-index', '--list', '--max-errors', '--max-rows', '--resume', '--source'],'backup': ['--accept-pending', '--as', '--background', '--brain', '--confirm-authority-reviewed', '--confirm-backup-compatible', '--confirm-quiesced', '--dir', '--explain', '--follow', '--full', '--help', '--into', '--json', '--mode', '--no-accept-pending', '--output', '--path', '--progress-interval', '--progress-json', '--purge-mirror', '--quiet', '--restore-only', '--source', '--timeout', '--timings', '--wait'],'beliefs': ['--apply', '--archived-at', '--brain', '--from-url-env', '--help', '--json', '--probe', '--purge-mirror', '--since', '--source'],@@ -115,7 +115,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {'repair': ['--accept-pending', '--acknowledge-managed', '--after', '--all', '--all-drifted', '--apply', '--as', '--auto-additive', '--background', '--brain', '--break-lock', '--class', '--client', '--close', '--cursor', '--cwd', '--day', '--diff', '--expect', '--explain', '--ff-only', '--follow', '--force', '--force-break-lock', '--from', '--full', '--full-history', '--generation', '--held', '--help', '--id', '--include-ambiguous', '--include-cross-entity', '--include-failures', '--include-repairs', '--json', '--keep', '--key', '--kind', '--limit', '--max-cost', '--max-cost-usd', '--max-usd', '--mode', '--no-accept-pending', '--no-delegate', '--no-embed', '--no-llm', '--older-than', '--only', '--prefer', '--principal', '--probe', '--progress-interval', '--progress-json', '--provenance', '--quiet', '--remediate', '--remediation-plan', '--request', '--request-id', '--reset-checkpoint', '--retry-failed', '--rules', '--run', '--scopes', '--seat', '--session', '--side', '--since', '--skip', '--skip-failed', '--slug', '--slugs', '--source', '--stale', '--state', '--timeout', '--timings', '--url', '--wait', '--yes'],'repair-jsonb': ['--accept-pending', '--as', '--background', '--brain', '--dry-run', '--explain', '--follow', '--help', '--json', '--no-accept-pending', '--probe', '--progress-interval', '--progress-json', '--quiet', '--source', '--supabase', '--timeout', '--timings', '--url', '--wait'],'report': ['--brain', '--content', '--dir', '--help', '--json', '--source', '--title', '--type'],- 'repos': ['--abandon', '--abbrev-ref', '--abort', '--accept-suggested', '--access', '--account', '--add', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--adopt-slug-path', '--after', '--all', '--all-new', '--allow-unverified-remote', '--allowed-operations', '--app-id', '--app-install', '--app-pem', '--apply', '--approval-out', '--approved', '--attest-actor', '--attest-ops', '--attest-sources', '--audit', '--auto-additive', '--autostash', '--backups', '--batch-check', '--before', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-usd-per-day', '--cached', '--calendar-id', '--category', '--classify', '--cleanup-dead-local-locks', '--clear', '--client', '--clone-dir', '--code', '--config', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--count', '--cursor', '--days', '--decisions', '--delegated-namespace', '--delegated-slug-prefixes', '--depth', '--detect', '--diff-filter', '--dir', '--disable', '--dry-run', '--enable', '--error-unmatch', '--exclude', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-epoch', '--expected-incarnation', '--expected-state', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--fix', '--force', '--format', '--from', '--from-git', '--full', '--future-days', '--get', '--get-all', '--git-dir', '--git-path', '--github-repo', '--grant-types', '--group-by', '--hard', '--help', '--history-days', '--holds', '--http', '--id', '--if-version', '--include', '--include-warns', '--install', '--is-ancestor', '--is-inside-work-tree', '--json', '--keep', '--keep-checkout', '--keep-storage', '--kind', '--lanes', '--limit', '--list-out', '--local', '--local-env-vars', '--loops-exclude-labels', '--manifest', '--max-cost-usd', '--may-act-for', '--member', '--message', '--migrate-legacy', '--migration', '--min-trust', '--mode', '--name', '--name-only', '--no-autostash', '--no-cron', '--no-embed', '--no-extract', '--no-federate', '--no-federated', '--no-harden', '--no-lanes', '--no-pull', '--no-tags', '--no-verify', '--not', '--only', '--operation', '--operations', '--origin', '--others', '--out', '--params', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--plan', '--porcelain', '--preview', '--private-pages', '--probe', '--profile', '--pull', '--push-only', '--push-remote', '--quiet', '--read-sources', '--rebase', '--redirect-uri', '--refresh-operations', '--remove-backup', '--repair', '--replace', '--repos', '--request-id', '--require-clean', '--reset-checkpoint', '--reset-default', '--resolve', '--resume', '--retire', '--retry-failed', '--sample', '--scope', '--scopes', '--secret', '--self-transfer', '--services', '--set', '--set-upstream-to', '--shared-skills', '--short', '--show-toplevel', '--since', '--slug-prefixes', '--source', '--source-id', '--source-ids', '--sources', '--stale', '--state', '--status', '--stdin', '--surface', '--symbolic-full-name', '--takes-holders', '--to', '--token', '--token-command', '--token-endpoint-auth-method', '--token-env', '--token-ttl', '--unindexed', '--uninstall', '--unset-all', '--unsettle', '--untracked-files', '--url', '--usage', '--verify', '--wait', '--wait-drain', '--warn-only', '--window', '--yes'],+ 'repos': ['--abandon', '--abbrev-ref', '--abort', '--accept-suggested', '--access', '--account', '--add', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--adopt-slug-path', '--after', '--all', '--all-new', '--allow-unverified-remote', '--allowed-operations', '--app-id', '--app-install', '--app-pem', '--apply', '--approval-out', '--approved', '--attest-actor', '--attest-ops', '--attest-sources', '--audit', '--auto-additive', '--autostash', '--backups', '--batch-check', '--before', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-usd-per-day', '--cached', '--calendar-id', '--category', '--classify', '--cleanup-dead-local-locks', '--clear', '--client', '--clone-dir', '--code', '--config', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--count', '--cursor', '--days', '--decisions', '--delegated-namespace', '--delegated-slug-prefixes', '--depth', '--detect', '--diff-filter', '--dir', '--disable', '--dry-run', '--enable', '--error-unmatch', '--exclude', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-epoch', '--expected-incarnation', '--expected-state', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--fix', '--force', '--format', '--from', '--from-git', '--full', '--future-days', '--get', '--get-all', '--git-dir', '--git-path', '--github-repo', '--grant-types', '--group-by', '--hard', '--help', '--history-days', '--holds', '--http', '--id', '--if-version', '--include', '--include-warns', '--install', '--is-ancestor', '--is-inside-work-tree', '--json', '--keep', '--keep-checkout', '--keep-storage', '--kind', '--lanes', '--limit', '--list-out', '--local', '--local-env-vars', '--loops-exclude-labels', '--manifest', '--max-cost-usd', '--may-act-for', '--member', '--message', '--migrate-legacy', '--migration', '--min-trust', '--mode', '--name', '--name-only', '--no-autostash', '--no-cron', '--no-embed', '--no-extract', '--no-federate', '--no-federated', '--no-harden', '--no-lanes', '--no-pull', '--no-tags', '--no-verify', '--not', '--only', '--operation', '--operations', '--origin', '--others', '--out', '--params', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--plan', '--porcelain', '--preview', '--private-pages', '--probe', '--profile', '--pull', '--push-only', '--push-remote', '--quiet', '--read-sources', '--rebase', '--redirect-uri', '--refresh-operations', '--remove-backup', '--repair', '--replace', '--repos', '--request-id', '--require-clean', '--reset-checkpoint', '--reset-default', '--resolve', '--resume', '--retire', '--retry-failed', '--sample', '--scan-secrets', '--scope', '--scopes', '--secret', '--self-transfer', '--services', '--set', '--set-upstream-to', '--shared-skills', '--short', '--show-toplevel', '--since', '--slug-prefixes', '--source', '--source-id', '--source-ids', '--sources', '--stale', '--state', '--status', '--stdin', '--surface', '--symbolic-full-name', '--takes-holders', '--to', '--token', '--token-command', '--token-endpoint-auth-method', '--token-env', '--token-ttl', '--unindexed', '--uninstall', '--unset-all', '--unsettle', '--untracked-files', '--url', '--usage', '--verify', '--wait', '--wait-drain', '--warn-only', '--window', '--yes'],'resolvers': ['--backend', '--brain', '--cost', '--help', '--json', '--source'],'retrieval-upgrade': ['--accept-pending', '--all', '--as', '--background', '--batch-size', '--brain', '--catch-up', '--dim', '--dry-run', '--embedding-dimensions', '--embedding-model', '--explain', '--facts', '--follow', '--force', '--held', '--help', '--ignore-env-override', '--images', '--include-null-signature', '--json', '--max-cost-usd', '--max-usd', '--no-accept-pending', '--no-embed', '--non-interactive', '--only', '--oversized', '--pace', '--pace-max-concurrency', '--plan', '--priority', '--progress-interval', '--progress-json', '--quiet', '--replace', '--reranker', '--retarget', '--slugs', '--source', '--stale', '--status', '--timeout', '--timings', '--to', '--wait', '--yes'],'routing-eval': ['--brain', '--help', '--json', '--llm', '--skills-dir', '--source'],@@ -129,7 +129,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {'skillpack': ['--all', '--apply-clean-hunks', '--author', '--auto', '--brain', '--dest', '--dry-run', '--env', '--exit-code', '--fast', '--fix', '--force-unlock', '--format', '--from', '--full', '--harness', '--help', '--homepage', '--json', '--license', '--list', '--minimal', '--name-only', '--no-cache', '--no-lint', '--note', '--out', '--overwrite-local', '--persona', '--probe', '--pure', '--push', '--quick', '--quiet', '--refresh', '--repo', '--schema-pack', '--scope', '--short', '--since', '--skill', '--skills', '--skills-dir', '--skip-doctor', '--source', '--strict', '--stub', '--supabase', '--target', '--tier', '--trust', '--url', '--verify', '--version', '--workspace', '--yes'],'skillpack-check': ['--accept-pending', '--as', '--background', '--brain', '--explain', '--fast', '--follow', '--help', '--json', '--list', '--no-accept-pending', '--progress-interval', '--progress-json', '--quiet', '--source', '--strict', '--timeout', '--timings', '--wait', '--yes'],'smoke-test': ['--brain', '--help', '--json', '--source'],- 'sources': ['--abandon', '--abbrev-ref', '--abort', '--accept-pending', '--accept-suggested', '--access', '--account', '--add', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--adopt-slug-path', '--after', '--all', '--all-new', '--allow-unverified-remote', '--allowed-operations', '--app-id', '--app-install', '--app-pem', '--apply', '--approval-out', '--approved', '--as', '--attest-actor', '--attest-ops', '--attest-sources', '--audit', '--auto-additive', '--autostash', '--background', '--backups', '--batch-check', '--before', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-usd-per-day', '--cached', '--calendar-id', '--category', '--channels', '--classify', '--cleanup-dead-local-locks', '--clear', '--client', '--clone-dir', '--code', '--config', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--count', '--cursor', '--days', '--db-url', '--decisions', '--delegated-namespace', '--delegated-slug-prefixes', '--depth', '--detect', '--diff-filter', '--dir', '--disable', '--dry-run', '--enable', '--error-unmatch', '--exclude', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-epoch', '--expected-incarnation', '--expected-state', '--explain', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--fix', '--follow', '--force', '--format', '--from', '--from-git', '--full', '--future-days', '--get', '--get-all', '--git-dir', '--git-path', '--github-repo', '--grant-types', '--group-by', '--hard', '--help', '--history-days', '--holds', '--http', '--id', '--if-version', '--include', '--include-warns', '--install', '--is-ancestor', '--is-inside-work-tree', '--json', '--keep', '--keep-checkout', '--keep-storage', '--kind', '--lanes', '--legacy-lock', '--limit', '--list-out', '--local', '--local-env-vars', '--lookback-days', '--loops-exclude-labels', '--manifest', '--max-cost-usd', '--max-requests', '--may-act-for', '--member', '--message', '--migrate-legacy', '--migration', '--min-trust', '--mode', '--name', '--name-only', '--no-accept-pending', '--no-autostash', '--no-cron', '--no-embed', '--no-extract', '--no-federate', '--no-federated', '--no-harden', '--no-lanes', '--no-pull', '--no-tags', '--no-verify', '--not', '--only', '--operation', '--operations', '--origin', '--others', '--out', '--params', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--plan', '--porcelain', '--preview', '--private-pages', '--probe', '--profile', '--progress-interval', '--progress-json', '--provider', '--pull', '--push-only', '--push-remote', '--quiet', '--read-sources', '--rebase', '--record', '--redirect-uri', '--refresh-operations', '--remove-backup', '--repair', '--replace', '--repos', '--request-id', '--require-clean', '--reset-checkpoint', '--reset-default', '--resolve', '--resume', '--retire', '--retry-failed', '--sample', '--scope', '--scopes', '--secret', '--self-transfer', '--services', '--set', '--set-upstream-to', '--shared-skills', '--short', '--show-toplevel', '--since', '--skip', '--slug-prefixes', '--source', '--source-id', '--source-ids', '--sources', '--stale', '--state', '--status', '--stdin', '--surface', '--symbolic-full-name', '--sync-interval-min', '--takes-holders', '--timeout', '--timezone', '--timings', '--to', '--token', '--token-command', '--token-endpoint-auth-method', '--token-env', '--token-ttl', '--transcript', '--unindexed', '--uninstall', '--unset-all', '--unsettle', '--untracked-files', '--url', '--usage', '--verify', '--visibility', '--wait', '--wait-drain', '--warn-only', '--window', '--yes'],+ 'sources': ['--abandon', '--abbrev-ref', '--abort', '--accept-pending', '--accept-suggested', '--access', '--account', '--add', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--adopt-slug-path', '--after', '--all', '--all-new', '--allow-unverified-remote', '--allowed-operations', '--app-id', '--app-install', '--app-pem', '--apply', '--approval-out', '--approved', '--as', '--attest-actor', '--attest-ops', '--attest-sources', '--audit', '--auto-additive', '--autostash', '--background', '--backups', '--batch-check', '--before', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-usd-per-day', '--cached', '--calendar-id', '--category', '--channels', '--classify', '--cleanup-dead-local-locks', '--clear', '--client', '--clone-dir', '--code', '--config', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--count', '--cursor', '--days', '--db-url', '--decisions', '--delegated-namespace', '--delegated-slug-prefixes', '--depth', '--detect', '--diff-filter', '--dir', '--disable', '--dry-run', '--enable', '--error-unmatch', '--exclude', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-epoch', '--expected-incarnation', '--expected-state', '--explain', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--fix', '--follow', '--force', '--format', '--from', '--from-git', '--full', '--future-days', '--get', '--get-all', '--git-dir', '--git-path', '--github-repo', '--grant-types', '--group-by', '--hard', '--help', '--history-days', '--holds', '--http', '--id', '--if-version', '--include', '--include-warns', '--install', '--is-ancestor', '--is-inside-work-tree', '--json', '--keep', '--keep-checkout', '--keep-storage', '--kind', '--lanes', '--legacy-lock', '--limit', '--list-out', '--local', '--local-env-vars', '--lookback-days', '--loops-exclude-labels', '--manifest', '--max-cost-usd', '--max-requests', '--may-act-for', '--member', '--message', '--migrate-legacy', '--migration', '--min-trust', '--mode', '--name', '--name-only', '--no-accept-pending', '--no-autostash', '--no-cron', '--no-embed', '--no-extract', '--no-federate', '--no-federated', '--no-harden', '--no-lanes', '--no-pull', '--no-tags', '--no-verify', '--not', '--only', '--operation', '--operations', '--origin', '--others', '--out', '--params', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--plan', '--porcelain', '--preview', '--private-pages', '--probe', '--profile', '--progress-interval', '--progress-json', '--provider', '--pull', '--push-only', '--push-remote', '--quiet', '--read-sources', '--rebase', '--record', '--redirect-uri', '--refresh-operations', '--remove-backup', '--repair', '--replace', '--repos', '--request-id', '--require-clean', '--reset-checkpoint', '--reset-default', '--resolve', '--resume', '--retire', '--retry-failed', '--sample', '--scan-secrets', '--scope', '--scopes', '--secret', '--self-transfer', '--services', '--set', '--set-upstream-to', '--shared-skills', '--short', '--show-toplevel', '--since', '--skip', '--slug-prefixes', '--source', '--source-id', '--source-ids', '--sources', '--stale', '--state', '--status', '--stdin', '--surface', '--symbolic-full-name', '--sync-interval-min', '--takes-holders', '--timeout', '--timezone', '--timings', '--to', '--token', '--token-command', '--token-endpoint-auth-method', '--token-env', '--token-ttl', '--transcript', '--unindexed', '--uninstall', '--unset-all', '--unsettle', '--untracked-files', '--url', '--usage', '--verify', '--visibility', '--wait', '--wait-drain', '--warn-only', '--window', '--yes'],'status': ['--abbrev-ref', '--acknowledge-managed', '--all', '--allow-empty', '--apply', '--brain', '--break-lock', '--cached', '--check', '--code', '--concurrency', '--confirm-destructive', '--count', '--cursor', '--deadline-ms', '--delete', '--detail', '--diff-filter', '--empty', '--enable', '--exclude', '--exclude-standard', '--fast', '--filters', '--fix', '--force-break-lock', '--format', '--full', '--full-history', '--funnel', '--hard-deadline', '--help', '--hold-state', '--include-gitignored', '--include-hidden', '--install', '--interval', '--is-ancestor', '--is-shallow-repository', '--json', '--lanes', '--limit', '--max-age', '--max-sources', '--mcp-only', '--missing-path', '--name-only', '--no-auto-embed', '--no-bulk', '--no-delegate', '--no-embed', '--no-extract', '--no-gpg-sign', '--no-hard-deadline', '--no-lanes', '--no-llm', '--no-pull', '--no-renames', '--no-repair', '--no-schema-pack', '--no-verify', '--no-walk', '--others', '--parallel', '--path', '--prefer', '--preview', '--priority', '--quiet', '--redact-paths', '--repo', '--request-id', '--reset-checkpoint', '--retry-failed', '--retry-held', '--reverse', '--section', '--serial', '--show-toplevel', '--skip-failed', '--slug', '--slugs', '--source', '--source-id', '--src-subpath', '--stale', '--status', '--strategy', '--timeout', '--url', '--verify', '--watch', '--workers', '--working-tree', '--yes'],'storage': ['--brain', '--help', '--json', '--plan', '--repo', '--restore-only', '--source', '--to'],'sweep': ['--accept-pending', '--apply', '--as', '--assign-corpus', '--background', '--batch-limit', '--brain', '--budget-ms', '--delete-brain', '--explain', '--follow', '--help', '--home', '--json', '--no-accept-pending', '--no-delegate', '--once', '--only', '--progress-interval', '--progress-json', '--quiet', '--retry-failed', '--session', '--source', '--source-id', '--stale', '--timeout', '--timings', '--wait'],diff --git a/src/core/git/reconcile.ts b/src/core/git/reconcile.tsindex 4a68e53fd4..d4aea0255d 100644--- a/src/core/git/reconcile.ts+++ b/src/core/git/reconcile.ts@@ -2,15 +2,17 @@* One checkout brought level with its upstream, the engine-free half of `gbrain sources git-reconcile` (the managed half* runs `gbrain sources refresh`). Idempotent: a checkout already level costs one fetch and reports in_sync. Behind:* the shared pull (fast-forward, never a rebase). Ahead or diverged: the upstream-rewrite check, then the shared- * publish with the secret gate (merged in memory, never a rebase or force-push, refusing on a conflict). Concurrent- * callers serialize on the checkout's commit and publish locks and end level with the same upstream.+ * publish with the secret gate (merged in memory, never a rebase or force-push, refusing on a conflict), bound with+ * --expect-remote to the upstream the rewrite check read, so a force-push after the check refuses instead of being+ * merged back. The pull and the publish run as bounded `gbrain git commit-push` children (their Git work is synchronous),+ * so a caller's event loop (the autopilot daemon's) never blocks. Concurrent callers take turns on the reconcile lock.*/import { execFileBounded } from '../bounded-child-exec.ts';import { classifyGitCheckout } from '../git-checkout.ts';import { gitChildEnv } from '../git-env.ts';-import { opError } from '../ops/contract.ts';+import { OperationError, opError } from '../ops/contract.ts';import { acquireNativeLock } from '../persistence/native-lock.ts';-import { commitAndPush, pullShared } from './commit-push.ts';+import { CHILD_ENV, resolveChildCliInvocation } from '../minions/job-isolation.ts';import { upstreamBeforeFetch, upstreamRewriteReason, type GitRead } from './upstream-history.ts';export type CheckoutReconcileStatus = 'in_sync' | 'published' | 'fast_forwarded' | 'lagging' | 'unpublished' | 'no_repo' | 'no_upstream';@@ -68,9 +70,35 @@ export async function withReconcileLock<T>(root: string, waitMs: number, fn: ()}export interface ReconcileCheckoutOptions {- fetchTimeoutMs?: number; dryRun?: boolean; waitMs?: number;+ fetchTimeoutMs?: number; dryRun?: boolean; waitMs?: number; childTimeoutMs?: number;/** False leaves local commits where they are and reports them unpublished (the user turned automatic publishing off); behind still fast-forwards. */publish?: boolean;+ /** Why local commits were left, when `publish` is false. */+ unpublishedReason?: string;+}++/** A remote that moves between the rewrite check and the push is fetched and checked again, this many times in all. */+const MOVED_REMOTE_ATTEMPTS = 4;++/** The bound on one `gbrain git commit-push` child (a fetch, an in-memory merge and a push, repeated while the remote keeps moving). */+export const COMMIT_PUSH_CHILD_TIMEOUT_MS = 600_000;++/** Run `gbrain git commit-push <args> --path <root> --json` in a bounded child; its JSON document, or its refusal rethrown. */+export async function commitPushChild(root: string, args: string[], timeoutMs = COMMIT_PUSH_CHILD_TIMEOUT_MS): Promise<Record<string, unknown>> {+ const cli = resolveChildCliInvocation(process.env, process.execPath, process.argv[1], () => null);+ if (!cli) throw opError('git_push_unavailable', `This process could not locate its own CLI executable to reconcile ${root}; nothing changed.`,+ `Set ${CHILD_ENV.childCliOverride} to the path of the CLI executable and retry.`);+ const child = await execFileBounded(cli.cmd, [...cli.argsPrefix, 'git', 'commit-push', ...args, '--path', root, '--json'],+ { timeout: timeoutMs, termGraceMs: 10_000, maxBuffer: 1024 * 1024, env: process.env });+ let doc: Record<string, unknown> | null = null;+ try { doc = JSON.parse(String(child.stdout).trim()); } catch { /* reported below */ }+ if (!child.error && doc && typeof doc.code !== 'string') return doc;+ if (doc && typeof doc.code === 'string' && typeof doc.message === 'string') {+ throw opError(doc.code as Parameters<typeof opError>[0], doc.message, typeof doc.suggestion === 'string' ? doc.suggestion : '',+ { ...(typeof doc.detail === 'string' ? { detail: doc.detail } : {}), retryable: doc.retryable === true });+ }+ throw opError('push_unconfirmed', `gbrain git commit-push ${args[0]} in ${root} did not report a result (${child.error ? `exit ${String(child.error.code ?? child.error.signal ?? 'unknown')}` : 'unreadable output'}: ${String(child.stderr).trim().slice(0, 300) || 'no detail'}); the remote may already hold the push.`,+ 'Retry: a reconcile of a level checkout reports in_sync.', { retryable: true });}export async function reconcileCheckout(root: string, opts: ReconcileCheckoutOptions = {}): Promise<CheckoutReconcile> {@@ -82,22 +110,28 @@ async function reconcileLocked(root: string, opts: ReconcileCheckoutOptions): Prconst read = gitReader(root);const hasUpstream = (await read(['rev-parse', '--verify', '-q', '@{upstream}'], 1, 128)).stdout.trim();if (!hasUpstream) return { root, status: 'no_upstream', ahead: 0, behind: 0 };- const before = await upstreamBeforeFetch(read);- const level = await fetchLevel(root, read, opts.fetchTimeoutMs);- if (!level) return { root, status: 'no_upstream', ahead: 0, behind: 0 };- const { ahead, behind, target, head, upstream } = level;- if (!ahead && !behind) return { root, status: 'in_sync', ahead, behind, sha: target };- if (ahead && opts.publish === false) return { root, status: 'unpublished', ahead, behind, sha: target, reason: 'automatic publishing is off (sources.refresh_publish_diverged false)' };- if (opts.dryRun) return { root, status: ahead ? 'published' : 'fast_forwarded', ahead, behind, sha: target, reason: 'dry run: nothing changed' };- if (!ahead) {- const pulled = pullShared(root);- return pulled.status === 'lagging' ? { root, status: 'lagging', ahead, behind, sha: target, ...(pulled.reason ? { reason: pulled.reason } : {}) }- : { root, status: 'fast_forwarded', ahead, behind, sha: pulled.to ?? target };+ for (let attempt = 1; ; attempt++) {+ const before = await upstreamBeforeFetch(read);+ const level = await fetchLevel(root, read, opts.fetchTimeoutMs);+ if (!level) return { root, status: 'no_upstream', ahead: 0, behind: 0 };+ const { ahead, behind, target, head, upstream } = level;+ if (!ahead && !behind) return { root, status: 'in_sync', ahead, behind, sha: target };+ if (ahead && opts.publish === false) return { root, status: 'unpublished', ahead, behind, sha: target, reason: opts.unpublishedReason ?? 'automatic publishing is off (sources.refresh_publish_diverged false)' };+ if (opts.dryRun) return { root, status: ahead ? 'published' : 'fast_forwarded', ahead, behind, sha: target, reason: 'dry run: nothing changed' };+ if (!ahead) {+ const pulled = await commitPushChild(root, ['--pull'], opts.childTimeoutMs);+ if (pulled.status === 'lagging') return { root, status: 'lagging', ahead, behind, sha: target, ...(typeof pulled.reason === 'string' ? { reason: pulled.reason } : {}) };+ return { root, status: pulled.status === 'advanced' ? 'fast_forwarded' : 'in_sync', ahead, behind, sha: typeof pulled.to === 'string' ? pulled.to : target };+ }+ const rewrite = await upstreamRewriteReason(read, before, upstream, target, head);+ if (rewrite) throw opError('upstream_rewritten', `${rewrite} Nothing was pushed from ${root}.`,+ `Ask the user: git -C ${root} log --stat ${upstream}..HEAD lists the local commits; publishing them anyway is gbrain git commit-push --push-only --scan-secrets --path ${root}.`);+ try {+ const pushed = await commitPushChild(root, ['--push-only', '--scan-secrets', '--expect-remote', target], opts.childTimeoutMs);+ return { root, status: pushed.checkout === 'lagging' ? 'lagging' : 'published', ahead, behind, ...(typeof pushed.sha === 'string' ? { sha: pushed.sha } : {}),+ integrated: Number(pushed.integrated) || 0, ...(typeof pushed.lagging_reason === 'string' ? { reason: pushed.lagging_reason } : {}) };+ } catch (error) {+ if (attempt >= MOVED_REMOTE_ATTEMPTS || !(error instanceof OperationError) || error.code !== 'push_unconfirmed' || !/after --expect-remote/.test(error.message)) throw error;+ }}- const rewrite = await upstreamRewriteReason(read, before, upstream, target, head);- if (rewrite) throw opError('upstream_rewritten', `${rewrite} Nothing was pushed from ${root}.`,- `Ask the user: git -C ${root} log --stat ${upstream}..HEAD lists the local commits; publishing them anyway is gbrain git commit-push --push-only --scan-secrets --path ${root}.`);- const pushed = commitAndPush({ repo: root, cwd: root, paths: [], pushOnly: true, scanSecrets: true });- return { root, status: pushed.checkout === 'lagging' ? 'lagging' : 'published', ahead, behind, sha: pushed.sha ?? undefined, integrated: pushed.integrated,- ...(pushed.lagging_reason ? { reason: pushed.lagging_reason } : {}) };}diff --git a/test/autopilot-git-reconcile.test.ts b/test/autopilot-git-reconcile.test.tsindex 27cfb331ca..d2b59b2724 100644--- a/test/autopilot-git-reconcile.test.ts+++ b/test/autopilot-git-reconcile.test.ts@@ -1,50 +1,88 @@/**- * Autopilot reconciles Git checkouts in a bounded child: the daemon's event loop keeps running (lease renewals,- * heartbeat) while the child fetches and pushes, a refusal comes back as a log line, and a hung child is killed.+ * Autopilot reconciles Git checkouts inside the daemon (so it works on PGLite, whose data directory the daemon holds),+ * without blocking it: the daemon's event loop keeps running (lease renewals, heartbeat) while a publish child pushes,+ * a refusal comes back as a log line, and a hung child is killed at its bound.*/import { afterAll, beforeAll, expect, test } from 'bun:test';-import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { execFileSync } from 'node:child_process';+import { chmodSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';-import { reconcileGitInChild } from '../src/commands/autopilot-git-reconcile.ts';+import { autopilotReconcile } from '../src/commands/autopilot-git-reconcile.ts';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';import { withEnv } from './helpers/with-env.ts';-let dir = '';-beforeAll(() => { dir = mkdtempSync(join(tmpdir(), 'autopilot-git-reconcile-')); });-afterAll(() => { rmSync(dir, { recursive: true, force: true }); });+const dir = realpathSync(mkdtempSync(join(tmpdir(), 'autopilot-git-reconcile-')));+const identity = { GIT_AUTHOR_NAME: 'Example', GIT_AUTHOR_EMAIL: '[email protected]', GIT_COMMITTER_NAME: 'Example', GIT_COMMITTER_EMAIL: '[email protected]' };+const git = (root: string, ...args: string[]) => execFileSync('git', ['-C', root, '-c', 'user.name=Example', '-c', '[email protected]',+ '-c', 'commit.gpgsign=false', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();+const realCli = join(dir, 'gbrain');+let engine: PGLiteEngine;-function fakeCli(name: string, body: string): string {+beforeAll(async () => {+ writeFileSync(realCli, `#!/bin/sh\nexec '${process.execPath}' '${join(import.meta.dir, '..', 'src', 'cli.ts')}' "$@"\n`);+ chmodSync(realCli, 0o755);+ engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema();+}, 120_000);+afterAll(async () => { await engine.disconnect(); rmSync(dir, { recursive: true, force: true }); });++function source(name: string): { root: string; remote: string } {+ const remote = join(dir, `${name}.git`), root = join(dir, name);+ execFileSync('git', ['init', '-q', '--bare', '-b', 'main', remote]);+ execFileSync('git', ['clone', '-q', remote, root], { stdio: 'ignore' });+ git(root, 'checkout', '-q', '-b', 'main');+ mkdirSync(join(root, 'notes'));+ writeFileSync(join(root, 'notes', 'a.md'), 'start\n');+ git(root, 'add', '.'); git(root, 'commit', '-qm', 'init'); git(root, 'push', '-q', '-u', 'origin', 'main');+ return { root, remote };+}+async function only(name: string, root: string, remote: string) {+ await engine.executeRaw('DELETE FROM sources WHERE id <> $1', ['default']);+ await engine.executeRaw('INSERT INTO sources(id,name,local_path,config) VALUES($1,$1,$2,$3::jsonb)', [name, root, JSON.stringify({ remote_url: remote })]);+}+function wrapper(name: string, onPush: string): string {const path = join(dir, name);- writeFileSync(path, `#!/bin/sh\n${body}\n`);+ writeFileSync(path, `#!/bin/sh\ncase " $* " in *" --push-only "*) ${onPush};; esac\nexec '${realCli}' "$@"\n`);chmodSync(path, 0o755);return path;}-test('the event loop keeps ticking while the reconcile child runs, and a publish is logged', async () => {- const cli = fakeCli('slow.sh', `[ "$1 $2 $3" = "sources git-reconcile --json" ] || exit 9-sleep 2-echo '{"results":[{"sources":["source-a"],"root":"/r","status":"published"},{"sources":["source-b"],"root":"/s","status":"in_sync"}],"exit":0}'`);+test('the event loop keeps ticking while a publish child runs, and the publish is logged', async () => {+ const s = source('slow');+ await only('slow-source', s.root, s.remote);+ writeFileSync(join(s.root, 'notes', 'b.md'), 'stranded\n'); git(s.root, 'add', '.'); git(s.root, 'commit', '-qm', 'stranded');+ const local = git(s.root, 'rev-parse', 'HEAD');let ticks = 0;const timer = setInterval(() => { ticks++; }, 50);const started = Date.now();- const outcome = await withEnv({ GBRAIN_JOB_CHILD_CLI: cli }, () => reconcileGitInChild()).finally(() => clearInterval(timer));+ const outcome = await withEnv({ ...identity, GBRAIN_JOB_CHILD_CLI: wrapper('slow.sh', 'sleep 2') }, () => autopilotReconcile(engine)).finally(() => clearInterval(timer));expect(Date.now() - started).toBeGreaterThanOrEqual(1900);expect(ticks).toBeGreaterThanOrEqual(25);- expect(outcome).toEqual({ ok: true, exit: 0, lines: ['source-a: published'] });-}, 30_000);+ expect(outcome).toEqual({ ok: true, lines: ['slow-source: published'] });+ expect(git(s.remote, 'rev-parse', 'refs/heads/main')).toBe(local);+ expect(await withEnv({ ...identity, GBRAIN_JOB_CHILD_CLI: realCli }, () => autopilotReconcile(engine))).toEqual({ ok: true, lines: [] });+}, 120_000);-test('a refusal that needs the user is reported, not thrown', async () => {- const cli = fakeCli('refuse.sh', `echo '{"results":[{"sources":["source-a"],"root":"/r","status":"needs_user","error":{"code":"publish_secret_found","message":"a secret"}}],"exit":1}'-exit 1`);- expect(await withEnv({ GBRAIN_JOB_CHILD_CLI: cli }, () => reconcileGitInChild()))- .toEqual({ ok: false, exit: 1, lines: ['source-a: needs_user publish_secret_found: a secret'] });-}, 30_000);+test('a refusal that needs the user is reported, not thrown, and nothing is pushed', async () => {+ const s = source('secret');+ await only('secret-source', s.root, s.remote);+ const before = git(s.remote, 'rev-parse', 'refs/heads/main');+ writeFileSync(join(s.root, 'notes', 'key.md'), `token ${'ghp_' + 'Zt4q'.repeat(9)}\n`); git(s.root, 'add', '.'); git(s.root, 'commit', '-qm', 'oops');+ const outcome = await withEnv({ ...identity, GBRAIN_JOB_CHILD_CLI: realCli }, () => autopilotReconcile(engine));+ expect(outcome.ok).toBe(false);+ expect(outcome.lines).toHaveLength(1);+ expect(outcome.lines[0]).toStartWith('secret-source: needs_user publish_secret_found: ');+ expect(outcome.lines[0]).not.toContain('Zt4q');+ expect(git(s.remote, 'rev-parse', 'refs/heads/main')).toBe(before);+}, 120_000);-test('a child that hangs past the bound is killed and reported', async () => {- const cli = fakeCli('hang.sh', 'exec sleep 30');+test('a publish child that hangs past its bound is killed and reported as retryable', async () => {+ const s = source('hang');+ await only('hang-source', s.root, s.remote);+ writeFileSync(join(s.root, 'notes', 'c.md'), 'stuck\n'); git(s.root, 'add', '.'); git(s.root, 'commit', '-qm', 'stuck');const started = Date.now();- const outcome = await withEnv({ GBRAIN_JOB_CHILD_CLI: cli }, () => reconcileGitInChild(500));- expect(Date.now() - started).toBeLessThan(15_000);+ const outcome = await withEnv({ ...identity, GBRAIN_JOB_CHILD_CLI: wrapper('hang.sh', 'exec sleep 30') }, () => autopilotReconcile(engine, { childTimeoutMs: 500 }));+ expect(Date.now() - started).toBeLessThan(20_000);expect(outcome.ok).toBe(false);- expect(outcome.lines[0]).toStartWith('sources git-reconcile ');-}, 30_000);+ expect(outcome.lines[0]).toStartWith('hang-source: failed push_unconfirmed: ');+}, 120_000);diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txtindex 730dd3597f..35d1273c7f 100644--- a/test/postgres-unit-arms.txt+++ b/test/postgres-unit-arms.txt@@ -515,6 +515,7 @@ test/shared-skills-writer-boundary.test.tstest/source-lifecycle-dry-run-physical-root-6849.test.tstest/source-retire-missing-checkout.test.tstest/source-row-diagnostics.test.ts+test/sources-git-reconcile.test.tstest/sources-resolve-path.test.tstest/stats-health-source-scope.test.tstest/sync-absent-from-worktree-s27.test.tsdiff --git a/test/sources-git-reconcile.test.ts b/test/sources-git-reconcile.test.tsindex d05ac532a8..3d583dcdc8 100644--- a/test/sources-git-reconcile.test.ts+++ b/test/sources-git-reconcile.test.ts@@ -64,10 +64,13 @@ const commit = (root: string, file: string, content: string) => {return git(root, 'rev-parse', 'HEAD');};const siblingPush = (r: Repo, file: string, content: string) => { git(r.sibling, 'pull', '-q', '--no-rebase', 'origin', 'main'); const sha = commit(r.sibling, file, content); git(r.sibling, 'push', '-q', 'origin', 'main'); return sha; };+const onRemoteSha = (root: string, sha: string) => { try { git(root, 'fetch', '-q', 'origin'); git(root, 'merge-base', '--is-ancestor', sha, 'origin/main'); return true; } catch { return false; } };const tip = (r: Repo) => git(r.remote, 'rev-parse', 'refs/heads/main');const onRemote = (r: Repo, sha: string) => { try { git(r.remote, 'merge-base', '--is-ancestor', sha, 'refs/heads/main'); return true; } catch { return false; } };const refusal = async (p: Promise<unknown>) => p.then(() => { throw new Error('expected a refusal'); }, e => e as { code: string; message: string });-const reconcile = (root: string) => withEnv(identity, () => reconcileCheckout(root));+const childEnv = { ...identity, GBRAIN_JOB_CHILD_CLI: childCli };+const reconcile = (root: string) => withEnv(childEnv, () => reconcileCheckout(root));+const reconcileAll = (engine: BrainEngine, ids?: string[]) => withEnv(childEnv, () => reconcileSources(engine, ids ? { sourceIds: ids } : {}));test('no Git checkout and no upstream report themselves and change nothing', async () => {const plain = join(dir, 'plain'); mkdirSync(plain);@@ -124,6 +127,27 @@ test('a secret in the local commits and a rewritten upstream each refuse with noexpect(tip(w)).toBe(rewritten);}, 60_000);+test('a force-push between the rewrite check and the push is not merged back: the publish is bound to the checked upstream', async () => {+ const w = repo('race');+ const purged = commit(w.root, 'notes/purge-me.md', 'published, then purged\n');+ git(w.root, 'push', '-q', 'origin', 'main');+ commit(w.root, 'notes/local.md', 'local\n');+ const mark = join(dir, 'race.mark'), racer = join(dir, 'bin', 'racer');+ writeFileSync(racer, `#!/bin/sh+case " $* " in *" --push-only "*) if [ ! -f '${mark}' ]; then touch '${mark}'+ git -C '${w.sibling}' fetch -q origin && git -C '${w.sibling}' reset -q --hard '${purged}~1'+ echo rewritten > '${join(w.sibling, 'notes', 'other.md')}' 2>/dev/null || { mkdir -p '${join(w.sibling, 'notes')}'; echo rewritten > '${join(w.sibling, 'notes', 'other.md')}'; }+ git -C '${w.sibling}' add -A && git -C '${w.sibling}' -c user.name=Example -c [email protected] commit -qm rewrite && git -C '${w.sibling}' push -q --force origin main+fi;; esac+exec '${childCli}' "$@"+`);+ chmodSync(racer, 0o755);+ const error = await refusal(withEnv({ ...identity, GBRAIN_JOB_CHILD_CLI: racer }, () => reconcileCheckout(w.root)));+ expect(error.code).toBe('upstream_rewritten');+ expect(error.message).toContain(purged);+ expect(onRemote(w, purged)).toBe(false);+}, 120_000);+test('eight concurrent callers while another clone pushes mid-run: all succeed, no commit is lost, and a ninth call is in_sync', async () => {const r = repo('concurrent');const start = tip(r);@@ -132,7 +156,7 @@ test('eight concurrent callers while another clone pushes mid-run: all succeed,writeFileSync(script, `import { reconcileCheckout } from '${join(import.meta.dir, '..', 'src', 'core', 'git', 'reconcile.ts')}';\n`+ `try { console.log(JSON.stringify(await reconcileCheckout(process.argv[2]))); } catch (e) { console.log(JSON.stringify({ code: (e as { code?: string }).code, message: String((e as Error).message) })); process.exit(1); }\n`);const run = () => new Promise<{ code: number | null; out: string }>(resolve => {- const child = spawn(process.execPath, [script, r.root], { env: { ...process.env, ...identity }, stdio: ['ignore', 'pipe', 'pipe'] });+ const child = spawn(process.execPath, [script, r.root], { env: { ...process.env, ...childEnv }, stdio: ['ignore', 'pipe', 'pipe'] });let out = ''; child.stdout.on('data', d => { out += d; });child.on('close', code => resolve({ code, out }));});@@ -167,6 +191,10 @@ test('managed worktree: Git durability on publishes through refresh and a repeatgit(f.root, 'merge-base', '--is-ancestor', local, 'HEAD');expect(f.head()).toBe(git(f.root, 'ls-remote', 'origin', 'refs/heads/main').split('\t')[0]);expect(await reconcileSources(engine, { sourceIds: [f.alpha, f.beta] })).toMatchObject([{ status: 'in_sync' }]);+ await engine.setConfig(REFRESH_PUBLISH_DIVERGED_KEY, 'false');+ const unpushed = commit(f.root, 'beta/later.md', page('Later', 'Another local commit.'));+ expect(await reconcileSources(engine, { sourceIds: [f.alpha, f.beta] })).toMatchObject([{ managed: true, status: 'unpublished', ahead: 1 }]);+ expect(onRemoteSha(f.root, unpushed)).toBe(false);} finally {await engine.executeRaw(`UPDATE persistence_host_bindings SET git_durability=NULL WHERE local_path LIKE $1`, [`${f.root}%`]);await engine.unsetConfig(REFRESH_PUBLISH_DIVERGED_KEY);@@ -197,16 +225,39 @@ test('with automatic publishing turned off, local commits stay unpublished whileawait engine.connect({}); await engine.initSchema();try {const r = repo('optout');- await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', ['optout-source', r.root]);+ await engine.executeRaw('INSERT INTO sources(id,name,local_path,config) VALUES($1,$1,$2,$3::jsonb)', ['optout-source', r.root, JSON.stringify({ remote_url: r.remote })]);await engine.setConfig(REFRESH_PUBLISH_DIVERGED_KEY, 'false');const theirs = siblingPush(r, 'notes/theirs.md', 'from the sibling\n');- expect(await withEnv(identity, () => reconcileSources(engine))).toMatchObject([{ sources: ['optout-source'], status: 'fast_forwarded', behind: 1 }]);+ expect(await reconcileAll(engine)).toMatchObject([{ sources: ['optout-source'], status: 'fast_forwarded', behind: 1 }]);expect(git(r.root, 'rev-parse', 'HEAD')).toBe(theirs);const local = commit(r.root, 'notes/mine.md', 'mine\n');- expect(await withEnv(identity, () => reconcileSources(engine))).toMatchObject([{ sources: ['optout-source'], status: 'unpublished', ahead: 1, behind: 0 }]);+ expect(await reconcileAll(engine)).toMatchObject([{ sources: ['optout-source'], status: 'unpublished', ahead: 1, behind: 0 }]);expect(tip(r)).toBe(theirs);await engine.setConfig(REFRESH_PUBLISH_DIVERGED_KEY, '');- expect(await withEnv(identity, () => reconcileSources(engine))).toMatchObject([{ sources: ['optout-source'], status: 'published', ahead: 1 }]);+ expect(await reconcileAll(engine)).toMatchObject([{ sources: ['optout-source'], status: 'published', ahead: 1 }]);expect(tip(r)).toBe(local);} finally { await engine.disconnect(); }-}, 60_000);+}, 120_000);++test('a checkout gbrain did not clone for the source is never published by default; a sync-disabled or missing source is skipped', async () => {+ const engine = new PGLiteEngine();+ await engine.connect({}); await engine.initSchema();+ try {+ const r = repo('foreign');+ mkdirSync(join(r.root, 'notes'), { recursive: true });+ await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', ['inside-a-repo', join(r.root, 'notes')]);+ const before = tip(r);+ commit(r.root, 'notes/unpushed.md', 'someone else\'s commit\n');+ const [held] = await reconcileAll(engine);+ expect(held).toMatchObject({ sources: ['inside-a-repo'], status: 'unpublished', ahead: 1 });+ expect(held.reason).toContain('did not clone');+ expect(tip(r)).toBe(before);+ await engine.executeRaw(`UPDATE sources SET config = '{"syncEnabled": false}'::jsonb WHERE id = 'inside-a-repo'`);+ await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', ['moved-away', join(dir, 'no-such-folder')]);+ expect(await reconcileAll(engine)).toEqual([{ sources: [], root: '', managed: false, status: 'no_repo', ahead: 0, behind: 0 }]);+ expect(await reconcileAll(engine, ['inside-a-repo'])).toMatchObject([{ status: 'unpublished' }]);+ await engine.setConfig(REFRESH_PUBLISH_DIVERGED_KEY, 'true');+ expect(await reconcileAll(engine, ['inside-a-repo'])).toMatchObject([{ status: 'published', ahead: 1 }]);+ expect(tip(r)).not.toBe(before);+ } finally { await engine.disconnect(); }+}, 120_000);