The best way to control Claude Code, Codex and more from any computer or phone
fix(acp): reject models unavailable to the active session (#26623)
Co-authored-by: maria-rcks <maria@kuuro.net>
Tejas Rahane committed
Oct 30, 2026 at 18:41 UTC
e4a067b526a19b57515ceb0a820ed6b4334b8db8
2 files changed
+117
-16
apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
+79
-11
@@ -28,6 +28,7 @@ import * as HttpClientResponse from "effect/http/HttpClientResponse";
28
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
29
import * as EffectAcpErrors from "effect-acp/errors";
30
31
+import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
32
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
33
import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
34
import {
@@ -468,6 +469,7 @@ describe("AcpRegistryAdapterV2", () => {
469
readonly storedModel?: string;
470
readonly storedModePick?: string;
471
readonly turnModels?: ReadonlyArray<string>;
472
+ readonly rejectedModel?: string;
473
}) {
474
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
475
// Scope release gives the replay agent at most a second to exit, so the status
@@ -605,7 +607,19 @@ describe("AcpRegistryAdapterV2", () => {
607
configurations.push(published);
608
current = target;
609
}
608
- }).pipe(Effect.scoped);
610
+ }).pipe(
611
+ Effect.match({
612
+ onFailure: (error) => {
613
+ assert.isDefined(input.rejectedModel);
614
+ assert.equal(
615
+ makeProviderFailure({ cause: error }).message,
616
+ `The agent did not accept the model "${input.rejectedModel}". Choose another model for this provider, then retry.`,
617
+ );
618
+ },
619
+ onSuccess: () => assert.isUndefined(input.rejectedModel),
620
+ }),
621
+ Effect.scoped,
622
+ );
623
yield* Effect.all(agentExits, { discard: true });
624
yield* makeAcpReplayCompletenessAssertion(fileSystem, statusPath, transcript);
625
return { configurations };
@@ -772,8 +786,70 @@ describe("AcpRegistryAdapterV2", () => {
786
}).pipe(Effect.provide(layerTest), Effect.scoped),
787
);
788
789
+ it.effect.each([
790
+ "config",
791
+ "legacy",
792
+ "updated-config",
793
+ "removed-config",
794
+ "configuration-update",
795
+ "unavailable-before-configuration",
796
+ ] as const)(
797
+ "rejects an unavailable explicit model in a %s catalog before inference",
798
+ (catalog) => {
799
+ const duringTurn = catalog === "updated-config" || catalog === "removed-config";
800
+ const duringConfiguration = catalog === "configuration-update";
801
+ const changesOptions =
802
+ duringConfiguration || catalog === "unavailable-before-configuration";
803
+ const model = duringTurn || duringConfiguration ? "hermes" : "missing";
804
+ const restrictedOption = {
805
+ ...modelOption("model", "other"),
806
+ options: [{ value: "other", name: "Other" }],
807
+ };
808
+ return openWithStoredPicks({
809
+ setup: {
810
+ ...(catalog === "legacy" || catalog === "removed-config"
811
+ ? {
812
+ models: {
813
+ currentModelId: "other",
814
+ availableModels: [{ modelId: "other", name: "Other" }],
815
+ },
816
+ }
817
+ : {}),
818
+ configOptions:
819
+ catalog === "legacy"
820
+ ? []
821
+ : [
822
+ {
823
+ ...modelOption("model", "hermes"),
824
+ options: [{ value: "hermes", name: "Hermes" }],
825
+ },
826
+ ...(changesOptions ? [permissionModeOption("ask")] : []),
827
+ ],
828
+ },
829
+ storedModel: model,
830
+ ...(duringTurn ? { turnModels: [model, model] } : {}),
831
+ ...(changesOptions ? { storedModePick: "auto" } : {}),
832
+ rejectedModel: model,
833
+ pickFrames: duringTurn
834
+ ? prompt(configOptionUpdate(catalog === "removed-config" ? [] : [restrictedOption]))
835
+ : duringConfiguration
836
+ ? [
837
+ outbound("session/set_config_option", {
838
+ sessionId: "agent-session",
839
+ configId: "permission-mode",
840
+ value: "auto",
841
+ }),
842
+ answer("session/set_config_option", {
843
+ configOptions: [restrictedOption, permissionModeOption("auto")],
844
+ }),
845
+ ]
846
+ : [],
847
+ }).pipe(Effect.provide(layerTest), Effect.scoped);
848
+ },
849
+ );
850
+
851
// regression: #19519 models come from session model state, not a hardcoded list
776
- it.effect("leaves unadvertised model IDs alone in both model selection protocols", () =>
852
+ it.effect("keeps unadvertised default and auto selections agent-controlled", () =>
853
Effect.gen(function* () {
854
const { configurations } = yield* openWithStoredPicks({
855
setup: {
@@ -783,15 +859,7 @@ describe("AcpRegistryAdapterV2", () => {
859
},
860
},
861
storedModel: "default",
786
- turnModels: [
787
- "auto",
788
- "removed-model",
789
- "other",
790
- "default",
791
- "auto",
792
- "hermes",
793
- "removed-model",
794
- ],
862
+ turnModels: ["auto", "default", "other", "default", "auto", "default", "auto"],
863
pickFrames: [
864
...prompt(),
865
...prompt(),
packages/provider-acp/src/server/adapter.ts
+38
-5
@@ -97,7 +97,11 @@ import {
97
resolveEmbeddedTerminalContent,
98
type AcpClientTerminals,
99
} from "./clientTerminals.ts";
100
-import { ACP_EMPTY_OPTION_VALUE, ACP_SESSION_MODE_OPTION_ID } from "./sessionConfig.ts";
100
+import {
101
+ ACP_EMPTY_OPTION_VALUE,
102
+ ACP_SESSION_MODE_OPTION_ID,
103
+ flattenSelectChoices,
104
+} from "./sessionConfig.ts";
105
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
106
import {
107
t3AcpPromptWithInstructions,
@@ -6733,12 +6737,41 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6737
return activated;
6738
});
6739
6740
+ const validateModelSelection = Effect.fn("AcpAdapterV2.validateModelSelection")(function* (
6741
+ modelSelection: ModelSelection,
6742
+ ) {
6743
+ const model = flavor.resolveModelId?.(modelSelection) ?? modelSelection.model;
6744
+ if (
6745
+ flavor.applyModelSelection !== undefined ||
6746
+ model.length === 0 ||
6747
+ model === "default" ||
6748
+ model === "auto" ||
6749
+ flavor.customModels?.includes(model) === true
6750
+ )
6751
+ return;
6752
+ const option = findModelConfigOption(yield* runtime.getConfigOptions);
6753
+ const models = (yield* Ref.get(activeSessionSetup))?.sessionSetupResult.models;
6754
+ const available =
6755
+ option?.type === "select"
6756
+ ? flattenSelectChoices(option.options).some((choice) => choice.value === model)
6757
+ : models?.availableModels.some((choice) => choice.modelId === model);
6758
+ if (available === false) {
6759
+ return yield* new AcpModelSelectionError({
6760
+ model: modelSelection.model,
6761
+ cause: EffectAcpErrors.AcpRequestError.invalidParams(
6762
+ "The requested model is not available in this session.",
6763
+ ),
6764
+ });
6765
+ }
6766
+ });
6767
+
6768
const configureSession = Effect.fnUntraced(function* (
6769
startResult: AcpSessionRuntime.AcpSessionRuntimeStartResult,
6770
modelSelection: ModelSelection,
6771
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
6772
) {
6773
yield* Ref.set(activeSelection, null);
6774
+ yield* validateModelSelection(modelSelection);
6775
const requestedModel = flavor.resolveModelId?.(modelSelection) ?? modelSelection.model;
6776
// Invalid params is the agent refusing the value, and the runtime
6777
// raises the same code when the session's model option does not offer
@@ -6766,10 +6799,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6799
if (modelOption?.type === "select") {
6800
if (
6801
isCustomModel ||
6769
- modelOption.options.some((entry) =>
6770
- "value" in entry
6771
- ? entry.value === requestedModel
6772
- : entry.options.some((choice) => choice.value === requestedModel),
6802
+ flattenSelectChoices(modelOption.options).some(
6803
+ (choice) => choice.value === requestedModel,
6804
)
6805
) {
6806
yield* runtime
@@ -6941,6 +6972,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6972
nativeBuildConfigurationBySessionId.delete(startResult.sessionId);
6973
}
6974
}
6975
+ yield* validateModelSelection(modelSelection);
6976
yield* (
6977
flavor.onSessionConfigurationUpdate?.(
6978
yield* runtime.getConfigOptions,
@@ -7448,6 +7480,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7480
yield* Ref.set(activeInteractionMode, turnInput.runtimePolicy.interactionMode);
7481
}
7482
}
7483
+ yield* validateModelSelection(turnInput.modelSelection);
7484
yield* Ref.set(lastTurnRoute, {
7485
threadId: turnInput.threadId,
7486
providerThreadId: turnInput.providerThread.id,