@devries-cameron20 / t3code Mirror · read-only / commits / 05e835378f
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 22:15 UTC

fix(acp-registry): model refresh picks up models an agent adds upstream (#34246)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Edouard Andrei committed Nov 12, 2026 at 01:19 UTC 05e835378faa1ff425d4e284f668ff386d5d90c9
2 files changed +127
packages/provider-acp-registry/src/server/driver.test.ts
+123
@@ -1,18 +1,32 @@
1 +import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2 +import * as NodeServices from "@effect/platform-node/NodeServices";
3 import { AcpRegistryOperationError, ProviderInstanceId } from "@t3tools/contracts";
4 +import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
5 +import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
6 +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
7 +import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
8 import { AcpRegistrySettings } from "../settings.ts";
9 import { describe, expect, it } from "@effect/vitest";
10 import * as Effect from "effect/Effect";
11 +import * as Fiber from "effect/Fiber";
12 +import * as FileSystem from "effect/FileSystem";
13 +import * as Layer from "effect/Layer";
14 import * as Option from "effect/Option";
15 +import * as Path from "effect/Path";
16 import * as Schema from "effect/Schema";
17 +import * as Stream from "effect/Stream";
18
19 +import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts";
20 import * as AcpRegistrySupport from "./AcpRegistrySupport.ts";
21 import {
22 + AcpRegistryDriver,
23 applyAcpRegistryAvailableCommands,
24 applyAcpRegistryLiveConfiguration,
25 buildCheckedAcpRegistrySnapshot,
26 checkAcpRegistryProviderReadiness,
27 checkAcpRegistryProviderStatus,
28 } from "./driver.ts";
29 +import { normalizeAcpRegistryLiveConfiguration } from "./probe.ts";
30
31 const decodeSettings = Schema.decodeSync(AcpRegistrySettings);
32 const identity = {
@@ -432,3 +446,112 @@ describe("acpRegistrySnapshotReadiness", () => {
446 }),
447 );
448 });
449 +
450 +const fakeAgentSource = `
451 +import { readFileSync } from "node:fs";
452 +import { createInterface } from "node:readline";
453 +const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n");
454 +createInterface({ input: process.stdin }).on("line", (line) => {
455 + const { id, method } = JSON.parse(line);
456 + if (id === undefined) return;
457 + if (method === "initialize") {
458 + send({ id, result: { protocolVersion: 1, agentCapabilities: {}, authMethods: [] } });
459 + } else if (method === "session/new") {
460 + const modelIds = JSON.parse(readFileSync(process.argv[2], "utf8"));
461 + send({
462 + id,
463 + result: {
464 + sessionId: "probe-session",
465 + models: {
466 + currentModelId: modelIds[0],
467 + availableModels: modelIds.map((modelId) => ({ modelId, name: modelId })),
468 + },
469 + },
470 + });
471 + send({
472 + method: "session/update",
473 + params: {
474 + sessionId: "probe-session",
475 + update: { sessionUpdate: "available_commands_update", availableCommands: [] },
476 + },
477 + });
478 + } else {
479 + send({ id, result: {} });
480 + }
481 +});
482 +`;
483 +
484 +const driverLayer = TestProviderHost.layer({ runBackgroundWork: false }).pipe(
485 + Layer.provideMerge(AcpRegistryRuntimeCoordinator.layer),
486 + Layer.provideMerge(IdAllocator.layer),
487 + Layer.provideMerge(McpProviderSessions.layer),
488 + Layer.provideMerge(
489 + Layer.succeed(
490 + ProviderEventLoggers.ProviderEventLoggers,
491 + ProviderEventLoggers.NoOpProviderEventLoggers,
492 + ),
493 + ),
494 + Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
495 +);
496 +
497 +it.layer(driverLayer, { excludeTestServices: true })("AcpRegistryDriver", (it) => {
498 + it.effect("drops cached and session-reported models when its caches are invalidated", () =>
499 + Effect.gen(function* () {
500 + const fileSystem = yield* FileSystem.FileSystem;
501 + const path = yield* Path.Path;
502 + const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "acp-driver-" });
503 + const agentPath = path.join(directory, "agent.mjs");
504 + const modelsPath = path.join(directory, "models.json");
505 + yield* fileSystem.writeFileString(agentPath, fakeAgentSource);
506 + yield* fileSystem.writeFileString(modelsPath, JSON.stringify(["old-model"]));
507 + const coordinator = yield* AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator;
508 +
509 + const instance = yield* AcpRegistryDriver.create({
510 + instanceId: identity.instanceId,
511 + displayName: identity.displayName,
512 + enabled: true,
513 + environment: [],
514 + config: decodeSettings({ agentId: "test-agent" }),
515 + }).pipe(
516 + Effect.provideService(AcpRegistrySupport.AcpRegistryCatalog, {
517 + ...catalogWithInspection({
518 + status: "ready",
519 + agentId: "test-agent",
520 + version: "1.0.0",
521 + distribution: "npx",
522 + }),
523 + resolve: () =>
524 + Effect.succeed({
525 + distribution: "npx" as const,
526 + spawn: { command: process.execPath, args: [agentPath, modelsPath] },
527 + }),
528 + }),
529 + );
530 + const modelSlugs = instance.snapshot.streamChanges.pipe(
531 + Stream.map((snapshot) => snapshot.models.map((model) => model.slug)),
532 + );
533 + const waitForModels = (expected: ReadonlyArray<string>) =>
534 + modelSlugs.pipe(
535 + Stream.filter((slugs) => slugs.join() === expected.join()),
536 + Stream.runHead,
537 + );
538 +
539 + const probed = yield* waitForModels(["old-model"]).pipe(Effect.forkScoped);
540 + yield* instance.snapshot.refresh;
541 + yield* Fiber.join(probed);
542 + yield* coordinator.publishLiveConfiguration(
543 + identity.instanceId,
544 + normalizeAcpRegistryLiveConfiguration([], undefined, {
545 + currentModelId: "old-model",
546 + availableModels: [{ modelId: "old-model", name: "old-model" }],
547 + }),
548 + );
549 + yield* fileSystem.writeFileString(modelsPath, JSON.stringify(["old-model", "new-model"]));
550 +
551 + const refreshed = yield* waitForModels(["old-model", "new-model"]).pipe(Effect.forkScoped);
552 + yield* instance.invalidateCaches ?? Effect.void;
553 + yield* instance.snapshot.refresh;
554 + expect(Option.isSome(yield* Fiber.join(refreshed))).toBe(true);
555 + }),
556 + );
557 +});
packages/provider-acp-registry/src/server/driver.ts
+4
@@ -825,6 +825,10 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
825 ...snapshot,
826 refresh: snapshot.refresh.pipe(Effect.tap(() => controller.refreshMethods ?? Effect.void)),
827 },
828 + invalidateCaches: (Option.isSome(runtimeCoordinator)
829 + ? runtimeCoordinator.value.clearLiveConfiguration(instanceId)
830 + : Effect.void
831 + ).pipe(Effect.andThen(liveSnapshotSemaphore.withPermit(invalidateEnrichmentCache))),
832 orchestrationAdapter,
833 textGeneration: makeUnsupportedTextGeneration(),
834 acpSessionManagement: {