Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: a local edit adoption whose caller names no claim token ends as a lost claim
garrytan628f30fc5beb
diff --git a/src/core/persistence/local-edit-adoption.ts b/src/core/persistence/local-edit-adoption.tsindex f8de5a744d..ac0b19bd38 100644--- a/src/core/persistence/local-edit-adoption.ts+++ b/src/core/persistence/local-edit-adoption.ts@@ -207,8 +207,8 @@ export async function adoptedHeadHolds(binding: WorktreeBinding, root: string, p*/export async function assertAdoptionCaller(engine: BrainEngine, row: WriteRequest, caller: { id?: unknown; token?: unknown } | undefined, lock = false): Promise<void> {if (!caller) return;- const [held] = await engine.executeRaw(`SELECT 1 FROM persistence_requests WHERE id=$1::uuid AND state='running' AND execution_token=$2::uuid${lock ? ' FOR SHARE' : ''}`,- [String(caller.id), String(caller.token)]);+ const [held] = typeof caller.id === 'string' && typeof caller.token === 'string' ? await engine.executeRaw(+ `SELECT 1 FROM persistence_requests WHERE id=$1::uuid AND state='running' AND execution_token=$2::uuid${lock ? ' FOR SHARE' : ''}`, [caller.id, caller.token]) : [];if (held) return;throw opError('write_claim_lost', 'The write this local edit adoption was made for no longer waits on it.',`Adoption request ${row.request_id} in source ${row.source_id} belongs to a write whose claim ended (it was cancelled, finished, or reclaimed after its process stopped), so the local edit was not adopted and nothing was written.`);diff --git a/test/adopt-local-edit.test.ts b/test/adopt-local-edit.test.tsindex 2bf6e95138..0777f0f747 100644--- a/test/adopt-local-edit.test.ts+++ b/test/adopt-local-edit.test.ts@@ -594,3 +594,22 @@ test('#8755 n: a conflict or a merge that starts after the adoption prepared keetry { await refused(); } finally { rmSync(join(f.root, '.git', 'MERGE_HEAD'), { force: true }); }}), 180_000);+test('#8755 o: an adoption whose caller names no claim token ends write_claim_lost, not a database error', () => each(async f => {+ const { localEditAdoptionSeams } = await import('../src/core/persistence/local-edit-adoption.ts');+ writeFileSync(join(f.root, 'alpha', 'one.md'), EDITED);+ const before = { head: head(f), revision: await revision(f, 'one') };+ let calls = 0;+ localEditAdoptionSeams.beforePublish = async () => {+ if (calls++) return;+ await f.engine.executeRaw("UPDATE persistence_requests SET intent=jsonb_set(intent, '{adoptLocalEdit,caller,token}', 'null'::jsonb) WHERE source_id=$1 AND intent ? 'adoptLocalEdit'", [f.alpha]);+ throw Object.assign(new Error('could not serialize access due to concurrent update'), { code: '40001' });+ };+ await timeline(f)().catch(() => undefined);+ expect(calls).toBe(1);+ const [adoption] = await adoptionRows(f);+ expect(adoption).toMatchObject({ state: 'failed', error_code: 'write_claim_lost' });+ expect(file(f, 'one.md')).toBe(EDITED);+ expect(head(f)).toBe(before.head);+ expect(await revision(f, 'one')).toBe(before.revision);+}), 180_000);+