Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(#6712 PR 4b): a folded stamp owes the tail its whole batch

garrytan79d214e14646
diff --git a/src/core/persistence/sync-pass-fold.ts b/src/core/persistence/sync-pass-fold.ts
index 5bc217fdc5..a9547b0df3 100644
--- a/src/core/persistence/sync-pass-fold.ts
+++ b/src/core/persistence/sync-pass-fold.ts
@@ -53,6 +53,11 @@ export interface PassFold {
episodeFullId: string | null; scope: string;
/** The pass row's obligations when the import was frozen: the stamp writes them, as the checkpoint request reads the row's. */
obligations?: ManagedSyncPassValue['obligations'];
+ /**
+ * The imports of the batch the stamp rides, this one included: the stamp's counts were read before that batch drained,
+ * and the proof shows each of them wrote its page, so the tail owes all of them (absent on a stamp frozen before: 1).
+ */
+ batch?: number;
}
/**
@@ -154,6 +159,6 @@ async function provenStamp(tx: BrainEngine, { row, p, root }: { row: WriteReques
const prior = pass.value.obligations.converged?.writeback;
const read = prior?.length ? await readConvergedWatermark(tx, scope, row.request_id, OPEN_AT_STAMP_CAP, { own: writeback, prior }) : watermark;
await publishPassStamp(tx, row, p, root, async () => {}, fold.obligations ? { value: { ...pass.value, obligations: fold.obligations } } : pass,
- { changed: stamp.changed + (outcome.noop === true ? 0 : 1), watermark: read, ...(emptyScope === undefined ? {} : { emptyScope }) });
+ { changed: stamp.changed + (outcome.noop === true ? 0 : fold.batch ?? 1), watermark: read, ...(emptyScope === undefined ? {} : { emptyScope }) });
return null;
}
diff --git a/src/core/persistence/sync-pass-run.ts b/src/core/persistence/sync-pass-run.ts
index 0e15a6bfb3..186f7f888d 100644
--- a/src/core/persistence/sync-pass-run.ts
+++ b/src/core/persistence/sync-pass-run.ts
@@ -869,7 +869,7 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Pr
for (let i = 0; i < built.entries.length; i += PASS_BATCH_MAX) {
const chunk = built.entries.slice(i, i + PASS_BATCH_MAX), last = !!fold && i + chunk.length >= built.entries.length;
// A folded stamp writes the pass row with the obligations as they stand when its import is frozen.
- const stopped = await drain(chunk, last ? { ...await stampFor(level), fold: { ...fold, obligations: structuredClone(value.obligations) } } : undefined);
+ const stopped = await drain(chunk, last ? { ...await stampFor(level), fold: { ...fold, obligations: structuredClone(value.obligations), batch: chunk.length } } : undefined);
if (stopped) return stop(stopped);
value.telemetry.remaining = Math.max(0, built.entries.length - i - chunk.length) + inFlight.length + owed.length + mismatch.length;
if (await envelopeCrossed(engine, value, costScope, processingOptions)) counts.costDeferred = 1;