Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence,sync): receipt health tells lane groups apart without reading intent; nothing frozen ahead before the first commit (#5984 G3)

garrytan4d4079a7445d
diff --git a/src/core/persistence/journal.ts b/src/core/persistence/journal.ts
index ef0e27f804..4dbf0496b3 100644
--- a/src/core/persistence/journal.ts
+++ b/src/core/persistence/journal.ts
@@ -817,7 +817,7 @@ export async function writeHealthFacts(engine: BrainEngine, rows: WriteRequest[]
AND (s.state IN ('running','recovering') OR s.recovery IS NOT NULL) ORDER BY s.sequence LIMIT 1) AS started_sequence,
(SELECT s.sequence FROM persistence_requests s WHERE s.worktree_id=w.id
AND (s.state IN ('running','recovering') OR s.recovery IS NOT NULL)
- AND NOT (s.state='running' AND s.recovery IS NULL AND s.intent ? 'lane') ORDER BY s.sequence LIMIT 1) AS started_unlaned,
+ AND NOT (s.state='running' AND s.recovery IS NULL AND s.operation='submit_job') ORDER BY s.sequence LIMIT 1) AS started_unlaned,
${STUCK_RECOVERY('r')} AS recovering,
r.blocked_reason IN ('unexpected_file_bytes','unexpected_staging_bytes') AS inspect_owner FROM persistence_requests r
WHERE r.worktree_id=w.id AND (r.state IN ('queued','running','recovering') OR r.recovery IS NOT NULL)
@@ -841,8 +841,8 @@ export async function writeHealthFacts(engine: BrainEngine, rows: WriteRequest[]
for (const row of pending) {
const fact = byRoot.get(row.worktree_id ?? `db:${row.source_incarnation}`);
if (!fact) continue;
- // #5984 Phase 4.5: a foreground write publishing beside running lane groups is not waiting on them.
- const head = row.state === 'queued' ? fact.sequence : row.worktree_id && !String(row.intent?.kind ?? '').startsWith('managed_sync_') ? fact.started_unlaned : fact.started_sequence;
+ // #5984 Phase 4.5: a foreground write publishing beside running lane groups (claimed sync jobs) is not waiting on them.
+ const head = row.state === 'queued' ? fact.sequence : row.worktree_id && row.operation !== 'submit_job' ? fact.started_unlaned : fact.started_sequence;
result.set(row.id, { observed_at, recovery_required: fact.recovery_required,
owner_unavailable: fact.owner_unavailable,
inspect_owner: fact.inspect_owner,
diff --git a/src/core/persistence/sync-run.ts b/src/core/persistence/sync-run.ts
index 80ca557156..b9b32dca0c 100644
--- a/src/core/persistence/sync-run.ts
+++ b/src/core/persistence/sync-run.ts
@@ -704,6 +704,9 @@ async function admitAhead(engine: BrainEngine, cursor: Cursor, key: string, bulk
if (!bulk.settings.enabled || !cursor.group?.length) return cursor;
const lane = laneRunOf(cursor, bulk);
// With lanes, twice the lane count stays admitted, so lanes never wait for the sync side to freeze the next group.
+ // Nothing is frozen ahead until the run's first page commits, so the first group publishes without competing for
+ // connections and the event loop (#5984 G3).
+ if (cursor.counts.added + cursor.counts.modified + cursor.counts.deleted === 0) return cursor;
const depth = lane ? 2 * Math.max(1, lanePolicy(cursor.binding.worktree_id)?.effective ?? 1) : 1;
let current = cursor, foregroundChecked = false;
for (let slot = 0; ; slot++) {
diff --git a/test/persistence-diagnostics.test.ts b/test/persistence-diagnostics.test.ts
index 7bf5581e14..e716d10f4c 100644
--- a/test/persistence-diagnostics.test.ts
+++ b/test/persistence-diagnostics.test.ts
@@ -200,14 +200,15 @@ test('#5984 4.5: a foreground write publishing beside running lane groups is not
const worktree = randomUUID();
await engine.executeRaw("INSERT INTO persistence_worktrees(id,owner_host_id,state) VALUES($1,$2,'active')", [worktree, randomUUID()]);
await engine.executeRaw('UPDATE persistence_requests SET worktree_id=$2 WHERE id=ANY($1::uuid[])', [[lane.id, foreground.id], worktree]);
+ await engine.executeRaw("UPDATE persistence_requests SET operation='submit_job' WHERE id=$1::uuid", [lane.id]);
await engine.executeRaw("UPDATE persistence_requests SET state='running',execution_token=gen_random_uuid() WHERE id=ANY($1::uuid[])", [[lane.id, foreground.id]]);
const earlier = async () => {
const rows = await engine.executeRaw<WriteRequest>('SELECT * FROM persistence_requests WHERE id=$1::uuid', [foreground.id]);
return (await writeHealthFacts(engine, rows)).get(foreground.id)?.earlier_write;
};
expect(await earlier()).toBe(false);
- // A running sync row outside a lane run (the single path, which holds the worktree alone) still comes first.
- await engine.executeRaw("UPDATE persistence_requests SET intent=intent-'lane' WHERE id=$1::uuid", [lane.id]);
+ // A recovering sync row still comes first.
+ await engine.executeRaw("UPDATE persistence_requests SET state='recovering' WHERE id=$1::uuid", [lane.id]);
expect(await earlier()).toBe(true);
await engine.executeRaw("UPDATE persistence_requests SET state='cancelled',execution_token=NULL,completed_at=now() WHERE id=ANY($1::uuid[])", [[lane.id, foreground.id]]);
}