Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

refactor(#6712 PR 4b lane C): delete adoptionReport and the cursorAdopted/cursorFanIn result fields, their HoldRunState producers and their notice/drain consumers (a pass reports kept opt-outs as inherited_options)

garrytan7694715c267e
diff --git a/src/commands/sync.ts b/src/commands/sync.ts
index 97104744af..5a76d7c175 100644
--- a/src/commands/sync.ts
+++ b/src/commands/sync.ts
@@ -28,11 +28,6 @@ export interface SyncResult {
* not set them (`gbrain embed --stale` / `gbrain extract --stale` settle the pages they skipped).
*/
inherited_options?: Array<'noEmbed' | 'noExtract' | 'noSchemaPack'>;
- /** #6712 PR 1: this run finished a cursor another writer, or an older key, started, under that run's frozen options (shown to local callers). */
- cursorAdopted?: { writer_changed: boolean; legacy_key: boolean; sync_options?: import('../core/persistence/sync-prepare.ts').SyncCursorOptions | null;
- processing_options?: import('../core/persistence/sync-authority.ts').SyncProcessingOptions | null };
- /** #6712 PR 1: older-key cursors of the incarnation this run's fan-in folded (`retained`: left while a request under them is open). */
- cursorFanIn?: { adopted: boolean; superseded: number; retained: number };
/** #6693: caller remembers refused while their page's file awaited import (or was held), replayed after this sync imported it. */
replayedRemembers?: import('../core/repair/failed-writes.ts').ImportReplayReport;
/** #6712 PR 2 (L4): live pages whose canonical file is gone (ghost pages), counted after a managed sync with the read-only repair preview; sync never deletes them. */
diff --git a/src/commands/sync/perform.ts b/src/commands/sync/perform.ts
index 1d85afbb5f..2dbda69224 100644
--- a/src/commands/sync/perform.ts
+++ b/src/commands/sync/perform.ts
@@ -134,7 +134,7 @@ async function performManagedBranch(engine: BrainEngine, outer: SyncOpts): Promi
...(n ? { drain: { ...n, passes: d.passes + n.passes, processed: d.processed + n.processed, written: d.written + n.written, waived: d.waived + n.waived } } : {}) };
if (!next.staged) serr(`[sync] staged catch-up reached HEAD after ${stages} stages.`);
}
- await printCursorAdoption(result, sourceId);
+ printInheritedOptions(result);
if (!opts.dryRun) await recordUpstreamObservation(engine, opts.sourceId ?? 'default', opts.repoPath);
if (!opts.dryRun && ['synced', 'first_sync', 'up_to_date'].includes(result.status)) await clearSettledFailures(engine, opts.sourceId ?? 'default');
if (!opts.dryRun) {
@@ -169,17 +169,8 @@ async function performManagedBranch(engine: BrainEngine, outer: SyncOpts): Promi
}
}
-/**
- * #6712 PR 1: the one-line notices of a resumed cursor. A run that finished another writer's (or another option set's)
- * unfinished run names that run's own options, and a kept opt-out names the command that settles what it skipped.
- */
-async function printCursorAdoption(result: SyncResult, sourceId: string): Promise<void> {
- const adopted = result.cursorAdopted;
- if (adopted?.sync_options !== undefined) {
- const { managedSyncResumeArgs } = await import('../../core/sync-reconcile.ts');
- serr(`[sync] resumed the unfinished sync run of source ${sourceId}${adopted.writer_changed ? ' that another writer started' : ''}; it finishes under its own frozen options `
- + `(gbrain sync ${managedSyncResumeArgs({ sourceId, processingOptions: adopted.processing_options, syncOptions: adopted.sync_options }).join(' ')}), and the next run uses this run's.`);
- }
+/** #6712 PR 1: the one-line notice of a kept opt-out, naming the command that settles what it skipped. */
+function printInheritedOptions(result: SyncResult): void {
const kept = result.inherited_options ?? [];
if (!kept.length) return;
const flags = { noEmbed: '--no-embed', noExtract: '--no-extract', noSchemaPack: '--no-schema-pack' } as const;
diff --git a/src/core/persistence/sync-drain.ts b/src/core/persistence/sync-drain.ts
index 161d96f97f..33059f327d 100644
--- a/src/core/persistence/sync-drain.ts
+++ b/src/core/persistence/sync-drain.ts
@@ -1112,7 +1112,7 @@ export function formatDrainSummary(result: SyncResult, resumeCommand: string, so
const d = result.drain;
if (!d) return [];
// #6712 PR 2 (L5): one headline per state; a drain that finished a run an earlier invocation started says so.
- const resumed = d.outcome === 'synced' && result.runId && ((result.managedCursor?.progress?.startIndex ?? 0) > 0 || result.cursorAdopted) ? `resumed run ${result.runId} and converged, ` : '';
+ const resumed = d.outcome === 'synced' && result.runId && (result.managedCursor?.progress?.startIndex ?? 0) > 0 ? `resumed run ${result.runId} and converged, ` : '';
const lines = [`Managed sync ${d.outcome}: ${resumed}${d.processed} entries this run (${d.written} written, ${d.waived} waived)`
+ (d.remaining ? `, ${d.remaining} remaining` : '') + (d.rate_pages_per_min !== null ? `, ${d.rate_pages_per_min} pages/min` : '')
+ (d.remaining && d.eta_seconds !== null ? `, indexing ETA ${formatDuration(d.eta_seconds)}` : '') + '.'];
diff --git a/src/core/persistence/sync-run.ts b/src/core/persistence/sync-run.ts
index 5e69b3f1ee..002f1a9282 100644
--- a/src/core/persistence/sync-run.ts
+++ b/src/core/persistence/sync-run.ts
@@ -1209,10 +1209,7 @@ async function finishCheckpoint(engine: BrainEngine, key: string, cursor: Cursor
return scheduled.length ? result(cursor, 'partial', 'writer_yield') : result(cursor, cursor.from === null ? 'first_sync' : 'synced');
}
/** What the hold report needs from a managed run: its source, cursor and authority. */
-interface HoldRunState { sourceId?: string; incarnation?: string; remote?: boolean; cursor?: () => Cursor | CursorHeader | null;
- /** #6712 PR 1: what the fan-in folded, and what resuming the source's one cursor kept from it. */
- fanIn?: NonNullable<SyncResult['cursorFanIn']>; adopted?: { inherited: Array<keyof SyncProcessingOptions>; writerChanged: boolean; optionsDiffer: boolean;
- syncOptions: SyncCursorOptions | null; processingOptions: SyncProcessingOptions | null } }
+interface HoldRunState { sourceId?: string; incarnation?: string; remote?: boolean; cursor?: () => Cursor | CursorHeader | null }
/**
* One immutable page is admitted at a time; foreground writes can never sit behind a whole scan.
@@ -1252,33 +1249,22 @@ async function performManagedPass(engine: BrainEngine, opts: SyncOpts, slice?: {
screened: 'entries' in (cursor ?? {}) ? (cursor as Cursor).entries.slice(0, cursor!.index).filter(entry => entry.action === 'import').length : 0 });
const recovered = state.remote ? undefined : recoveredReport(state.sourceId, cursor?.counts.recovered);
const fences = fencesNormalizedReport(state.sourceId, cursor?.counts.fences, state.remote === true);
- return { ...synced, ...report, ...adoptionReport(state), ...(!state.remote && cursor?.convertedFromFailed?.length ? { converted_from_failed: cursor.convertedFromFailed } : {}),
+ return { ...synced, ...report, ...(!state.remote && cursor?.convertedFromFailed?.length ? { converted_from_failed: cursor.convertedFromFailed } : {}),
...(recovered ? { recovered_frontmatter: recovered } : {}), ...(fences ? { fences_normalized: fences } : {}) };
} catch {
return synced;
}
}
-/** #6712 PR 1: the result fields of a resumed cursor: the opt-outs it kept from the cursor, and what the fan-in folded. */
-function adoptionReport(state: HoldRunState): Pick<SyncResult, 'inherited_options' | 'cursorAdopted' | 'cursorFanIn'> {
- const adopted = state.adopted;
- return { ...(adopted?.inherited.length ? { inherited_options: adopted.inherited } : {}),
- ...(adopted && (adopted.writerChanged || state.fanIn?.adopted || adopted.optionsDiffer) ? { cursorAdopted: { writer_changed: adopted.writerChanged, legacy_key: state.fanIn?.adopted === true,
- ...(state.remote ? {} : { sync_options: adopted.syncOptions, processing_options: adopted.processingOptions }) } } : {}),
- ...(state.fanIn ? { cursorFanIn: state.fanIn } : {}) };
-}
/**
* #6712 PR 1: the key this pass reads and the older keys folded in (`resolveManagedCursor`). A remote caller folds nothing
* in: the cursors it would cancel or retire may belong to another principal (it adopts only its own). A superseded run's
* write still in flight settles before the adopted run publishes beside it (`waiting`, `writer_pending`).
*/
async function resolvePassCursor(engine: BrainEngine, input: { sourceId: string; incarnation: string; company: Parameters<typeof resolveManagedCursor>[1]['company'];
- remote: boolean; dryRun: boolean; assertActive: () => void; state: HoldRunState }): Promise<{ key: string; waiting?: SyncResult }> {
+ remote: boolean; dryRun: boolean; assertActive: () => void }): Promise<{ key: string; waiting?: SyncResult }> {
const resolution = await resolveManagedCursor(engine, { sourceId: input.sourceId, incarnation: input.incarnation, company: input.company, assertActive: input.assertActive,
readOnly: input.dryRun, foldIn: !input.remote });
- if (resolution.adoptedLegacyKey || resolution.superseded.length || resolution.retained.length) {
- input.state.fanIn = { adopted: !!resolution.adoptedLegacyKey, superseded: resolution.superseded.length, retained: resolution.retained.length };
- }
const header = resolution.waitFor && !input.dryRun
? (await engine.executeRaw<{ completed_keys: [CursorHeader] }>('SELECT completed_keys FROM op_checkpoints WHERE op=$1 AND fingerprint=$2', [OP, resolution.key]))[0]?.completed_keys?.[0] : undefined;
if (!header) return { key: resolution.key };
@@ -1508,7 +1494,7 @@ async function runManagedSync(engine: BrainEngine, opts: SyncOpts, slice: { maxP
} finally { setPassBatch(batchKey, null); }
} });
}
- const resolved = await resolvePassCursor(engine, { sourceId: context.sourceId, incarnation: context.incarnation, company, remote: authority.writer.remote, dryRun: !!opts.dryRun, assertActive, state });
+ const resolved = await resolvePassCursor(engine, { sourceId: context.sourceId, incarnation: context.incarnation, company, remote: authority.writer.remote, dryRun: !!opts.dryRun, assertActive });
key = resolved.key;
if (resolved.waiting) return resolved.waiting;
cursor = await readCursor(engine, key);