@devries-cameron20 / t3code-1 / commits / 3b2f958603
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): ACP Registry searches reuse a recently fetched index (#26248)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 19:18 UTC 3b2f958603a51d8c42c4ede02eee7b8cb310b2d9
3 files changed +122 -5
packages/client-runtime/src/state/server.ts
+2 -1
@@ -1310,7 +1310,8 @@ export function createServerEnvironmentAtoms<R, E>(
1310 searchAcpRegistry: createEnvironmentRpcQueryAtomFamily(runtime, {
1311 label: "environment-data:server:acp-registry:search",
1312 tag: WS_METHODS.serverSearchAcpRegistry,
1313 - // Reopening Add provider reuses recent results; submitting the same search refreshes it.
1313 + // Reopening Add provider reuses recent results. Submitting the same search asks the
1314 + // server again, which reuses a Registry index fetched in the last five minutes.
1315 staleTimeMs: 5 * 60_000,
1316 }),
1317 configProjection,
packages/provider-acp-registry/src/server/AcpRegistrySupport.test.ts
+95 -1
@@ -15,6 +15,7 @@ import * as Path from "effect/Path";
15 import * as Fiber from "effect/Fiber";
16 import * as Layer from "effect/Layer";
17 import * as Schema from "effect/Schema";
18 +import * as TestClock from "effect/testing/TestClock";
19 import * as HttpClient from "effect/http/HttpClient";
20 import * as HttpClientResponse from "effect/http/HttpClientResponse";
21 import * as ChildProcess from "effect/process/ChildProcess";
@@ -821,7 +822,7 @@ describe("AcpRegistrySupport", () => {
822 );
823 });
824
824 - it.effect("refreshes explicit searches and coalesces concurrent refreshes", () => {
825 + it.effect("searches reuse an index fetched in the last five minutes", () => {
826 const agent = makeAgent({ npx: { package: "@example/acp@1.2.3" } });
827 let requests = 0;
828 return Effect.gen(function* () {
@@ -840,6 +841,11 @@ describe("AcpRegistrySupport", () => {
841 );
842 expect(requests).toBe(1);
843
844 + yield* TestClock.adjust("4 minutes");
845 + yield* resolver.search({ query: "other" });
846 + expect(requests).toBe(1);
847 +
848 + yield* TestClock.adjust("1 minute");
849 yield* resolver.search({ query: "example" });
850 expect(requests).toBe(2);
851 }).pipe(
@@ -855,6 +861,94 @@ describe("AcpRegistrySupport", () => {
861 );
862 });
863
864 + it.effect("searches retry the network after falling back to the cached index", () => {
865 + const agent = makeAgent({ npx: { package: "@example/acp@1.2.3" } });
866 + let requests = 0;
867 + return Effect.gen(function* () {
868 + const fileSystem = yield* FileSystem.FileSystem;
869 + const cacheDir = yield* fileSystem.makeTempDirectoryScoped({
870 + prefix: "t3-acp-registry-retry-",
871 + });
872 + yield* fileSystem.makeDirectory(`${cacheDir}/acp-registry`, { recursive: true });
873 + yield* fileSystem.writeFileString(
874 + `${cacheDir}/acp-registry/registry.json`,
875 + makeRegistry(agent),
876 + );
877 + const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
878 + cacheDir,
879 + toolsDir: `${cacheDir}/tools`,
880 + registryUrl,
881 + });
882 + const offline = yield* resolver.search({ query: "example" });
883 + expect(offline.agents.map((result) => result.id)).toEqual([agent.id]);
884 + expect(requests).toBe(1);
885 +
886 + yield* resolver.search({ query: "example" });
887 + expect(requests).toBe(2);
888 + yield* resolver.search({ query: "example" });
889 + expect(requests).toBe(2);
890 + }).pipe(
891 + Effect.scoped,
892 + Effect.provide(
893 + layerResolver((request) => {
894 + requests += 1;
895 + return Effect.succeed(
896 + HttpClientResponse.fromWeb(
897 + request,
898 + requests === 1
899 + ? new Response("unavailable", { status: 503 })
900 + : new Response(makeRegistry(agent)),
901 + ),
902 + );
903 + }),
904 + ),
905 + );
906 + });
907 +
908 + it.effect("searches retry the network after a refresh falls back within the reuse window", () => {
909 + const agent = makeAgent({ npx: { package: "@example/acp@1.2.3" } });
910 + let requests = 0;
911 + let online = true;
912 + return Effect.gen(function* () {
913 + const fileSystem = yield* FileSystem.FileSystem;
914 + const cacheDir = yield* fileSystem.makeTempDirectoryScoped({
915 + prefix: "t3-acp-registry-refresh-fallback-",
916 + });
917 + const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
918 + cacheDir,
919 + toolsDir: `${cacheDir}/tools`,
920 + registryUrl,
921 + });
922 + yield* resolver.search({ query: "example" });
923 + expect(requests).toBe(1);
924 +
925 + // Prepare always refreshes; an unknown agent stops it right after the refresh.
926 + online = false;
927 + const missing = yield* resolver.prepare({ agentId: "missing-agent" }).pipe(Effect.flip);
928 + expect(missing.reason).toBe("agent_not_found");
929 + expect(requests).toBe(2);
930 +
931 + online = true;
932 + yield* resolver.search({ query: "example" });
933 + expect(requests).toBe(3);
934 + }).pipe(
935 + Effect.scoped,
936 + Effect.provide(
937 + layerResolver((request) => {
938 + requests += 1;
939 + return Effect.succeed(
940 + HttpClientResponse.fromWeb(
941 + request,
942 + online
943 + ? new Response(makeRegistry(agent))
944 + : new Response("unavailable", { status: 503 }),
945 + ),
946 + );
947 + }),
948 + ),
949 + );
950 + });
951 +
952 it.effect("filters runner recipes that the environment cannot prepare", () => {
953 const runnerAgent = makeAgent({ npx: { package: "@example/acp@1.2.3" } });
954 const binaryAgent = {
packages/provider-acp-registry/src/server/AcpRegistrySupport.ts
+25 -3
@@ -55,6 +55,8 @@ const MAX_PACKAGE_MANIFEST_BYTES = 1024 * 1024;
55 // Older clients omit the limit and validate responses against a 20-agent cap.
56 const DEFAULT_SEARCH_LIMIT = 20;
57 const REGISTRY_REQUEST_TIMEOUT = "30 seconds";
58 +// Searches reuse an index fetched this recently; prepare always fetches the latest.
59 +const REGISTRY_SEARCH_MAX_AGE_MS = 5 * 60 * 1_000;
60 const ARCHIVE_REQUEST_TIMEOUT = "20 minutes";
61 const PACKAGE_INSTALL_TIMEOUT = "20 minutes";
62 const PACKAGE_QUERY_TIMEOUT = "30 seconds";
@@ -659,6 +661,8 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
661 : path.join(packageInstallRoot(agent, distribution), "bin");
662 const packageReceiptsDirectory = path.join(registryDirectory, "package-installs");
663 const registryRef = yield* Ref.make<AcpRegistryIndex | undefined>(undefined);
664 + // When the network last served registryRef; unset while it holds the disk cache.
665 + const registryFetchedAtMs = yield* Ref.make<number | undefined>(undefined);
666 const registryRevision = yield* Ref.make(0);
667 const registrySemaphore = yield* Semaphore.make(1);
668 const installSemaphore = yield* Semaphore.make(1);
@@ -848,25 +852,43 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
852 const current = yield* Ref.get(registryRef);
853 if (current !== undefined && currentRevision !== observedRevision) return current;
854
851 - const registry = yield* fetchRegistry().pipe(
855 + const { registry, fetched } = yield* fetchRegistry().pipe(
856 + Effect.map((registry) => ({ registry, fetched: true })),
857 Effect.catch((networkError) =>
858 readCachedRegistry.pipe(
859 Effect.flatMap(
860 Option.match({
861 onNone: () => Effect.fail(networkError),
857 - onSome: Effect.succeed,
862 + onSome: (registry) => Effect.succeed({ registry, fetched: false }),
863 }),
864 ),
865 ),
866 ),
867 );
868 yield* Ref.set(registryRef, registry);
869 + yield* Ref.set(registryFetchedAtMs, fetched ? yield* Clock.currentTimeMillis : undefined);
870 yield* Ref.update(registryRevision, (revision) => revision + 1);
871 return registry;
872 }),
873 );
874 });
875
876 + const recentRegistry = Effect.fn("AcpRegistryCatalog.recentRegistry")(function* () {
877 + const current = yield* Ref.get(registryRef);
878 + const fetchedAtMs = yield* Ref.get(registryFetchedAtMs);
879 + const now = yield* Clock.currentTimeMillis;
880 + // A clock moved back makes the stamp untrustworthy, so it counts as stale.
881 + if (
882 + current !== undefined &&
883 + fetchedAtMs !== undefined &&
884 + now >= fetchedAtMs &&
885 + now - fetchedAtMs < REGISTRY_SEARCH_MAX_AGE_MS
886 + ) {
887 + return current;
888 + }
889 + return yield* refreshRegistry();
890 + });
891 +
892 const loadCachedRegistry = Effect.fn("AcpRegistryCatalog.loadCachedRegistry")(function* () {
893 const current = yield* Ref.get(registryRef);
894 if (current !== undefined) return current;
@@ -1589,7 +1611,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
1611
1612 const search: AcpRegistryCatalog["Service"]["search"] = Effect.fn("AcpRegistryCatalog.search")(
1613 function* (input) {
1592 - const registry = yield* refreshRegistry();
1614 + const registry = yield* recentRegistry();
1615 const ranked = registry.agents.flatMap((agent) => {
1616 const distribution = resolveAcpRegistryDistribution({
1617 agent,