TypeScript
fix(provider-acp-registry): install agents with large archive listings (#25545)
kareemsetl812cb68b7d21
diff --git a/packages/provider-acp-registry/src/server/AcpRegistrySupport.test.ts b/packages/provider-acp-registry/src/server/AcpRegistrySupport.test.tsindex 7cfc19e6fd3..c5612082f31 100644--- a/packages/provider-acp-registry/src/server/AcpRegistrySupport.test.ts+++ b/packages/provider-acp-registry/src/server/AcpRegistrySupport.test.ts@@ -698,7 +698,7 @@ describe("AcpRegistrySupport", () => {},);- it.effect("installs a tar archive containing a root directory entry", () => {+ it.effect("installs a tar archive with a root entry and a listing larger than 1 MiB", () => {const downloadUrl = "https://registry.test/agent.tar.gz";const agent = makeAgent({binary: { "linux-x86_64": { archive: downloadUrl, cmd: "./agent" } },@@ -709,6 +709,14 @@ describe("AcpRegistrySupport", () => {const source = `${cacheDir}/source`;yield* fileSystem.makeDirectory(source);yield* fileSystem.writeFileString(`${source}/agent`, "#!/bin/sh\necho managed\n");+ // 5,000 long names list past the generic 1 MiB command output cap.+ const entries = `${source}/entries`;+ yield* fileSystem.makeDirectory(entries);+ yield* Effect.forEach(+ Array.from({ length: 5_000 }, (_, index) => index),+ (index) => fileSystem.writeFileString(`${entries}/${index}-${"e".repeat(240)}`, ""),+ { concurrency: 16 },+ );const archivePath = `${cacheDir}/agent.tar.gz`;const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;const tar = yield* spawner.spawn(diff --git a/packages/provider-acp-registry/src/server/AcpRegistrySupport.ts b/packages/provider-acp-registry/src/server/AcpRegistrySupport.tsindex 1d333ff2da6..910048b55a7 100644--- a/packages/provider-acp-registry/src/server/AcpRegistrySupport.ts+++ b/packages/provider-acp-registry/src/server/AcpRegistrySupport.ts@@ -51,6 +51,9 @@ const ACP_REGISTRY_URL = "https://cdn.agentclientprotocol.com/registry/v1/latestconst MAX_REGISTRY_BYTES = 1024 * 1024;const MAX_ARCHIVE_BYTES = 1024 * 1024 * 1024;+const MAX_COMMAND_OUTPUT_BYTES = 1024 * 1024;+// Archive listings can exceed the output of package-manager commands.+const MAX_ARCHIVE_LISTING_BYTES = 64 * 1024 * 1024;const MAX_PACKAGE_MANIFEST_BYTES = 1024 * 1024;// Older clients omit the limit and validate responses against a 20-agent cap.const DEFAULT_SEARCH_LIMIT = 20;@@ -916,6 +919,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(functreadonly env?: NodeJS.ProcessEnv;readonly timeout?: Duration.Input;readonly truncatedOutputReason?: AcpRegistryErrorReason;+ readonly maxStdoutBytes?: number;} = {},) {const collect = Effect.gen(function* () {@@ -934,8 +938,11 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(functyield* Effect.addFinalizer(() => child.kill().pipe(Effect.ignore));const [stdout, stderr, exitCode] = yield* Effect.all([- collectUint8StreamText({ stream: child.stdout, maxBytes: 1024 * 1024 }),- collectUint8StreamText({ stream: child.stderr, maxBytes: 1024 * 1024 }),+ collectUint8StreamText({+ stream: child.stdout,+ maxBytes: options.maxStdoutBytes ?? MAX_COMMAND_OUTPUT_BYTES,+ }),+ collectUint8StreamText({ stream: child.stderr, maxBytes: MAX_COMMAND_OUTPUT_BYTES }),child.exitCode,],{ concurrency: "unbounded" },@@ -1532,10 +1539,11 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct: platform === "win32"? ["-tf", archivePath]: undefined;+ const listingOptions = { maxStdoutBytes: MAX_ARCHIVE_LISTING_BYTES };const entries =listArgs === undefined- ? yield* runCommand("unzip", ["-Z1", archivePath])- : yield* runCommand(tarCommand, listArgs);+ ? yield* runCommand("unzip", ["-Z1", archivePath], listingOptions)+ : yield* runCommand(tarCommand, listArgs, listingOptions);if (!validateArchiveEntries(entries)) {return yield* new AcpRegistryError({reason: "archive_invalid",