Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
refactor(sync): receipt write state in its own helper, keeping prepareSyncMutation within the function-size limit after the #7141 merge
garrytanf2d452c2a4eb
diff --git a/src/core/persistence/sync-prepare.ts b/src/core/persistence/sync-prepare.tsindex b938461e6c..5070960e65 100644--- a/src/core/persistence/sync-prepare.ts+++ b/src/core/persistence/sync-prepare.ts@@ -653,6 +653,12 @@ export async function prepareManagedSyncMutation(unbounded: BrainEngine, row: Wrreturn p?.kind === 'managed_sync_import' && p.stamp?.fold && at.root && !screening ? foldPassCheckpoint(prepared, { row, p, root: at.root }) : prepared;}+/** #6722 and #7106: what a committed sync write left the page's embedding and search index in, for its receipt. */+async function syncWriteState(tx: BrainEngine, row: WriteRequest, page: Parameters<typeof sizeStateField>[3],+ segmented: Parameters<typeof segmentedOutcome>[0], frontmatter: Parameters<typeof isQuarantined>[0]): Promise<Record<string, unknown>> {+ return { ...await sizeStateField(tx, row.source_id, row.slug, page), ...segmentedOutcome(segmented, isQuarantined(frontmatter)) };+}+async function prepareSyncMutation(unbounded: BrainEngine, row: WriteRequest, _config: GBrainConfig, clock: ClaimPhaseClock | undefined,screening: { unsaved: true } | undefined, at: { root?: string }): Promise<SyncPreparedMutation> {const engine = boundedReads(unbounded, clock);@@ -944,11 +950,9 @@ async function prepareSyncMutation(unbounded: BrainEngine, row: WriteRequest, _c...syncDiskProvenance(writeback ? Buffer.from(canonicalFile) : syncDiskBytes(root, p.path!, p.content!, p.rawHash), p.target) }); },]);preparedImport.postimage = final;- // #6722: a large or embed_skip page says what this write left its embedding in.- const sizeState = applied.noop ? {} : await sizeStateField(tx, row.source_id, row.slug, live?.page);+ const writeState = applied.noop ? {} : await syncWriteState(tx, row, live?.page, installed?.segmented, applied.parsedPage?.frontmatter);return { status: moved ? 'renamed' : applied.noop ? 'skipped' : snapshot ? 'updated' : 'created', slug: row.slug, source_id: row.source_id,- chunks: applied.result.chunks, noop: applied.noop && !moved, imported_file: true, ...(moved ? { renamed_from: moved.slug } : {}), ...sizeState,- ...(applied.noop ? {} : segmentedOutcome(installed?.segmented, isQuarantined(applied.parsedPage?.frontmatter))),+ chunks: applied.result.chunks, noop: applied.noop && !moved, imported_file: true, ...(moved ? { renamed_from: moved.slug } : {}), ...writeState,...(recovery?.length ? { recovered_frontmatter: true } : {}), ...(commentValue ? { comment_value: true } : {}),...(fenceFixes.length ? { fences_normalized: fenceFixesWire(fenceFixes) } : {}) };} };