Skip to content

Commit 77d17b1

Browse files
fix(provider-acp-registry): prepared binary agents stay ready when the registry advances (pingdotgg#26543)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent bff276e commit 77d17b1

2 files changed

Lines changed: 100 additions & 12 deletions

File tree

‎packages/provider-acp-registry/src/server/AcpRegistrySupport.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,70 @@ describe("AcpRegistrySupport", () => {
622622
);
623623
});
624624

625+
it.effect("keeps a prepared binary ready after the registry advances its version", () => {
626+
const makeBinaryAgent = (version: string) => ({
627+
...makeAgent({
628+
binary: {
629+
"linux-x86_64": {
630+
archive: `https://registry.test/example-agent-${version}.bin`,
631+
cmd: "./bin/example-agent",
632+
},
633+
},
634+
}),
635+
version,
636+
});
637+
let agent = makeBinaryAgent("1.2.3");
638+
return Effect.gen(function* () {
639+
const fileSystem = yield* FileSystem.FileSystem;
640+
const cacheDir = yield* fileSystem.makeTempDirectoryScoped({
641+
prefix: "t3-acp-registry-advance-",
642+
});
643+
const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
644+
cacheDir,
645+
toolsDir: `${cacheDir}/tools`,
646+
registryUrl,
647+
});
648+
yield* resolver.prepare({ agentId: agent.id });
649+
650+
agent = makeBinaryAgent("1.2.4");
651+
yield* TestClock.adjust("6 minutes");
652+
yield* resolver.search({ query: "example" });
653+
654+
expect(yield* resolver.inspect(settings())).toMatchObject({
655+
status: "ready",
656+
distribution: "binary",
657+
});
658+
const resolved = yield* resolver.resolve(settings(), "/workspace", {});
659+
expect(resolved.spawn.command).toContain(
660+
"/tools/example-agent/1.2.4/linux-x86_64/bin/example-agent",
661+
);
662+
expect(yield* fileSystem.readFileString(resolved.spawn.command)).toBe(
663+
"#!/bin/sh\necho 1.2.4\n",
664+
);
665+
666+
expect(yield* resolver.uninstallManagedBinary({ agentId: agent.id })).toMatchObject({
667+
removed: true,
668+
});
669+
expect(yield* resolver.inspect(settings())).toMatchObject({ status: "unprepared" });
670+
}).pipe(
671+
Effect.scoped,
672+
Effect.provide(
673+
layerResolver((request) =>
674+
Effect.succeed(
675+
HttpClientResponse.fromWeb(
676+
request,
677+
new Response(
678+
request.url === registryUrl
679+
? makeRegistry(agent)
680+
: `#!/bin/sh\necho ${agent.version}\n`,
681+
),
682+
),
683+
),
684+
),
685+
),
686+
);
687+
});
688+
625689
it.effect(
626690
"prepares the registry version despite an older PATH binary and permits explicit overrides",
627691
() => {

‎packages/provider-acp-registry/src/server/AcpRegistrySupport.ts‎

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,27 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
13931393
};
13941394
};
13951395

1396+
const hasInstalledBinaryVersion = Effect.fn("AcpRegistryCatalog.hasInstalledBinaryVersion")(
1397+
function* (agentId: string) {
1398+
const agentRoot = path.join(installsDirectory, agentId);
1399+
const versions = yield* fileSystem
1400+
.readDirectory(agentRoot)
1401+
.pipe(Effect.orElseSucceed((): Array<string> => []));
1402+
for (const version of versions) {
1403+
for (const candidateTarget of resolveAcpRegistryPlatformTargetCandidates(platformTarget)) {
1404+
if (
1405+
yield* fileSystem
1406+
.exists(path.join(agentRoot, version, candidateTarget))
1407+
.pipe(Effect.orElseSucceed(() => false))
1408+
) {
1409+
return true;
1410+
}
1411+
}
1412+
}
1413+
return false;
1414+
},
1415+
);
1416+
13961417
const installBinary = Effect.fn("AcpRegistryCatalog.installBinary")(function* (
13971418
agent: AcpRegistryAgent,
13981419
target: typeof AcpRegistryBinaryTarget.Type,
@@ -1773,25 +1794,28 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
17731794
const exists = yield* fileSystem
17741795
.exists(paths.executablePath)
17751796
.pipe(Effect.orElseSucceed(() => false));
1776-
if (!exists) {
1797+
// Any prepared version keeps the agent ready; resolve installs the current one on demand.
1798+
if (!exists && !(yield* hasInstalledBinaryVersion(agent.id))) {
17771799
return {
17781800
status: "unprepared",
17791801
agentId,
17801802
version: agent.version,
17811803
distribution: "binary",
17821804
} as const;
17831805
}
1784-
yield* assertExecutableInRoot(paths.installRoot, paths.executablePath).pipe(
1785-
Effect.mapError((cause) =>
1786-
isAcpRegistryError(cause)
1787-
? cause
1788-
: new AcpRegistryError({
1789-
reason: "install_failed",
1790-
detail: `Could not validate cached ACP Registry agent ${agent.id}.`,
1791-
cause,
1792-
}),
1793-
),
1794-
);
1806+
if (exists) {
1807+
yield* assertExecutableInRoot(paths.installRoot, paths.executablePath).pipe(
1808+
Effect.mapError((cause) =>
1809+
isAcpRegistryError(cause)
1810+
? cause
1811+
: new AcpRegistryError({
1812+
reason: "install_failed",
1813+
detail: `Could not validate cached ACP Registry agent ${agent.id}.`,
1814+
cause,
1815+
}),
1816+
),
1817+
);
1818+
}
17951819
return {
17961820
status: "ready",
17971821
agentId,

0 commit comments

Comments
 (0)