Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(#6712 PR 4b): a pass's in-flight wait covers a put_page's pending Git effect

garrytana1a42b9b0e0b
diff --git a/src/core/persistence/sync-pass-run.ts b/src/core/persistence/sync-pass-run.ts
index 3672e4aa59..ee389ce965 100644
--- a/src/core/persistence/sync-pass-run.ts
+++ b/src/core/persistence/sync-pass-run.ts
@@ -263,14 +263,16 @@ async function batchEntries(engine: BrainEngine, level: ShadowLevel, deletes: Sh
async function awaitInFlight(engine: BrainEngine, level: ShadowLevel, inFlight: ShadowPath[], budgetMs: number, assertActive: () => void): Promise<{ added: number; modified: number; deleted: number; renamed: number }> {
const pageIds = inFlight.flatMap(entry => entry.pageId === null ? [] : [entry.pageId]);
const origins = inFlight.map(entry => entryPaths(level, entry.path).sourcePath);
- const names = `r.page_id=ANY($2::int[]) OR r.intent->>'sourcePath'=ANY($3::text[])`;
+ const names = `r.page_id=ANY($2::int[]) OR r.intent->>'sourcePath'=ANY($3::text[]) OR r.intent->>'path'=ANY($3::text[])`;
const opened = await engine.executeRaw<{ id: string }>(`SELECT r.id FROM persistence_requests r WHERE r.source_id=$1 AND r.state IN ('queued','running','recovering') AND (${names})`,
[level.sourceId, pageIds, origins]);
const until = Date.now() + budgetMs;
while (Date.now() < until) {
- const [open] = await engine.executeRaw(`SELECT 1 FROM persistence_requests r WHERE r.source_id=$1 AND (r.state IN ('queued','running','recovering')
- OR EXISTS (SELECT 1 FROM persistence_effects e WHERE e.request_id=r.id AND e.kind='git' AND e.state IN ('queued','running')))
- AND (${names}) LIMIT 1`, [level.sourceId, pageIds, origins]);
+ // The open work readOpenWork marked: an open request, or a pending Git effect named by its request or its relative_path
+ // (a put_page that created its page records no page_id or origin on the request).
+ const [open] = await engine.executeRaw(`SELECT 1 FROM persistence_requests r WHERE r.source_id=$1 AND (r.state IN ('queued','running','recovering') AND (${names})
+ OR EXISTS (SELECT 1 FROM persistence_effects e WHERE e.request_id=r.id AND e.kind='git' AND e.state IN ('queued','running')
+ AND (${names} OR e.data->>'relative_path'=ANY($3::text[])))) LIMIT 1`, [level.sourceId, pageIds, origins]);
assertActive();
if (!open) break;
await new Promise(resolve => setTimeout(resolve, 100));
diff --git a/test/sync-pass-live-6712.test.ts b/test/sync-pass-live-6712.test.ts
index f7be746dea..61c0f4a312 100644
--- a/test/sync-pass-live-6712.test.ts
+++ b/test/sync-pass-live-6712.test.ts
@@ -12,6 +12,7 @@
*
* - probe 49: a re-screen-due hold alone runs a hold-only round (not a full round), which clears it.
* - item 7: a local CLI pass waits (to 30 s) on its own write while this process's consumer holds it or has yet to claim it.
+ * - in-flight wait: the pass waits on the open work it classified, a pending Git effect included, before stopping writer_pending.
* - probe 46 (reparse half): a parser change on a fileSame and dbSame page is a `reparse`: re-imported, no hold.
* - probe 48: a request admitted before the stamp that publishes after it (`open_at_stamp`) makes the next tick a full round, not idle.
* - probe 53: a repair that changes a candidate mid-pass meets no busy refusal (busy is open requests only), and the path
@@ -142,6 +143,18 @@ describe('#6712 PR 4b live pass fences (pglite)', () => {
expect((await engine.readPageSnapshot('notes/a', { sourceId: 'default' }))?.page.compiled_truth).toContain('admitted while the consumer is busy');
}, { setup }), 180_000);
+ test('in-flight wait: a pass waits out a put_page\'s pending Git effect (its request names no page or origin), then imports the committed change', () => managedBrain(async ({ engine, ctx, root }) => {
+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');
+ await submitPageMutation(ctx, { operation: 'put_page', params: { slug: 'notes/d', request_id: randomUUID(), content: note('notes/d', 'The body put_page wrote.') } });
+ // The page's Git effect is still pending (its publication landed; the commit is 2 s out) when an agent commits a change.
+ const held = await engine.executeRaw("UPDATE persistence_effects SET next_attempt_at=now()+interval '2 seconds' WHERE kind='git' AND state='queued' AND set_config('gbrain.persistence_protocol','2',true)='2' RETURNING id");
+ expect(held).toHaveLength(1);
+ writeFileSync(join(root, 'notes/d.md'), note('notes/d', 'A committed agent change of notes/d.')); commit(root, 'agent change of d');
+ const synced = await performManagedSync(engine, OPTS);
+ expect({ status: synced.status, reason: synced.reason, held: synced.held ?? [] }).toEqual({ status: 'synced', reason: undefined, held: [] });
+ expect((await engine.readPageSnapshot('notes/d', { sourceId: 'default' }))?.page.compiled_truth).toContain('A committed agent change of notes/d.');
+ }, { setup: hardened }), 180_000);
+
test('a sliced pass that yields writer_yield reports the entries it settled in the stopped round', () => managedBrain(async ({ engine, root }) => {
expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');
for (const slug of ['a', 'b', 'c']) writeFileSync(join(root, `notes/${slug}.md`), note(`notes/${slug}`, `An edit of notes/${slug}.`));