Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sync): #6712 PR 4b a pin changed under an unstamped pass is refused slug_root_mode_mismatch (#6694)
garrytan837e323f1165
diff --git a/src/core/persistence/sync-pass-row.ts b/src/core/persistence/sync-pass-row.tsindex d18fbbc04e..9f6ba694e7 100644--- a/src/core/persistence/sync-pass-row.ts+++ b/src/core/persistence/sync-pass-row.ts@@ -76,6 +76,13 @@ export interface ManagedSyncPassValue {legacy_markers_at?: string;/** #6712 PR 4b (design §2.6): the set hash of a withheld mass delete; with the env valve set the next tick runs a full round to apply it. */deletes_withheld?: string | null;+ /**+ * #6694 on the pass: the slug-root mode a subdirectory source's pass admitted pages under before a stamp published it. Later+ * passes read under it, so a pin changed meanwhile is refused `slug_root_mode_mismatch` at the stamp instead of importing the+ * same files again under the other mode's slugs. A configured stamp clears it; keeping the new pin retires it+ * (`gbrain repair managed-sync-orphans`, `slug_mode_refused`).+ */+ slug_mode?: 'git-root' | 'source-root';/** #6712 PR 3 (L7) on the pass: the page request a blocked pass stopped on, which the next pass replays while what refused it is unchanged. */blocked?: { request_id: string; pass_id: string };};diff --git a/src/core/persistence/sync-pass-run.ts b/src/core/persistence/sync-pass-run.tsindex 2763ca2c7d..248e9df8c8 100644--- a/src/core/persistence/sync-pass-run.ts+++ b/src/core/persistence/sync-pass-run.ts@@ -493,7 +493,8 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Prvalue.telemetry.round = round;input.onLevelRead(head);const level = await readShadowLevel(engine, { sourceId, context, workingTree: mode === 'working',- pass: { noSchemaPack: processingOptions.noSchemaPack, episodeFullId: episode?.full_id ?? null, retryConsumed: round > 1 ? retryConsumed : undefined, exclude: opts.exclude, includeHidden: opts.includeHidden, strategy: opts.strategy, bootstrap: markersOwed() } });+ pass: { noSchemaPack: processingOptions.noSchemaPack, episodeFullId: episode?.full_id ?? null, retryConsumed: round > 1 ? retryConsumed : undefined, exclude: opts.exclude, includeHidden: opts.includeHidden, strategy: opts.strategy, bootstrap: markersOwed(),+ slugMode: value.obligations.slug_mode } });assertActive();if (!level) throw new Error(`Source ${sourceId} became a company-brain source during its sync pass.`);// Each round reads the level at the current HEAD, and its batches freeze that commit (a commit landing mid-pass is@@ -570,7 +571,7 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Prreturn { ...result('blocked_by_failures', 'reconcile_host_required'), reconcile };}if (mismatch.length || owed.length) break;- if (round === 1 && configured && context.source.last_commit === head && !episode && !retry.length && !tail) {+ if (round === 1 && configured && context.source.last_commit === head && !episode && !retry.length && !tail && !value.obligations.slug_mode) {// v3 §3.3: a pass that finds nothing at last_commit = T admits no checkpoint; it keeps master's up_to_date (only// last_sync_at), and its full round refreshes the converged watermark so the next tick can be idle.const at = new Date().toISOString();@@ -617,6 +618,8 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): PrS.set(settledKey(entry.path, entry.state.level), 'collision'); counts.collisions++;}if (optOutEpisode && !value.obligations.episode && built.entries.length) value.obligations.episode = episode = optOutEpisode;+ // #6694: the mode this pass publishes pages under is recorded before the first of them, so a pin changed before the stamp refuses there.+ if (level.scope && built.entries.length && !value.obligations.slug_mode) { value.obligations.slug_mode = level.slugMode; await save('open', null); }for (let i = 0; i < built.entries.length; i += PASS_BATCH_MAX) {const chunk = built.entries.slice(i, i + PASS_BATCH_MAX);const stopped = await drain(chunk);diff --git a/src/core/persistence/sync-pass.ts b/src/core/persistence/sync-pass.tsindex 1fac77e000..30bd916d97 100644--- a/src/core/persistence/sync-pass.ts+++ b/src/core/persistence/sync-pass.ts@@ -58,6 +58,8 @@ export interface PassLevelInput {bootstrap?: boolean;/** The pass imports without the schema pack (`no-schema-pack` or an episode carrying it): its parser expects no pack. */noSchemaPack?: boolean;+ /** #6694: the slug-root mode an unstamped pass of this source admitted under (`obligations.slug_mode`); a subdirectory source reads under it, not its pin. */+ slugMode?: 'git-root' | 'source-root';}/** PGLite's keyset page size (design v3.2 §2.1); Postgres reads `I⋈P` in one statement of its snapshot. */const PGLITE_KEYSET_ROWS = 2_000;@@ -267,7 +269,7 @@ export async function readShadowLevel(engine: BrainEngine, input: { sourceId: stt = timer();const [company, slugModeRead, excludeRead, includeHiddenRead, workingRead, packRead, mirrorRead] = await Promise.allSettled([currentCompanyBrainSync(sourceId) ? Promise.resolve(true) : getCompanyBrainProfile(engine, sourceId).then(profile => !!profile),- scope ? resolveSlugRootMode(engine, { sourceId, explicitGitRoot: false, slugPrefix: resolveSlugForPath(join(scope, 'x.md')).slice(0, -2), dryRun: true }) : Promise.resolve('git-root' as const),+ scope && input.pass?.slugMode ? Promise.resolve(input.pass.slugMode) : scope ? resolveSlugRootMode(engine, { sourceId, explicitGitRoot: false, slugPrefix: resolveSlugForPath(join(scope, 'x.md')).slice(0, -2), dryRun: true }) : Promise.resolve('git-root' as const),syncExcludePatterns(engine, [...input.pass?.exclude ?? []]),engine.getConfig('sync.include_hidden'),input.workingTree === undefined ? engine.getConfig('sync.include_working_tree') : Promise.resolve(null),diff --git a/src/core/persistence/sync-prepare.ts b/src/core/persistence/sync-prepare.tsindex a3031bba65..21e5591ba7 100644--- a/src/core/persistence/sync-prepare.ts+++ b/src/core/persistence/sync-prepare.ts@@ -526,6 +526,7 @@ async function applyPassCheckpoint(tx: BrainEngine, row: WriteRequest, p: SyncInparser_fp: stamp.parserFp, pack: stamp.pack, selection_fp: stamp.selectionFp, last_full_at: stamp.full || !prior ? at : prior.last_full_at,passes_since_full: stamp.full || !prior ? 0 : prior.passes_since_full + 1 };if (stamp.closesEpisode) delete value.obligations.episode;+ if (stamp.configured) delete value.obligations.slug_mode;Object.assign(value.obligations, { not_converged_streak: 0, mismatch: {}, faults: {}, stuck_since: null });value.telemetry = { ...value.telemetry, outcome: 'synced', stop_reason: stamp.configured ? null : 'selection_scoped', ended_at: at, remaining: 0,duration_ms: Date.parse(at) - Date.parse(value.telemetry.started_at) };