Skip to content

Commit ea796dc

Browse files
committed
fix(provider-acp-registry): install agents with large archive listings
Registry binary installs list the archive before extracting it so unsafe paths can be rejected. That listing was read through the generic 1 MiB command output cap, but listing size tracks entry count rather than archive size: Cortex Code's macOS build has 12,752 entries and a 1.5 MB listing, so installing it always failed with "produced more output than expected". Give archive listings their own 64 MiB cap. Extraction and package-manager commands keep the 1 MiB cap.
1 parent 3f94487 commit ea796dc

2 files changed

Lines changed: 78 additions & 4 deletions

File tree

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,71 @@ describe("AcpRegistrySupport", () => {
755755
);
756756
});
757757

758+
it.effect("installs an archive whose entry listing exceeds the command output limit", () => {
759+
const downloadUrl = "https://registry.test/agent-long-listing.tar.gz";
760+
const agent = makeAgent({
761+
binary: { "linux-x86_64": { archive: downloadUrl, cmd: "./agent" } },
762+
});
763+
return Effect.gen(function* () {
764+
const fileSystem = yield* FileSystem.FileSystem;
765+
const cacheDir = yield* fileSystem.makeTempDirectoryScoped({
766+
prefix: "t3-acp-long-listing-",
767+
});
768+
const source = `${cacheDir}/source`;
769+
yield* fileSystem.makeDirectory(source);
770+
yield* fileSystem.writeFileString(`${source}/agent`, "#!/bin/sh\necho managed\n");
771+
// 5,000 long names list past the generic 1 MiB command output cap.
772+
const entries = `${source}/entries`;
773+
yield* fileSystem.makeDirectory(entries);
774+
yield* Effect.forEach(
775+
Array.from({ length: 5_000 }, (_, index) => index),
776+
(index) => fileSystem.writeFileString(`${entries}/${index}-${"e".repeat(240)}`, ""),
777+
{ concurrency: 16 },
778+
);
779+
const archivePath = `${cacheDir}/agent.tar.gz`;
780+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
781+
const tar = yield* spawner.spawn(
782+
ChildProcess.make("tar", ["-czf", archivePath, "-C", source, "."]),
783+
);
784+
expect(yield* tar.exitCode).toBe(0);
785+
const archive = yield* fileSystem.readFile(archivePath);
786+
const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
787+
cacheDir,
788+
toolsDir: `${cacheDir}/tools`,
789+
registryUrl,
790+
}).pipe(
791+
Effect.provideService(
792+
HttpClient.HttpClient,
793+
HttpClient.make((request) =>
794+
Effect.succeed(
795+
HttpClientResponse.fromWeb(
796+
request,
797+
request.url === registryUrl
798+
? new Response(makeRegistry(agent))
799+
: new Response(archive),
800+
),
801+
),
802+
),
803+
),
804+
);
805+
yield* resolver.prepare({ agentId: agent.id });
806+
const resolved = yield* resolver.resolve(settings(), "/workspace", {});
807+
expect(yield* fileSystem.readFileString(resolved.spawn.command)).toBe(
808+
"#!/bin/sh\necho managed\n",
809+
);
810+
}).pipe(
811+
Effect.scoped,
812+
Effect.provide(
813+
Layer.mergeAll(
814+
NodeServices.layer,
815+
TestProviderHost.layer().pipe(Layer.provide(NodeServices.layer)),
816+
),
817+
),
818+
Effect.provideService(HostProcess.Platform, "linux"),
819+
Effect.provideService(HostProcess.Architecture, "x64"),
820+
);
821+
});
822+
758823
it.effect("searches compatible agents with deterministic ranking and bounded metadata", () => {
759824
const exact = {
760825
...makeAgent({ npx: { package: "@example/[email protected]" } }),

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ const ACP_REGISTRY_URL = "https://cdn.agentclientprotocol.com/registry/v1/latest
5151

5252
const MAX_REGISTRY_BYTES = 1024 * 1024;
5353
const MAX_ARCHIVE_BYTES = 1024 * 1024 * 1024;
54+
const MAX_COMMAND_OUTPUT_BYTES = 1024 * 1024;
55+
// Listings scale with entry count, not archive size: Cortex Code's macOS build lists
56+
// 12,752 entries in 1.5 MB.
57+
const MAX_ARCHIVE_LISTING_BYTES = 64 * 1024 * 1024;
5458
const MAX_PACKAGE_MANIFEST_BYTES = 1024 * 1024;
5559
// Older clients omit the limit and validate responses against a 20-agent cap.
5660
const DEFAULT_SEARCH_LIMIT = 20;
@@ -894,6 +898,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
894898
readonly env?: NodeJS.ProcessEnv;
895899
readonly timeout?: Duration.Input;
896900
readonly truncatedOutputReason?: AcpRegistryErrorReason;
901+
readonly maxStdoutBytes?: number;
897902
} = {},
898903
) {
899904
const collect = Effect.gen(function* () {
@@ -912,8 +917,11 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
912917
yield* Effect.addFinalizer(() => child.kill().pipe(Effect.ignore));
913918
const [stdout, stderr, exitCode] = yield* Effect.all(
914919
[
915-
collectUint8StreamText({ stream: child.stdout, maxBytes: 1024 * 1024 }),
916-
collectUint8StreamText({ stream: child.stderr, maxBytes: 1024 * 1024 }),
920+
collectUint8StreamText({
921+
stream: child.stdout,
922+
maxBytes: options.maxStdoutBytes ?? MAX_COMMAND_OUTPUT_BYTES,
923+
}),
924+
collectUint8StreamText({ stream: child.stderr, maxBytes: MAX_COMMAND_OUTPUT_BYTES }),
917925
child.exitCode,
918926
],
919927
{ concurrency: "unbounded" },
@@ -1510,10 +1518,11 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
15101518
: platform === "win32"
15111519
? ["-tf", archivePath]
15121520
: undefined;
1521+
const listingOptions = { maxStdoutBytes: MAX_ARCHIVE_LISTING_BYTES };
15131522
const entries =
15141523
listArgs === undefined
1515-
? yield* runCommand("unzip", ["-Z1", archivePath])
1516-
: yield* runCommand(tarCommand, listArgs);
1524+
? yield* runCommand("unzip", ["-Z1", archivePath], listingOptions)
1525+
: yield* runCommand(tarCommand, listArgs, listingOptions);
15171526
if (!validateArchiveEntries(entries)) {
15181527
return yield* new AcpRegistryError({
15191528
reason: "archive_invalid",

0 commit comments

Comments
 (0)