Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes

garrytan4bb01cebc6ac
diff --git a/scripts/function-size-baseline.tsv b/scripts/function-size-baseline.tsv
index ab82f79b56..44bf4a2c36 100644
--- a/scripts/function-size-baseline.tsv
+++ b/scripts/function-size-baseline.tsv
@@ -50,7 +50,6 @@ src/core/minions/worker.ts MinionWorker.start 470 seed: W5 baseline, refactor wa
src/core/ops/facts.ts recall.handler 358 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 #4830 (W14 PR3): every hit names its source_id, falling back to the scope's single source (the federated case stays absent); +3 W5: recall threads the page-unit ranking cut into its hybrid page arm (logic in search/page-rank-cut.ts; delivery reports it); +3 #7043: copies of one claim collapse before the limit cut (the collapse lives in facts/capture-dedup.ts collapseFactReads) and the row names its entity_slugs/collapsed_count; +1 HARN-15: max_chars is parsed before any read (the bound lives in boundRecallChars)
src/core/ops/search.ts query.handler 338 +5 GBRA-81 item 5 per-stage search timings: the request's SearchTimings and setup-stage binding, the image branch's limit read hoisted out of the timed vector call, and its response stage wrapper (collector logic in search/stage-timings.ts); seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +2 GBRA-49 explain_target: one TargetTrace prep line and its HybridSearchOpts thread (diagnosis/meta live in prepareExplainTarget/finishExplainTarget); +1 W5 (#6445): query passes the page-unit ranking cut to hybrid search (logic in search/page-rank-cut.ts), merged with master growth
src/core/persistence/page-prepare.ts prepareInlineOrSegmentedMutation 303 +3 #7841: a put_page that asks for visibility: private is kept or refused (visibility_not_applied), checked before the no-op test and after the trust stamp (logic in persistence/visibility-request.ts)
-src/core/persistence/sync-prepare.ts prepareSyncMutation 301 TODO GBRA-217: +1 the change-reason lookup for a file whose page exists (logic in persistence/sync-reasons.ts managedFileHistory); new row at 301
src/core/progressive-batch/orchestrator.ts runProgressiveBatch 348 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/remediation/run.ts runRemediation 428 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/skillopt/orchestrator.ts runOptimizationLoop 644 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
diff --git a/src/core/persistence/sync-pass-batch.ts b/src/core/persistence/sync-pass-batch.ts
index d2c745b804..128e9442e0 100644
--- a/src/core/persistence/sync-pass-batch.ts
+++ b/src/core/persistence/sync-pass-batch.ts
@@ -66,11 +66,11 @@ export async function passBatchHead(tx: Pick<BrainEngine, 'executeRaw'>, key: st
const NS_SYNC_PASS = Buffer.from('5f0c6712b4a84e0b9d1a2c3e4f5a6712', 'hex');
/**
* `request_id = uuidv5(NS_SYNC_PASS, passId‖path‖level)` (design v3.2 §3.1): a same-pass replay reads the existing receipt.
- * #8729: `retry` (the entry's in-place re-freezes after a failed receipt) names a new request, so a retry prepares the
- * entry again instead of reading the failed receipt back; the first freeze keeps the v1 id.
+ * #8729: `retryOf` (the failed request an in-place re-freeze replaces) names a new request, unique per failed receipt, so
+ * a retry prepares the entry again instead of reading a failed receipt back; the first freeze keeps the v1 id.
*/
-export function passRequestId(passId: string, path: string, level: string | null, retry = 0): string {
- const hash = createHash('sha1').update(NS_SYNC_PASS).update(`sync_pass:v1:${passId.toLowerCase()}\0${path}\0${level ?? ''}${retry > 0 ? `\0retry:${retry}` : ''}`).digest();
+export function passRequestId(passId: string, path: string, level: string | null, retryOf?: string): string {
+ const hash = createHash('sha1').update(NS_SYNC_PASS).update(`sync_pass:v1:${passId.toLowerCase()}\0${path}\0${level ?? ''}${retryOf ? `\0retry:${retryOf.toLowerCase()}` : ''}`).digest();
hash[6] = (hash[6]! & 0x0f) | 0x50;
hash[8] = (hash[8]! & 0x3f) | 0x80;
const hex = hash.subarray(0, 16).toString('hex');
diff --git a/src/core/persistence/sync-prepare.ts b/src/core/persistence/sync-prepare.ts
index e38130bae0..d31268a874 100644
--- a/src/core/persistence/sync-prepare.ts
+++ b/src/core/persistence/sync-prepare.ts
@@ -688,7 +688,7 @@ async function syncWriteState(tx: BrainEngine, row: WriteRequest, page: Paramete
return { ...await sizeStateField(tx, row.source_id, row.slug, page), ...segmentedOutcome(segmented, isQuarantined(frontmatter)) };
}
-/** #8729: a screen (`screening`) publishes nothing, so the segmented staging its import opened is aborted at once, never left live beside the admitted write's. */
+/** #8729: a screen (`screening`) publishes nothing, so the segmented staging its import opened is aborted (unbounded: past the screen's deadline too) as soon as the import hands it over, never left live beside the admitted write's. */
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, { engineReads: true });
@@ -887,14 +887,13 @@ async function prepareSyncMutation(unbounded: BrainEngine, row: WriteRequest, _c
filename: basename(p.sourcePath).replace(/\.mdx?$/i, ''), sourcePath: p.sourcePath, allowEmptyOverwrite: true, history,
segmentedOwner: { kind: 'sync' as const, principalKind: row.principal_kind, principalId: row.principal_id, baseRevision: base?.revision ?? null } };
const result = await importFromContent(engine, renamed?.slug ?? row.slug, importContent, { ...importOptions,
- prepare: async value => { prepared = value; return value.result; } }).catch(error => {
+ prepare: async value => { prepared = value; if (screening) await abortSegmentedStaging(unbounded, value.segmented?.prepared); return value.result; } }).catch(error => {
if (!(error instanceof ContentSanityBlockError)) throw error;
throw syncContentRefusal({ code: 'content_rejected', message: error.message }, row, p);
});
if (!prepared) throw result.refusal ? syncContentRefusal(result.refusal, row, p) : syncPublicationRefusal('invalid_params', result.error ?? 'The sync file could not be prepared.', row, p,
`The file could not be prepared as page ${row.slug}.`);
const ready = prepared;
- if (screening) await abortSegmentedStaging(engine, ready.segmented?.prepared);
if (ready.observedRevision !== (base?.revision ?? null)) throw syncPublicationRefusal('revision_conflict', 'The page changed during sync preparation.', row, p, `Page ${renamed?.slug ?? row.slug} changed while this sync was being prepared.`);
if (ready.slug !== (renamed?.slug ?? row.slug)) {
// Cross-slug dedup must never advance the origin's checkpoint without a
diff --git a/src/core/persistence/sync-run.ts b/src/core/persistence/sync-run.ts
index 8e8fa00abe..1a379b8144 100644
--- a/src/core/persistence/sync-run.ts
+++ b/src/core/persistence/sync-run.ts
@@ -718,7 +718,7 @@ async function refreezeInPlace(engine: BrainEngine, input: SettleInput): Promise
const held = await holdUnderGate(engine, { cursor, key, pending, hold: fresh.hold, assertActive, observedAt, waitMs: input.waitMs, base });
return held === 'pending' ? null : held;
}
- return saveCursor(engine, key, cursor, { ...base, convertedFromFailed: converted, pending: { ...fresh, stops: (pending.stops ?? 0) + 1, requestId: cursor.passId ? passRequestId(cursor.passId, entry.path, (entry as PassEntry).level ?? null, (pending.stops ?? 0) + 1) : fresh.requestId } }, false, assertActive,
+ return saveCursor(engine, key, cursor, { ...base, convertedFromFailed: converted, pending: { ...fresh, stops: (pending.stops ?? 0) + 1, requestId: cursor.passId ? passRequestId(cursor.passId, entry.path, (entry as PassEntry).level ?? null, pending.requestId) : fresh.requestId } }, false, assertActive,
tx => recordSyncConversion(tx, cursor.sourceId, cursor.incarnation, { request_id: pending.requestId, path: pending.intent.path ?? null, slug: pending.slug, run_id: cursor.runId, outcome: 'refrozen' }));
}
diff --git a/test/sync-pass-retry-id-8729.test.ts b/test/sync-pass-retry-id-8729.test.ts
new file mode 100644
index 0000000000..1b89a35fdb
--- /dev/null
+++ b/test/sync-pass-retry-id-8729.test.ts
@@ -0,0 +1,23 @@
+/**
+ * #8729: an in-place re-freeze in a pass takes a request id derived from the failed request it replaces.
+ *
+ * 1. Protects: a retry never reuses a request id whose receipt already failed, even when the entry was frozen again
+ * in the same pass (a hold released) and its re-freeze count started over; the first freeze keeps the v1 id.
+ * 2. Fails when: the retry id is salted with a count that restarts (two refreeze chains share retry ids) or the
+ * first-freeze id changes (a same-pass replay would stop reading its own receipt).
+ */
+import { expect, test } from 'bun:test';
+import { passRequestId } from '../src/core/persistence/sync-pass-batch.ts';
+
+const pass = '6f1d2c3b-4a59-4e6f-8a7b-9c0d1e2f3a4b';
+const failedA = '0b5e8f3a-1c2d-4e5f-8a9b-0c1d2e3f4a5b';
+const failedB = '1c6f9a4b-2d3e-4f60-9bac-1d2e3f4a5b6c';
+
+test('the first freeze keeps the v1 id and each failed request names its own retry', () => {
+ expect(passRequestId(pass, 'conversations/chat-example.md', null)).toBe('e08647ff-1a4d-56ef-b056-dfd637966c9c');
+ const a = passRequestId(pass, 'conversations/chat-example.md', null, failedA);
+ const b = passRequestId(pass, 'conversations/chat-example.md', null, failedB);
+ expect(a).not.toBe(passRequestId(pass, 'conversations/chat-example.md', null));
+ expect(a).not.toBe(b);
+ expect(passRequestId(pass, 'conversations/chat-example.md', null, failedA.toUpperCase())).toBe(a);
+});