Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(import): a batch whose admission outcome is unknown names each file's own request id; probe pins ids and digests across the re-run

time-attack73f28f68b687
diff --git a/src/core/persistence/import-mutations.ts b/src/core/persistence/import-mutations.ts
index bc991ab77e..7fdebe1d1e 100644
--- a/src/core/persistence/import-mutations.ts
+++ b/src/core/persistence/import-mutations.ts
@@ -10,6 +10,7 @@ import { currentVerifiedLocalWriter, localHostId } from './identity.ts';
import { getWorktreeBinding } from './ownership.ts';
import { batchSharedReads, emitFenceNotice, initializeLocalPersistence, pendingAwareResponse, preparePageAdmission, requestPrincipalForContext, withBatchAdmission } from './page-mutations.ts';
import { admitBatch } from './page-batch.ts';
+import { writeOutcomeUnknown } from './admission-retry.ts';
import { assertPersistenceAccepting, waitForWrites } from './service.ts';
import type { WriteAdmission } from './journal.ts';
import type { WriteRequest } from './model.ts';
@@ -202,7 +203,12 @@ async function submitManagedImports(ctx: OperationContext, batch: string, params
try {
const admitted = await admitBatch(ctx, batch, admissions.map(entry => entry.admission));
admissions.forEach((entry, position) => rows.push({ index: entry.index, row: admitted[position]!, admitted: true, typeWarning: entry.typeWarning, slugAdvisory: entry.slugAdvisory }));
- } catch (reason) { for (const entry of admissions) settled[entry.index] = { status: 'rejected', reason }; }
+ } catch (reason) {
+ // #6355: the batch's outcome is unknown for every file; each file names its own request id to read (and replay).
+ const unknown = reason instanceof OperationError && reason.code === 'write_outcome_unknown';
+ for (const entry of admissions) settled[entry.index] = { status: 'rejected',
+ reason: unknown ? writeOutcomeUnknown(entry.admission.requestId!, new Error(String(reason.detail ?? reason.message))) : reason };
+ }
});
} catch (reason) {
for (let index = 0; index < params.length; index++) settled[index] ??= { status: 'rejected', reason };
diff --git a/test/persistence-import-batch.test.ts b/test/persistence-import-batch.test.ts
index 12ca289719..cf9f7b36b0 100644
--- a/test/persistence-import-batch.test.ts
+++ b/test/persistence-import-batch.test.ts
@@ -254,13 +254,20 @@ test('a batch admission whose COMMIT acknowledgment is lost replays its admitted
try { settled = await importManagedFiles(brain.engine, once, { sourceId, noEmbed: true }); } finally { restore(); }
expect(drops()).toBe(1);
expect(settled.map(result => result.status === 'fulfilled' && result.value.status)).toEqual(once.map(() => 'imported'));
- expect(await brain.engine.executeRaw("SELECT id FROM persistence_requests WHERE source_id=$1 AND slug LIKE 'once-%'", [sourceId])).toHaveLength(once.length);
+ // The re-run is a read: one row per file, under the request id and digest its durable intent recorded before admission.
+ const recorded = async (prefix: string) => (await brain.engine.executeRaw<{ slug: string; request_id: string; digest: string }>(
+ `SELECT slug,request_id::text AS request_id,digest FROM persistence_requests WHERE source_id=$1 AND slug LIKE $2 ORDER BY slug`, [sourceId, `${prefix}-%`]));
+ expect((await recorded('once')).map(row => row.slug)).toEqual(once.map((_, i) => `once-${i}`));
const always = write(join(home, `${brain.label}-${sourceId}-always`), Object.fromEntries(Array.from({ length: 4 }, (_, i) => [`always-${i}.md`, page(`Always ${i}`)])));
lose(Number.POSITIVE_INFINITY);
try { settled = await importManagedFiles(brain.engine, always, { sourceId, noEmbed: true }); } finally { restore(); }
expect(settled.map(result => result.status === 'rejected' && (result.reason as { code?: string }).code)).toEqual(always.map(() => 'write_outcome_unknown'));
+ const admitted = await recorded('always');
+ expect(admitted).toHaveLength(always.length);
+ // Each file's error names its own request id to read, the one its row was admitted under.
+ expect(settled.map(result => (result as PromiseRejectedResult).reason.fix?.argv?.at(-1))).toEqual(admitted.map(row => row.request_id));
const resumed = await importManagedFiles(brain.engine, always, { sourceId, noEmbed: true });
expect(resumed.map(result => result.status === 'fulfilled' && result.value.status)).toEqual(always.map(() => 'imported'));
- expect(await brain.engine.executeRaw("SELECT id FROM persistence_requests WHERE source_id=$1 AND slug LIKE 'always-%'", [sourceId])).toHaveLength(always.length);
+ expect(await recorded('always')).toEqual(admitted);
}
}), 300_000);