Skip to content

Commit aa146b8

Browse files
committed
fix(acp): reject models unavailable to the active session
1 parent 9e09926 commit aa146b8

3 files changed

Lines changed: 68 additions & 44 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ describe("AcpRegistryAdapterV2", () => {
771771
);
772772

773773
// regression: #19519 models come from session model state, not a hardcoded list
774-
it.effect("leaves unadvertised model IDs alone in both model selection protocols", () =>
774+
it.effect("keeps unadvertised default and auto selections agent-controlled", () =>
775775
Effect.gen(function* () {
776776
const { configurations } = yield* openWithStoredPicks({
777777
setup: {
@@ -781,15 +781,7 @@ describe("AcpRegistryAdapterV2", () => {
781781
},
782782
},
783783
storedModel: "default",
784-
turnModels: [
785-
"auto",
786-
"removed-model",
787-
"other",
788-
"default",
789-
"auto",
790-
"hermes",
791-
"removed-model",
792-
],
784+
turnModels: ["auto", "default", "other", "default", "auto", "default", "auto"],
793785
pickFrames: [
794786
...prompt(),
795787
...prompt(),

‎apps/server/src/orchestration-v2/testkit/AcpRegistryReplayFixtures.integration.test.ts‎

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ describe("ACP registry replay fixtures", () => {
3232
{ name: "open", firstTurn: false, code: -32602 },
3333
{ name: "switch", firstTurn: true, code: -32602 },
3434
{ name: "authentication", firstTurn: false, code: -32000 },
35+
{ name: "restricted-config", firstTurn: false, code: -32602 },
36+
{ name: "restricted-legacy", firstTurn: false, code: -32602 },
3537
])("preserves the ACP model-write $name failure through orchestration", (testCase) =>
3638
Effect.gen(function* () {
3739
const name = `acp_model_write_${testCase.name}`;
3840
const sessionId = "grok-replay-session-1";
3941
const rejectedModel = "replay-model-b";
42+
const restricted = testCase.name.startsWith("restricted-");
43+
const legacy = testCase.name === "restricted-legacy";
4044
const modelSelection = {
4145
instanceId: ProviderInstanceId.make("acpRegistry"),
4246
model: rejectedModel,
@@ -61,48 +65,63 @@ describe("ACP registry replay fixtures", () => {
6165
method: "session/new",
6266
result: {
6367
sessionId,
64-
configOptions: [
65-
{
66-
id: "model",
67-
name: "Model",
68-
category: "model",
69-
type: "select",
70-
currentValue: "replay-model-a",
71-
options: [
72-
{ value: "replay-model-a", name: "Model A" },
73-
{ value: rejectedModel, name: "Model B" },
68+
configOptions: legacy
69+
? []
70+
: [
71+
{
72+
id: "model",
73+
name: "Model",
74+
category: "model",
75+
type: "select",
76+
currentValue: "replay-model-a",
77+
options: [
78+
{ value: "replay-model-a", name: "Model A" },
79+
...(!restricted ? [{ value: rejectedModel, name: "Model B" }] : []),
80+
],
81+
},
7482
],
75-
},
76-
],
83+
...(legacy
84+
? {
85+
models: {
86+
currentModelId: "replay-model-a",
87+
availableModels: [{ modelId: "replay-model-a", name: "Model A" }],
88+
},
89+
}
90+
: {}),
7791
},
7892
},
7993
},
80-
...(testCase.firstTurn
94+
...(testCase.firstTurn || restricted
8195
? recorded.entries
8296
.slice(sessionIndex + 1)
8397
.filter((entry) => entry.type !== "runtime_exit")
8498
: []),
85-
{
86-
type: "expect_outbound",
87-
label: "session.set_model",
88-
frame: {
89-
kind: "request",
90-
method: "session/set_config_option",
91-
params: { sessionId, configId: "model", value: rejectedModel },
92-
},
93-
},
94-
{
95-
type: "emit_inbound",
96-
label: "session.set_model.rejected",
97-
frame: {
98-
kind: "response",
99-
method: "session/set_config_option",
100-
error: {
101-
code: testCase.code,
102-
message: testCase.code === -32602 ? "Invalid provider" : "Authentication required",
103-
},
104-
},
105-
},
99+
...(!restricted
100+
? [
101+
{
102+
type: "expect_outbound" as const,
103+
label: "session.set_model",
104+
frame: {
105+
kind: "request",
106+
method: "session/set_config_option",
107+
params: { sessionId, configId: "model", value: rejectedModel },
108+
},
109+
},
110+
{
111+
type: "emit_inbound" as const,
112+
label: "session.set_model.rejected",
113+
frame: {
114+
kind: "response",
115+
method: "session/set_config_option",
116+
error: {
117+
code: testCase.code,
118+
message:
119+
testCase.code === -32602 ? "Invalid provider" : "Authentication required",
120+
},
121+
},
122+
},
123+
]
124+
: []),
106125
],
107126
} satisfies ProviderReplayTranscript;
108127
const materialized = yield* materializeFixtureInput({

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6705,6 +6705,19 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
67056705
}
67066706
appliedModel = requestedModel;
67076707
}
6708+
if (
6709+
appliedModel === undefined &&
6710+
requestedModel !== "default" &&
6711+
requestedModel !== "auto" &&
6712+
(modelOption?.type === "select" || modelState != null)
6713+
) {
6714+
return yield* new AcpModelSelectionError({
6715+
model: modelSelection.model,
6716+
cause: EffectAcpErrors.AcpRequestError.invalidParams(
6717+
"The requested model is not available in this session.",
6718+
),
6719+
});
6720+
}
67086721
}
67096722
if (appliedModel !== undefined) {
67106723
const applied = appliedModel;

0 commit comments

Comments
 (0)