Skip to content

Commit 95e34fa

Browse files
only21milclaude
andcommitted
fix(acp-registry): installing one agent no longer blocks other registry agents
All ACP Registry install work shared one permit, so while one agent downloaded its binary or ran a package install, sessions and status checks for every other registry agent waited behind it. Each agent now takes its own permit. Work on the same agent stays serialized. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5ffe045 commit 95e34fa

2 files changed

Lines changed: 81 additions & 7 deletions

File tree

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,73 @@ describe("AcpRegistrySupport", () => {
14451445
});
14461446
});
14471447

1448+
it.effect("resolves an agent while another agent's download is still running", () => {
1449+
const slowArchiveUrl = "https://registry.test/slow-agent.bin";
1450+
const agent = makeAgent({
1451+
binary: { "linux-x86_64": { archive: archiveUrl, cmd: "./bin/example-agent" } },
1452+
});
1453+
const slowAgent = {
1454+
...makeAgent({
1455+
binary: { "linux-x86_64": { archive: slowArchiveUrl, cmd: "./bin/slow-agent" } },
1456+
}),
1457+
id: "slow-agent",
1458+
name: "Slow Agent",
1459+
};
1460+
const binaryBytes = new TextEncoder().encode("#!/bin/sh\necho example\n");
1461+
return Effect.gen(function* () {
1462+
const downloadStarted = yield* Deferred.make<void>();
1463+
const releaseDownload = yield* Deferred.make<void>();
1464+
return yield* Effect.gen(function* () {
1465+
const fileSystem = yield* FileSystem.FileSystem;
1466+
const cacheDir = yield* fileSystem.makeTempDirectoryScoped({
1467+
prefix: "t3-acp-registry-parallel-install-",
1468+
});
1469+
const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
1470+
cacheDir,
1471+
toolsDir: `${cacheDir}/tools`,
1472+
registryUrl,
1473+
});
1474+
1475+
const prepareFiber = yield* resolver
1476+
.prepare({ agentId: slowAgent.id })
1477+
.pipe(Effect.forkChild({ startImmediately: true }));
1478+
yield* Deferred.await(downloadStarted);
1479+
1480+
const resolved = yield* resolver.resolve(settings(), "/workspace");
1481+
expect(resolved.spawn.command).toContain(
1482+
"/tools/example-agent/1.2.3/linux-x86_64/bin/example-agent",
1483+
);
1484+
expect(prepareFiber.pollUnsafe()).toBeUndefined();
1485+
1486+
yield* Deferred.succeed(releaseDownload, undefined);
1487+
expect(yield* Fiber.join(prepareFiber)).toMatchObject({ prepared: true });
1488+
}).pipe(
1489+
Effect.scoped,
1490+
Effect.provide(
1491+
layerResolver((request) => {
1492+
if (request.url === registryUrl) {
1493+
return Effect.succeed(
1494+
HttpClientResponse.fromWeb(
1495+
request,
1496+
new Response(JSON.stringify({ version: "1.0.0", agents: [slowAgent, agent] })),
1497+
),
1498+
);
1499+
}
1500+
const response = HttpClientResponse.fromWeb(
1501+
request,
1502+
new Response(binaryBytes.buffer as ArrayBuffer),
1503+
);
1504+
if (request.url !== slowArchiveUrl) return Effect.succeed(response);
1505+
return Deferred.succeed(downloadStarted, undefined).pipe(
1506+
Effect.andThen(Deferred.await(releaseDownload)),
1507+
Effect.as(response),
1508+
);
1509+
}),
1510+
),
1511+
);
1512+
});
1513+
});
1514+
14481515
it.effect("reserves a prepared binary until a configured instance inspects it", () => {
14491516
const agent = makeAgent({
14501517
binary: {

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,14 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
662662
const registryRef = yield* Ref.make<AcpRegistryIndex | undefined>(undefined);
663663
const registryRevision = yield* Ref.make(0);
664664
const registrySemaphore = yield* Semaphore.make(1);
665-
const installSemaphore = yield* Semaphore.make(1);
665+
// Downloads and package installs can take minutes, so each agent waits only
666+
// for its own install work, not for another agent's.
667+
const installPermits = new Map<string, Semaphore.Semaphore>();
668+
const withInstallPermit = (agentId: string) => {
669+
const permit = installPermits.get(agentId) ?? Semaphore.makeUnsafe(1);
670+
installPermits.set(agentId, permit);
671+
return permit.withPermits(1);
672+
};
666673
const preparedBinaryReservations = yield* Ref.make<ReadonlyMap<string, number>>(new Map());
667674

668675
const managerBinDirectory = Effect.fn("AcpRegistryCatalog.managerBinDirectory")(function* (
@@ -1646,13 +1653,13 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
16461653
if (distribution.kind === "binary") {
16471654
// A PATH executable can be a different version with different ACP
16481655
// capabilities. Only an explicit command override opts into that copy.
1649-
yield* installSemaphore.withPermits(1)(
1656+
yield* withInstallPermit(agent.id)(
16501657
installBinary(agent, distribution.binaryTarget!).pipe(
16511658
Effect.tap(() => reservePreparedBinary(agent.id)),
16521659
),
16531660
);
16541661
} else {
1655-
yield* installSemaphore.withPermits(1)(
1662+
yield* withInstallPermit(agent.id)(
16561663
ensureGlobalPackage(agent, distribution.kind, distribution.packageName!, hostEnvironment),
16571664
);
16581665
}
@@ -1729,7 +1736,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
17291736
}
17301737

17311738
if (distribution.kind === "binary") {
1732-
return yield* installSemaphore.withPermits(1)(
1739+
return yield* withInstallPermit(agent.id)(
17331740
Effect.gen(function* () {
17341741
const paths = binaryPaths(agent, distribution.binaryTarget!);
17351742
if (paths === undefined) {
@@ -1841,7 +1848,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
18411848
command = resolvedOverride;
18421849
args = distribution.args;
18431850
} else if (distribution.kind === "npx" || distribution.kind === "uvx") {
1844-
const installed = yield* installSemaphore.withPermits(1)(
1851+
const installed = yield* withInstallPermit(agent.id)(
18451852
ensureGlobalPackage(
18461853
agent,
18471854
distribution.kind,
@@ -1854,7 +1861,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
18541861
commandBinDirectory = installed.binDirectory;
18551862
} else {
18561863
const target = distribution.binaryTarget!;
1857-
command = yield* installSemaphore.withPermits(1)(
1864+
command = yield* withInstallPermit(agent.id)(
18581865
installBinary(agent, target).pipe(
18591866
Effect.tap(() => consumePreparedBinaryReservation(agent.id)),
18601867
),
@@ -1887,7 +1894,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
18871894
const uninstallManagedBinary: AcpRegistryCatalog["Service"]["uninstallManagedBinary"] = (input) =>
18881895
hostSettings
18891896
.withSnapshot((settings) =>
1890-
installSemaphore.withPermits(1)(
1897+
withInstallPermit(input.agentId)(
18911898
Effect.gen(function* () {
18921899
const safeAgentId = yield* decodeBoundedAgentId(input.agentId).pipe(
18931900
Effect.mapError(

0 commit comments

Comments
 (0)