Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: pre-landing review fixes (a bulk import group is admitted past writes held behind it)
garrytan65b5e6194f55
diff --git a/src/core/persistence/journal.ts b/src/core/persistence/journal.tsindex 0851250a21..54b4f43d26 100644--- a/src/core/persistence/journal.ts+++ b/src/core/persistence/journal.ts@@ -431,11 +431,13 @@ export async function admitWriteGroupInTransaction(tx: BrainEngine, inputs: Writconst schemaRefusal = await schemaAdmissionRefusal(tx);if (schemaRefusal) throw schemaRefusal;const bytes = fresh.reduce((sum, item) => sum + item.bytes, 0), terminalBytes = fresh.reduce((sum, item) => sum + item.terminalBytes, 0);+ const syncGroup = fresh.every(item => managedSyncJob(item.input));for (const row of counters) {const brain = row.key === 'brain', scope = brain ? 'brain' : 'principal';- const outstanding = await outstandingRefusal(tx, row, first.principal, first.sourceId, fresh.length, brain ? limits.brainOutstanding : limits.principalOutstanding);+ const held = syncGroup ? await heldBehindImport(tx, brain ? null : first.principal) : { count: 0, bytes: 0 };+ const outstanding = await outstandingRefusal(tx, row, first.principal, first.sourceId, fresh.length, brain ? limits.brainOutstanding : limits.principalOutstanding, held.count);if (outstanding) throw outstanding;- if (Number(row.intent_bytes) + bytes > (brain ? limits.brainIntentBytes : limits.principalIntentBytes)) throw capacityError(`${scope} intent bytes`);+ if (Number(row.intent_bytes) - held.bytes + bytes > (brain ? limits.brainIntentBytes : limits.principalIntentBytes)) throw capacityError(`${scope} intent bytes`);if (Number(row.lifetime_ids) + fresh.length > limits[`${scope}LifetimeIds`]) throw await cumulativeCapacityError(tx, `${scope} permanent request IDs`,row.key, `${scope}LifetimeIds`, Number(row.lifetime_ids), limits[`${scope}LifetimeIds`]);if (Number(row.terminal_bytes) + terminalBytes > limits[`${scope}TerminalBytes`]) throw await cumulativeCapacityError(tx, `${scope} reserved receipt bytes`,diff --git a/test/import-write-barrier.test.ts b/test/import-write-barrier.test.tsindex 222300e329..673ddcf6ec 100644--- a/test/import-write-barrier.test.ts+++ b/test/import-write-barrier.test.ts@@ -422,6 +422,22 @@ test('a write held for an import never takes the capacity the import needs', ()}), 180_000);+test('a write held for an import never takes the capacity a bulk import group needs', () => each(async f => {+ await f.engine.setConfig('persistence.limits.principal_outstanding', '2');+ try {+ for (const name of ['one', 'two', 'three']) foreignCommit(f, `${name}.md`, page(`Alpha ${name}`, IMPORTED));+ const out = await local(f, 'put_page', { slug: 'one', content: page('Alpha one', 'Mine, held while a bulk group imports.') });+ const held = await requestRow(f, out.receipt.request_id);+ expect(held.state).toBe('deferred');+ await performManagedSync(f.engine, { sourceId: f.alpha, noPull: true, noEmbed: true,+ bulk: { enabled: true, reason: null, size: 16, maxTxnMs: 15_000, maxTxnExplicit: false } } as never);+ expect(await f.lastCommit(f.alpha)).toBe(git(f.root, 'rev-parse', 'HEAD'));+ expect((await settle(f, held)).state).toBe('committed');+ } finally {+ await f.engine.executeRaw("DELETE FROM config WHERE key='persistence.limits.principal_outstanding'");+ }+}), 180_000);+test('GST-1623: an import and a new hold between the expiry scan and its lock never expire the new hold', () => each(async f => {foreignCommit(f, 'one.md', page('Alpha one', IMPORTED));const out = await local(f, 'put_page', { slug: 'one', content: page('Alpha one', 'Mine, held again after an import.') });