Skip to content

Commit 5b0cf58

Browse files
only21milclaudemaria-rcks
authored
fix(acp-registry): installing one agent no longer blocks other agents (pingdotgg#23684)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent e2a6267 commit 5b0cf58

2 files changed

Lines changed: 83 additions & 7 deletions

File tree

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,76 @@ describe("AcpRegistrySupport", () => {
15471547
});
15481548
});
15491549

1550+
it.effect("resolves an installed agent while another agent's download is still running", () => {
1551+
const slowArchiveUrl = "https://registry.test/slow-agent.bin";
1552+
const agent = makeAgent({
1553+
binary: { "linux-x86_64": { archive: archiveUrl, cmd: "./bin/example-agent" } },
1554+
});
1555+
const slowAgent = {
1556+
...agent,
1557+
distribution: {
1558+
binary: { "linux-x86_64": { archive: slowArchiveUrl, cmd: "./bin/slow-agent" } },
1559+
},
1560+
id: "slow-agent",
1561+
name: "Slow Agent",
1562+
};
1563+
const binaryBytes = new TextEncoder().encode("#!/bin/sh\necho example\n");
1564+
return Effect.gen(function* () {
1565+
const downloadStarted = yield* Deferred.make<void>();
1566+
const releaseDownload = yield* Deferred.make<void>();
1567+
return yield* Effect.gen(function* () {
1568+
const fileSystem = yield* FileSystem.FileSystem;
1569+
const cacheDir = yield* fileSystem.makeTempDirectoryScoped({
1570+
prefix: "t3-acp-registry-parallel-install-",
1571+
});
1572+
const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
1573+
cacheDir,
1574+
toolsDir: `${cacheDir}/tools`,
1575+
registryUrl,
1576+
});
1577+
1578+
yield* resolver.resolve(settings(), "/workspace");
1579+
1580+
const prepareFiber = yield* resolver
1581+
.prepare({ agentId: slowAgent.id })
1582+
.pipe(Effect.forkChild({ startImmediately: true }));
1583+
yield* Deferred.await(downloadStarted);
1584+
1585+
const resolved = yield* resolver.resolve(settings(), "/workspace");
1586+
expect(resolved.spawn.command).toContain(
1587+
"/tools/example-agent/1.2.3/linux-x86_64/bin/example-agent",
1588+
);
1589+
expect(prepareFiber.pollUnsafe()).toBeUndefined();
1590+
1591+
yield* Deferred.succeed(releaseDownload, undefined);
1592+
expect(yield* Fiber.join(prepareFiber)).toMatchObject({ prepared: true });
1593+
}).pipe(
1594+
Effect.scoped,
1595+
Effect.provide(
1596+
layerResolver((request) => {
1597+
if (request.url === registryUrl) {
1598+
return Effect.succeed(
1599+
HttpClientResponse.fromWeb(
1600+
request,
1601+
new Response(JSON.stringify({ version: "1.0.0", agents: [slowAgent, agent] })),
1602+
),
1603+
);
1604+
}
1605+
const response = HttpClientResponse.fromWeb(
1606+
request,
1607+
new Response(binaryBytes.buffer as ArrayBuffer),
1608+
);
1609+
if (request.url !== slowArchiveUrl) return Effect.succeed(response);
1610+
return Deferred.succeed(downloadStarted, undefined).pipe(
1611+
Effect.andThen(Deferred.await(releaseDownload)),
1612+
Effect.as(response),
1613+
);
1614+
}),
1615+
),
1616+
);
1617+
});
1618+
});
1619+
15501620
it.effect("reserves a prepared binary until a configured instance inspects it", () => {
15511621
const agent = makeAgent({
15521622
binary: {

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,13 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
668668
const registryFetchedAtMs = yield* Ref.make<number | undefined>(undefined);
669669
const registryRevision = yield* Ref.make(0);
670670
const registrySemaphore = yield* Semaphore.make(1);
671-
const installSemaphore = yield* Semaphore.make(1);
671+
// Long installs must only block operations on the same agent.
672+
const installPermits = new Map<string, Semaphore.Semaphore>();
673+
const withInstallPermit = (agentId: string) => {
674+
const permit = installPermits.get(agentId) ?? Semaphore.makeUnsafe(1);
675+
installPermits.set(agentId, permit);
676+
return permit.withPermits(1);
677+
};
672678
const preparedBinaryReservations = yield* Ref.make<ReadonlyMap<string, number>>(new Map());
673679

674680
const managerBinDirectory = Effect.fn("AcpRegistryCatalog.managerBinDirectory")(function* (
@@ -1671,13 +1677,13 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
16711677
const distribution = yield* compatibleDistribution(agent, "auto");
16721678
if (distribution.kind === "binary") {
16731679
// Only explicit command overrides may use PATH copies with different ACP capabilities.
1674-
yield* installSemaphore.withPermits(1)(
1680+
yield* withInstallPermit(agent.id)(
16751681
installBinary(agent, distribution.binaryTarget!).pipe(
16761682
Effect.tap(() => reservePreparedBinary(agent.id)),
16771683
),
16781684
);
16791685
} else {
1680-
yield* installSemaphore.withPermits(1)(
1686+
yield* withInstallPermit(agent.id)(
16811687
ensureGlobalPackage(agent, distribution.kind, distribution.packageName!, hostEnvironment),
16821688
);
16831689
}
@@ -1754,7 +1760,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
17541760
}
17551761

17561762
if (distribution.kind === "binary") {
1757-
return yield* installSemaphore.withPermits(1)(
1763+
return yield* withInstallPermit(agent.id)(
17581764
Effect.gen(function* () {
17591765
const paths = binaryPaths(agent, distribution.binaryTarget!);
17601766
if (paths === undefined) {
@@ -1866,7 +1872,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
18661872
command = resolvedOverride;
18671873
args = distribution.args;
18681874
} else if (distribution.kind === "npx" || distribution.kind === "uvx") {
1869-
const installed = yield* installSemaphore.withPermits(1)(
1875+
const installed = yield* withInstallPermit(agent.id)(
18701876
ensureGlobalPackage(
18711877
agent,
18721878
distribution.kind,
@@ -1879,7 +1885,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
18791885
commandBinDirectory = installed.binDirectory;
18801886
} else {
18811887
const target = distribution.binaryTarget!;
1882-
command = yield* installSemaphore.withPermits(1)(
1888+
command = yield* withInstallPermit(agent.id)(
18831889
installBinary(agent, target).pipe(
18841890
Effect.tap(() => consumePreparedBinaryReservation(agent.id)),
18851891
),
@@ -1912,7 +1918,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
19121918
const uninstallManagedBinary: AcpRegistryCatalog["Service"]["uninstallManagedBinary"] = (input) =>
19131919
hostSettings
19141920
.withSnapshot((settings) =>
1915-
installSemaphore.withPermits(1)(
1921+
withInstallPermit(input.agentId)(
19161922
Effect.gen(function* () {
19171923
const safeAgentId = yield* decodeBoundedAgentId(input.agentId).pipe(
19181924
Effect.mapError(

0 commit comments

Comments
 (0)