Skip to content

Commit 603ef49

Browse files
committed
fix(acp): revalidate selections after catalog changes
1 parent 9d470ee commit 603ef49

3 files changed

Lines changed: 112 additions & 59 deletions

File tree

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import * as HttpClientResponse from "effect/http/HttpClientResponse";
2828
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
2929
import * as EffectAcpErrors from "effect-acp/errors";
3030

31+
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
3132
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
3233
import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
3334
import {
@@ -466,6 +467,7 @@ describe("AcpRegistryAdapterV2", () => {
466467
readonly storedModel?: string;
467468
readonly storedModePick?: string;
468469
readonly turnModels?: ReadonlyArray<string>;
470+
readonly rejectedModel?: string;
469471
}) {
470472
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
471473
// Scope release gives the replay agent at most a second to exit, so the status
@@ -603,7 +605,19 @@ describe("AcpRegistryAdapterV2", () => {
603605
configurations.push(published);
604606
current = target;
605607
}
606-
}).pipe(Effect.scoped);
608+
}).pipe(
609+
Effect.match({
610+
onFailure: (error) => {
611+
assert.isDefined(input.rejectedModel);
612+
assert.equal(
613+
makeProviderFailure({ cause: error }).message,
614+
`The agent did not accept the model "${input.rejectedModel}". Choose another model for this provider, then retry.`,
615+
);
616+
},
617+
onSuccess: () => assert.isUndefined(input.rejectedModel),
618+
}),
619+
Effect.scoped,
620+
);
607621
yield* Effect.all(agentExits, { discard: true });
608622
yield* makeAcpReplayCompletenessAssertion(fileSystem, statusPath, transcript);
609623
return { configurations };
@@ -770,6 +784,45 @@ describe("AcpRegistryAdapterV2", () => {
770784
}).pipe(Effect.provide(layerTest), Effect.scoped),
771785
);
772786

787+
it.effect.each(["config", "legacy", "updated-config"] as const)(
788+
"rejects an unavailable explicit model in a %s catalog before inference",
789+
(catalog) =>
790+
openWithStoredPicks({
791+
setup:
792+
catalog === "legacy"
793+
? {
794+
models: {
795+
currentModelId: "other",
796+
availableModels: [{ modelId: "other", name: "Other" }],
797+
},
798+
}
799+
: {
800+
configOptions: [
801+
{
802+
...modelOption("model", "hermes"),
803+
options: [{ value: "hermes", name: "Hermes" }],
804+
},
805+
],
806+
},
807+
storedModel: catalog === "updated-config" ? "hermes" : "missing",
808+
...(catalog === "updated-config" ? { turnModels: ["hermes", "hermes"] } : {}),
809+
rejectedModel: catalog === "updated-config" ? "hermes" : "missing",
810+
pickFrames:
811+
catalog === "updated-config"
812+
? [
813+
...prompt(
814+
configOptionUpdate([
815+
{
816+
...modelOption("model", "other"),
817+
options: [{ value: "other", name: "Other" }],
818+
},
819+
]),
820+
),
821+
]
822+
: [],
823+
}).pipe(Effect.provide(layerTest), Effect.scoped),
824+
);
825+
773826
// regression: #19519 models come from session model state, not a hardcoded list
774827
it.effect("keeps unadvertised default and auto selections agent-controlled", () =>
775828
Effect.gen(function* () {

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

Lines changed: 34 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,11 @@ 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 },
3735
])("preserves the ACP model-write $name failure through orchestration", (testCase) =>
3836
Effect.gen(function* () {
3937
const name = `acp_model_write_${testCase.name}`;
4038
const sessionId = "grok-replay-session-1";
4139
const rejectedModel = "replay-model-b";
42-
const restricted = testCase.name.startsWith("restricted-");
43-
const legacy = testCase.name === "restricted-legacy";
4440
const modelSelection = {
4541
instanceId: ProviderInstanceId.make("acpRegistry"),
4642
model: rejectedModel,
@@ -65,63 +61,48 @@ describe("ACP registry replay fixtures", () => {
6561
method: "session/new",
6662
result: {
6763
sessionId,
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-
},
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" },
8274
],
83-
...(legacy
84-
? {
85-
models: {
86-
currentModelId: "replay-model-a",
87-
availableModels: [{ modelId: "replay-model-a", name: "Model A" }],
88-
},
89-
}
90-
: {}),
75+
},
76+
],
9177
},
9278
},
9379
},
94-
...(testCase.firstTurn || restricted
80+
...(testCase.firstTurn
9581
? recorded.entries
9682
.slice(sessionIndex + 1)
9783
.filter((entry) => entry.type !== "runtime_exit")
9884
: []),
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-
: []),
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+
},
125106
],
126107
} satisfies ProviderReplayTranscript;
127108
const materialized = yield* materializeFixtureInput({

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ import {
9595
resolveEmbeddedTerminalContent,
9696
type AcpClientTerminals,
9797
} from "./clientTerminals.ts";
98-
import { ACP_EMPTY_OPTION_VALUE, ACP_SESSION_MODE_OPTION_ID } from "./sessionConfig.ts";
98+
import {
99+
ACP_EMPTY_OPTION_VALUE,
100+
ACP_SESSION_MODE_OPTION_ID,
101+
flattenSelectChoices,
102+
} from "./sessionConfig.ts";
99103
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
100104
import {
101105
t3AcpPromptWithInstructions,
@@ -5814,6 +5818,23 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
58145818
Effect.void
58155819
);
58165820
}
5821+
if (notification.update.sessionUpdate === "config_option_update") {
5822+
const selection = yield* Ref.get(activeSelection);
5823+
const modelOption = findModelConfigOption(yield* runtime.getConfigOptions);
5824+
const model =
5825+
selection === null
5826+
? undefined
5827+
: (flavor.resolveModelId?.(selection) ?? selection.model);
5828+
if (
5829+
model !== undefined &&
5830+
modelOption?.type === "select" &&
5831+
!flattenSelectChoices(modelOption.options).some(
5832+
(choice) => choice.value === model,
5833+
)
5834+
) {
5835+
yield* Ref.set(activeSelection, null);
5836+
}
5837+
}
58175838
if (
58185839
notification.update.sessionUpdate === "config_option_update" ||
58195840
notification.update.sessionUpdate === "current_mode_update"
@@ -6697,10 +6718,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
66976718
if (modelOption?.type === "select") {
66986719
if (
66996720
isCustomModel ||
6700-
modelOption.options.some((entry) =>
6701-
"value" in entry
6702-
? entry.value === requestedModel
6703-
: entry.options.some((choice) => choice.value === requestedModel),
6721+
flattenSelectChoices(modelOption.options).some(
6722+
(choice) => choice.value === requestedModel,
67046723
)
67056724
) {
67066725
yield* runtime

0 commit comments

Comments
 (0)