Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Find a deferred default-pack adoption on init retry, and count housekeeping's two reads in the maintenance pass
garrytanffc7704cd8dd
diff --git a/src/core/shared-skills/setup.ts b/src/core/shared-skills/setup.tsindex 2dc49a0a88..6fa5272f4f 100644--- a/src/core/shared-skills/setup.ts+++ b/src/core/shared-skills/setup.ts@@ -242,7 +242,7 @@ export async function installPackagedSharedSkills(ctx: OperationContext, sourceIconst principal = await requestPrincipalForContext(ctx);const [open] = await ctx.engine.executeRaw<WriteRequest>(`SELECT r.* FROM persistence_requests r JOIN sources s ON s.id=r.source_id AND s.incarnation=r.source_incarnationWHERE r.operation='put_skill' AND r.source_id=$1 AND r.principal_kind=$2 AND r.principal_id=$3 AND r.intent->>'pack_id'=$4- AND r.authority ? 'skillAdoptionPreconditions' AND r.state IN ('queued','running','recovering','committed') ORDER BY r.sequence DESC LIMIT 1`,+ AND r.authority ? 'skillAdoptionPreconditions' AND r.state IN ('queued','deferred','running','recovering','committed') ORDER BY r.sequence DESC LIMIT 1`,[sourceId, principal.kind, principal.id, DEFAULT_SHARED_PACK_ID]);const resumed = open ? await waitForWrite(ctx.engine, open, ctx.config, ctx.writeWaitMs) : null;if (resumed?.state === 'committed') return;diff --git a/test/persistence-consumer-idle.test.ts b/test/persistence-consumer-idle.test.tsindex eb9ce5eaf3..b43c83a417 100644--- a/test/persistence-consumer-idle.test.ts+++ b/test/persistence-consumer-idle.test.ts@@ -120,7 +120,7 @@ test('idle polling backs off to the cap, then a wake runs a full tick immediatelconst firstTick = statements.length;counted.resolve();// The first full tick carries the maintenance pass; a statement added to that pass changes this count on purpose.- expect(firstTick - bare.statements.length).toBe(8);+ expect(firstTick - bare.statements.length).toBe(10);await Bun.sleep(2_000);// 20 ms polling for 2 s would be ~100 ticks; doubling to a 160 ms cap is ~15.expect(statements.length - firstTick).toBeLessThan(40);diff --git a/test/shared-skills-packaged-key-7734.test.ts b/test/shared-skills-packaged-key-7734.test.tsindex 0cecff669c..1c8125405a 100644--- a/test/shared-skills-packaged-key-7734.test.ts+++ b/test/shared-skills-packaged-key-7734.test.ts@@ -118,3 +118,21 @@ test('#8453: an init retried after an upgrade keeps the pack an earlier releaseexpect(await requestIds(f.engine)).toEqual(admitted);expect((await f.engine.executeRaw<{ state: string }>("SELECT state FROM persistence_requests WHERE operation='put_skill'")).map((r) => r.state)).toEqual(['committed']);}), 120_000);++test('#8453: an init retried while the earlier adoption is deferred behind a refresh reports it pending instead of admitting a second', () => fixture(async (f) => {+ const older = packaged((files) => { for (const path of ['skillpack.json', 'README.md']) files[path] = files[path].replaceAll(VERSION, '0.0.1.0'); });+ const broken = interrupted(f.local, () => Object.assign(new Error('canceling statement due to statement timeout'), { code: '57014' }));+ await adoptSharedSkillpack(broken, 'default', older).catch(() => undefined);+ await disposePersistenceConsumer(broken.engine);+ await disposePersistenceConsumer(f.engine);+ const admitted = await requestIds(f.engine);+ expect(admitted).toHaveLength(1);+ // A write admitted during a worktree refresh waits as deferred until the refresh releases it; it is still the open adoption.+ await f.engine.transaction(async (tx) => {+ await tx.executeRaw('SET LOCAL session_replication_role = replica');+ await tx.executeRaw("UPDATE persistence_requests SET state='deferred' WHERE operation='put_skill'");+ });+ const error = await installPackagedSharedSkills({ ...f.local, writeWaitMs: 50 }, 'default').then(() => null, (e: unknown) => e);+ expect((error as { code?: string } | null)?.code).toBe('publication_pending');+ expect(await requestIds(f.engine)).toEqual(admitted);+}), 120_000);