From 69a49830c2dbfdb129bda4ef54d11796581260ad Mon Sep 17 00:00:00 2001 From: OmarAlex24 <77650361+OmarAlex24@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:02:15 -0600 Subject: [PATCH 1/4] fix(acp-registry): models show their own reasoning levels before their first session ACP agents such as Devin report reasoning levels only for a session's current model, so a model nobody had run a session on showed no effort picker, and what sessions did report was lost on restart. After the probe session is set up, the driver publishes the probed snapshot and then opens each visible model that has no known options in that session (hidden models skipped, favorites first, at most 24 per probe), reads its model-specific options, and restores the agent's original model so agents that save the selection keep their default. The per-model options are saved in the provider status cache, keyed by instance and trusted only for the agent version they came from; later probes continue from there. Live session reports replace saved or discovered entries. Implemented by Claude Opus 5.5 (high) via Devin CLI. --- .../src/server/driver.test.ts | 310 ++++++++++++++++++ .../src/server/driver.ts | 232 ++++++++----- .../src/server/learnedModelOptions.ts | 233 +++++++++++++ .../provider-acp-registry/src/server/probe.ts | 102 +++++- 4 files changed, 784 insertions(+), 93 deletions(-) create mode 100644 packages/provider-acp-registry/src/server/learnedModelOptions.ts diff --git a/packages/provider-acp-registry/src/server/driver.test.ts b/packages/provider-acp-registry/src/server/driver.test.ts index 684eb21d7456b..6b1fb00fde627 100644 --- a/packages/provider-acp-registry/src/server/driver.test.ts +++ b/packages/provider-acp-registry/src/server/driver.test.ts @@ -2,8 +2,10 @@ import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; import * as NodeServices from "@effect/platform-node/NodeServices"; import { AcpRegistryOperationError, + DEFAULT_SERVER_SETTINGS, ProviderInstanceId, type ServerProvider, + type ServerProviderModel, } from "@t3tools/contracts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions"; @@ -19,6 +21,7 @@ import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; +import type * as Scope from "effect/Scope"; import * as Stream from "effect/Stream"; import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts"; @@ -38,6 +41,7 @@ import { acpRegistryProbeResult, normalizeAcpRegistryLiveConfiguration, } from "./probe.ts"; +import { acpRegistryModelsToDiscover } from "./learnedModelOptions.ts"; const decodeSettings = Schema.decodeSync(AcpRegistrySettings); const identity = { @@ -864,6 +868,62 @@ describe("acpRegistryEnrichmentCache", () => { }); }); +describe("acpRegistryModelsToDiscover", () => { + it("orders unknown visible models by favorites and the user's order, up to the limit", () => { + const instanceId = ProviderInstanceId.make("acpRegistry_devin"); + const effort = { + id: "effort", + label: "Effort", + type: "select" as const, + role: "reasoning" as const, + options: [{ id: "high", label: "High" }], + currentValue: "high", + }; + const model = ( + slug: string, + extra: Partial = {}, + ): ServerProviderModel => ({ + slug, + name: slug, + isCustom: false, + capabilities: { optionDescriptors: [] }, + ...extra, + }); + const provider = { + instanceId, + models: [ + model("current", { isDefault: true }), + model("a"), + model("b"), + model("c"), + model("advertised", { capabilities: { optionDescriptors: [effort] } }), + model("known"), + model("custom", { isCustom: true }), + model("d"), + model("e"), + ], + }; + + expect( + acpRegistryModelsToDiscover({ + provider, + settings: { + ...DEFAULT_SERVER_SETTINGS, + favorites: [ + { provider: ProviderInstanceId.make("other"), model: "a" }, + { provider: instanceId, model: "e" }, + ], + providerModelPreferences: { + [instanceId]: { hiddenModels: ["b"], modelOrder: ["d", "c"] }, + }, + }, + learned: new Map([["known", []]]), + limit: 3, + }), + ).toEqual(["e", "d", "c"]); + }); +}); + describe("acpRegistryAdvertisesModelCatalog", () => { it("counts choices inside option groups and available model state", () => { expect( @@ -949,6 +1009,61 @@ createInterface({ input: process.stdin }).on("line", (line) => { }); `; +// Reports `effort` levels for its current model only, like Devin, and logs each model switch. +const perModelEffortAgentSource = ` +import { appendFileSync, readFileSync } from "node:fs"; +import { createInterface } from "node:readline"; +const [logPath, modelsPath] = process.argv.slice(2); +const levels = JSON.parse(readFileSync(modelsPath, "utf8")); +const modelIds = Object.keys(levels); +let current = modelIds[0]; +const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n"); +const configOptions = () => [ + { + id: "model", + name: "Model", + category: "model", + type: "select", + currentValue: current, + options: modelIds.map((value) => ({ value, name: value })), + }, + ...(levels[current] === null + ? [] + : [ + { + id: "effort", + name: "Effort", + category: "thought_level", + type: "select", + currentValue: levels[current][0], + options: levels[current].map((value) => ({ value, name: value })), + }, + ]), +]; +createInterface({ input: process.stdin }).on("line", (line) => { + const { id, method, params } = JSON.parse(line); + if (id === undefined) return; + if (method === "initialize") { + send({ id, result: { protocolVersion: 1, agentCapabilities: {}, authMethods: [] } }); + } else if (method === "session/new") { + send({ id, result: { sessionId: "probe-session", configOptions: configOptions() } }); + send({ + method: "session/update", + params: { + sessionId: "probe-session", + update: { sessionUpdate: "available_commands_update", availableCommands: [] }, + }, + }); + } else if (method === "session/set_config_option" && params.configId === "model") { + appendFileSync(logPath, params.value + "\\n"); + current = params.value; + send({ id, result: { configOptions: configOptions() } }); + } else { + send({ id, result: {} }); + } +}); +`; + const driverLayer = TestProviderHost.layer({ runBackgroundWork: false }).pipe( Layer.provideMerge(AcpRegistryRuntimeCoordinator.layer), Layer.provideMerge(IdAllocator.layer), @@ -1188,4 +1303,199 @@ it.layer(driverLayer, { excludeTestServices: true })("AcpRegistryDriver", (it) = ); }), ); + + const makePerModelEffortAgent = Effect.fn("makePerModelEffortAgent")(function* ( + levels: Readonly | null>>, + ) { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "acp-driver-" }); + const agentPath = path.join(directory, "agent.mjs"); + const logPath = path.join(directory, "switches.log"); + const modelsPath = path.join(directory, "models.json"); + yield* fileSystem.writeFileString(agentPath, perModelEffortAgentSource); + yield* fileSystem.writeFileString(logPath, ""); + yield* fileSystem.writeFileString(modelsPath, JSON.stringify(levels)); + return { + spawn: { command: process.execPath, args: [agentPath, logPath, modelsPath] }, + modelSwitches: fileSystem + .readFileString(logPath) + .pipe(Effect.map((log) => log.split("\n").filter((line) => line.length > 0))), + }; + }); + const createRegistryInstance = ( + instanceId: ProviderInstanceId, + spawn: { readonly command: string; readonly args: ReadonlyArray }, + version: string, + ) => + AcpRegistryDriver.create({ + instanceId, + displayName: identity.displayName, + enabled: true, + environment: [], + config: decodeSettings({ agentId: "test-agent" }), + }).pipe( + Effect.provideService(AcpRegistrySupport.AcpRegistryCatalog, { + ...catalogWithInspection({ + status: "ready", + agentId: "test-agent", + version, + distribution: "npx", + }), + resolve: () => Effect.succeed({ distribution: "npx" as const, spawn }), + }), + ); + const effortLevels = (snapshot: ServerProvider) => + snapshot.models + .map((model) => { + const effort = model.capabilities?.optionDescriptors?.find( + (option) => option.id === "effort", + ); + const levels = effort?.type === "select" ? effort.options.map((option) => option.id) : []; + return `${model.slug}:${levels.join("+")}`; + }) + .join(); + const refreshUntilEffortLevels = ( + instance: Effect.Success>, + expected: string, + ) => + Effect.gen(function* () { + const reached = yield* instance.snapshot.streamChanges.pipe( + Stream.filter((snapshot) => effortLevels(snapshot) === expected), + Stream.runHead, + Effect.forkScoped({ startImmediately: true }), + ); + yield* instance.snapshot.refresh; + yield* Fiber.join(reached); + }); + + // A session's report: the model select plus the current model's own effort levels. + const liveSession = ( + models: ReadonlyArray, + model: string, + levels: ReadonlyArray, + ) => + normalizeAcpRegistryLiveConfiguration([ + { + id: "model", + name: "Model", + category: "model", + type: "select", + currentValue: model, + options: models.map((value) => ({ value, name: value })), + }, + { + id: "effort", + name: "Effort", + category: "thought_level", + type: "select", + currentValue: levels[0]!, + options: levels.map((value) => ({ value, name: value })), + }, + ]); + + it.effect("reads each visible model's own reasoning levels before its first session", () => + Effect.gen(function* () { + const instanceId = ProviderInstanceId.make("acpRegistry_discovery"); + yield* (yield* TestProviderHost.TestProviderHostSettings).set({ + ...DEFAULT_SERVER_SETTINGS, + favorites: [{ provider: instanceId, model: "fav" }], + providerModelPreferences: { [instanceId]: { hiddenModels: ["hidden"], modelOrder: [] } }, + }); + const agent = yield* makePerModelEffortAgent({ + default: ["medium", "high"], + plain: null, + other: ["low", "high"], + hidden: ["low"], + fav: ["none", "max"], + }); + const instance = yield* createRegistryInstance(instanceId, agent.spawn, "1.0.0"); + + yield* refreshUntilEffortLevels( + instance, + "default:medium+high,plain:,other:low+high,hidden:,fav:none+max", + ); + // Favorites first, hidden models skipped, then the agent's own model restored. + expect(yield* agent.modelSwitches).toEqual(["fav", "plain", "other", "default"]); + + // What a live session reports for a model outranks what discovery read for it. + const coordinator = yield* AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator; + const models = ["default", "plain", "other", "hidden", "fav"]; + const live = yield* instance.snapshot.streamChanges.pipe( + Stream.filter( + (snapshot) => + effortLevels(snapshot) === "default:high,plain:,other:xhigh,hidden:,fav:none+max", + ), + Stream.runHead, + Effect.forkScoped({ startImmediately: true }), + ); + yield* coordinator.publishLiveConfiguration( + instanceId, + liveSession(models, "other", ["xhigh"]), + ); + yield* coordinator.publishLiveConfiguration( + instanceId, + liveSession(models, "default", ["high"]), + ); + expect(Option.isSome(yield* Fiber.join(live))).toBe(true); + }), + ); + + it.effect("keeps discovered reasoning levels across restarts until the agent updates", () => + Effect.gen(function* () { + const instanceId = ProviderInstanceId.make("acpRegistry_persisted"); + const coordinator = yield* AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator; + const agent = yield* makePerModelEffortAgent({ + default: ["medium", "high"], + other: ["low", "high"], + }); + const runInstance = ( + version: string, + expected: string, + then: ( + instance: Effect.Success>, + ) => Effect.Effect = () => Effect.void, + ) => + Effect.scoped( + createRegistryInstance(instanceId, agent.spawn, version).pipe( + Effect.tap((instance) => refreshUntilEffortLevels(instance, expected)), + Effect.flatMap(then), + ), + ); + + yield* runInstance("1.0.0", "default:medium+high,other:low+high"); + expect(yield* agent.modelSwitches).toEqual(["other", "default"]); + + // Reused after a restart; a live session then replaces the stored levels. + yield* runInstance("1.0.0", "default:medium+high,other:low+high", (instance) => + Effect.gen(function* () { + const replaced = yield* instance.snapshot.streamChanges.pipe( + Stream.filter((snapshot) => effortLevels(snapshot) === "default:high,other:xhigh"), + Stream.runHead, + Effect.forkScoped({ startImmediately: true }), + ); + const models = ["default", "other"]; + yield* coordinator.publishLiveConfiguration( + instanceId, + liveSession(models, "other", ["xhigh"]), + ); + yield* coordinator.publishLiveConfiguration( + instanceId, + liveSession(models, "default", ["high"]), + ); + yield* Fiber.join(replaced); + // The session ends with this instance; only the stored levels remain. + yield* coordinator.clearLiveConfiguration(instanceId); + }), + ); + expect(yield* agent.modelSwitches).toEqual(["other", "default"]); + + yield* runInstance("1.0.0", "default:medium+high,other:xhigh"); + expect(yield* agent.modelSwitches).toEqual(["other", "default"]); + + // An agent update makes every stored level stale. + yield* runInstance("2.0.0", "default:medium+high,other:low+high"); + expect(yield* agent.modelSwitches).toEqual(["other", "default", "other", "default"]); + }), + ); }); diff --git a/packages/provider-acp-registry/src/server/driver.ts b/packages/provider-acp-registry/src/server/driver.ts index 46d8ed3219aa4..0d4f3cf068865 100644 --- a/packages/provider-acp-registry/src/server/driver.ts +++ b/packages/provider-acp-registry/src/server/driver.ts @@ -53,6 +53,7 @@ import { type AcpRegistryConfigurationProbe, type AcpRegistryConfigurationProbeResult, type AcpRegistryLiveConfiguration, + type AcpRegistryModelDiscovery, deleteAcpRegistrySession, disableAcpRegistryProvider, listAcpRegistrySessions, @@ -65,12 +66,21 @@ import * as AcpRegistrySupport from "./AcpRegistrySupport.ts"; import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts"; import * as AcpRegistryAuth from "./auth.ts"; import * as AcpRegistryAuthenticationState from "./authenticationState.ts"; +import { + acpRegistryCurrentModelOptions, + acpRegistryModelsToDiscover, + makeAcpRegistryLearnedModelOptionsStore, + withAcpRegistryLearnedModelOptions, +} from "./learnedModelOptions.ts"; const DRIVER_KIND = ProviderDriverKind.make("acpRegistry"); const decodeSettings = Schema.decodeSync(AcpRegistrySettings); // Cache only successful authenticated probes so sign-in changes remain visible. const PROBE_SUCCESS_TTL_MS = 15 * 60 * 1_000; const PROBE_PROVISIONAL_TTL_MS = 30 * 1_000; +// Devin answers a model switch in about a third of a second and lists 170 models, +// so a probe reads a few seconds' worth; later probes continue from the saved results. +const MAX_DISCOVERED_MODELS_PER_PROBE = 24; function acpRegistryProbeTtlMs(provider: ServerProvider): number { const discoveredModels = provider.models.filter((model) => !model.isCustom); @@ -518,6 +528,9 @@ export const checkAcpRegistryProviderStatus = Effect.fn("AcpRegistryDriver.check readonly settings: AcpRegistrySettings; readonly cwd: string; readonly environment: NodeJS.ProcessEnv; + readonly modelDiscovery?: Omit & { + readonly onProbed: (provider: ServerProvider) => Effect.Effect>; + }; }, probeConfiguration: AcpRegistryConfigurationProbe, ): Effect.fn.Return { @@ -544,12 +557,25 @@ export const checkAcpRegistryProviderStatus = Effect.fn("AcpRegistryDriver.check inspection: inspected.success, }); } + const inspection = inspected.success; + const modelDiscovery = input.modelDiscovery; const probed = yield* Effect.result( probeConfiguration({ instanceId: input.instanceId, settings: input.settings, cwd: input.cwd, environment: providerProbeEnvironment(input.environment), + ...(modelDiscovery === undefined + ? {} + : { + modelDiscovery: { + onProbed: (probe) => + modelDiscovery.onProbed( + buildCheckedAcpRegistrySnapshot({ ...input, checkedAt, inspection, probe }), + ), + onDiscovered: modelDiscovery.onDiscovered, + }, + }), }), ); return Result.isFailure(probed) @@ -688,26 +714,31 @@ export const AcpRegistryDriver: ProviderDriver>([]); - const applyLiveConfiguration = ( + // reported by sessions and probe discovery are kept here and on disk. + const learnedModelOptions = yield* makeAcpRegistryLearnedModelOptionsStore({ + cacheDir: host.paths.providerStatusCacheDir, + instanceId, + settings: effectiveConfig, + }); + const applyLiveConfiguration = Effect.fn("AcpRegistryDriver.applyLiveConfiguration")(function* ( provider: ServerProvider, configuration: AcpRegistryLiveConfiguration, - ) => - Ref.modify(learnedModels, (learned) => { - const next = applyAcpRegistryLiveConfiguration( - provider, - configuration, - effectiveConfig.customModels, - learned.length > 0 ? learned : provider.models, - ); - return [next, next.models === provider.models ? learned : next.models]; - }); - const clearLearnedModels = Ref.set(learnedModels, []); + ) { + const reported = acpRegistryCurrentModelOptions(configuration); + if (reported !== undefined) { + yield* learnedModelOptions.learn(reported.modelId, reported.options, "live"); + } + return withAcpRegistryLearnedModelOptions( + applyAcpRegistryLiveConfiguration(provider, configuration, effectiveConfig.customModels), + yield* learnedModelOptions.get, + ); + }); + const clearLearnedModels = learnedModelOptions.clear; const withLiveRuntimeState = Effect.fn("AcpRegistryDriver.withLiveRuntimeState")(function* ( input: ServerProvider, ) { if (input.auth.status === "unauthenticated") yield* confirmedAuthentication.set(false); + if (input.installed) yield* learnedModelOptions.setVersion(input.version); const provider = input.enabled && input.installed && @@ -715,26 +746,22 @@ export const AcpRegistryDriver: ProviderDriver { - const withCommands = applyAcpRegistryAvailableCommands(provider, commands); - return Option.match(configuration, { - onNone: () => Effect.succeed(withCommands), - onSome: (liveConfiguration) => - applyLiveConfiguration(withCommands, liveConfiguration), - }).pipe( - Effect.map((withConfiguration) => - applyAcpRegistryUrlAuthAction(withConfiguration, authAction), - ), - ); - }), - ); + if (Option.isNone(runtimeCoordinator)) { + return withAcpRegistryLearnedModelOptions(provider, yield* learnedModelOptions.get); + } + const coordinator = runtimeCoordinator.value; + const withCommands = applyAcpRegistryAvailableCommands( + provider, + yield* coordinator.getAvailableCommands(instanceId), + ); + const configuration = yield* coordinator.getLiveConfiguration(instanceId); + const withConfiguration = Option.isSome(configuration) + ? yield* applyLiveConfiguration(withCommands, configuration.value) + : withAcpRegistryLearnedModelOptions(withCommands, yield* learnedModelOptions.get); + return applyAcpRegistryUrlAuthAction( + withConfiguration, + yield* coordinator.getUrlAuthAction(instanceId), + ); }); // A local executable's version comes only from probing it, so readiness checks reuse the last report. const reportedLocalVersion = yield* Ref.make(null); @@ -751,19 +778,49 @@ export const AcpRegistryDriver: ProviderDriver