Skip to content

Commit 70e476b

Browse files
StiensWoutclaude
andcommitted
fix(acp): titled multi-select form questions reach the user, and empty selections stay valid
ACP form elicitations with a titled multi-select (`items.anyOf` of `{ const, title }` options) were rejected by effect-acp before the adapter saw them: the agent got an invalid-params error. The schema generator recursed into `properties` maps as if they were schemas, so TitledMultiSelectItems' property named `anyOf` was read as a combinator and the type was generated as Schema.Never in v1 and v2. The generator now maps `properties` values as subschemas while keeping their names, and leaves literal data keywords (`const`, `default`, `enum`, `examples`) alone. The regenerated files change only TitledMultiSelectItems; the generator also moves the five elicitation declarations that depend on it. They were produced with @effect/openapi-generator 4.0.0-rc.112, the version that reproduces the committed files byte for byte. The form parser offers titled items as a fixed multi-select with each option's const as its value. Multi-select answers must be arrays. An explicit `[]` is kept, for required and optional fields, instead of cancelling or being dropped; a selection of only unknown options is still invalid, and `minItems`/`maxItems` are enforced. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c7bb68e commit 70e476b

11 files changed

Lines changed: 2522 additions & 2194 deletions

File tree

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4382,6 +4382,15 @@ describe("AcpAdapterV2", () => {
43824382
],
43834383
},
43844384
tags: { type: "array", items: { type: "string", enum: ["a", "b", "c"] } },
4385+
areas: {
4386+
type: "array",
4387+
items: {
4388+
anyOf: [
4389+
{ const: "api", title: "API", description: "Server routes" },
4390+
{ const: "ui", title: "Interface" },
4391+
],
4392+
},
4393+
},
43854394
confirm: { type: "boolean" },
43864395
count: { type: "integer" },
43874396
ratio: { type: "number" },
@@ -4396,6 +4405,7 @@ describe("AcpAdapterV2", () => {
43964405
color: optionValues(byId.get("color"))?.[1],
43974406
size: optionValues(byId.get("size"))?.[1],
43984407
tags: ["c", "a", "unknown", "a"],
4408+
areas: optionValues(byId.get("areas"))?.toReversed(),
43994409
confirm: optionValues(byId.get("confirm"))?.[1],
44004410
count: "3",
44014411
ratio: " 0.5 ",
@@ -4436,6 +4446,13 @@ describe("AcpAdapterV2", () => {
44364446
multiSelect: true,
44374447
allowCustomAnswer: false,
44384448
},
4449+
{
4450+
id: "areas",
4451+
labels: ["API", "Interface"],
4452+
values: ["api", "ui"],
4453+
multiSelect: true,
4454+
allowCustomAnswer: false,
4455+
},
44394456
{
44404457
id: "confirm",
44414458
labels: ["true", "false"],
@@ -4458,6 +4475,7 @@ describe("AcpAdapterV2", () => {
44584475
color: "green",
44594476
size: "l",
44604477
tags: ["c", "a"],
4478+
areas: ["ui", "api"],
44614479
confirm: false,
44624480
count: 3,
44634481
ratio: 0.5,
@@ -4467,6 +4485,56 @@ describe("AcpAdapterV2", () => {
44674485
}).pipe(Effect.provide(layerTest), Effect.scoped),
44684486
);
44694487

4488+
it.live("keeps explicit empty selections and checks selection counts", () =>
4489+
Effect.gen(function* () {
4490+
const items = { type: "string", enum: ["a", "b", "c"] };
4491+
const requestedSchema = {
4492+
type: "object",
4493+
properties: {
4494+
none: { type: "array", items, default: [] },
4495+
all: { type: "array", items, maxItems: 3 },
4496+
optionalNone: { type: "array", items },
4497+
some: { type: "array", items, minItems: 1 },
4498+
tooMany: { type: "array", items, maxItems: 1 },
4499+
single: { type: "array", items },
4500+
unknownOnly: { type: "array", items },
4501+
omitted: { type: "array", items },
4502+
},
4503+
required: ["none", "all", "some"],
4504+
};
4505+
const accepted = yield* runFormElicitation({
4506+
name: "selection-counts",
4507+
requestedSchema,
4508+
answer: () => ({
4509+
none: [],
4510+
all: ["a", "b", "c"],
4511+
optionalNone: [],
4512+
some: ["b"],
4513+
// Optional and not valid selections, so they are left out.
4514+
tooMany: ["a", "b"],
4515+
single: "a",
4516+
unknownOnly: ["z"],
4517+
}),
4518+
});
4519+
assert.deepStrictEqual(accepted.response, {
4520+
action: "accept",
4521+
content: { none: [], all: ["a", "b", "c"], optionalNone: [], some: ["b"] },
4522+
});
4523+
const belowMinimum = yield* runFormElicitation({
4524+
name: "selection-below-minimum",
4525+
requestedSchema,
4526+
answer: () => ({ none: [], all: ["a"], some: [] }),
4527+
});
4528+
assert.deepStrictEqual(belowMinimum.response, { action: "cancel" });
4529+
const requiredOmitted = yield* runFormElicitation({
4530+
name: "selection-required-omitted",
4531+
requestedSchema,
4532+
answer: () => ({ all: ["a"], some: ["a"] }),
4533+
});
4534+
assert.deepStrictEqual(requiredOmitted.response, { action: "cancel" });
4535+
}).pipe(Effect.provide(layerTest), Effect.scoped),
4536+
);
4537+
44704538
it.live("cancels a form whose required answer does not fit, or that is dismissed", () =>
44714539
Effect.gen(function* () {
44724540
const requestedSchema = {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { OrchestratorFixtureInput } from "../shared.ts";
2+
3+
export const ACP_TITLED_MULTISELECT_PROMPT =
4+
"Ask which areas this fixture should cover, allowing several. After receiving the answer, respond exactly: titled multi-select fixture complete";
5+
6+
/**
7+
* An ACP form elicitation whose multi-select lists titled `anyOf` options.
8+
* The client submits option values, including one the form never offered.
9+
*/
10+
export function acpTitledMultiSelectInput(): OrchestratorFixtureInput {
11+
return {
12+
interactionMode: "plan",
13+
steps: [
14+
{ type: "message", text: ACP_TITLED_MULTISELECT_PROMPT },
15+
{
16+
type: "answer_next_user_input_request",
17+
answers: { fixture_areas: ["ui", "unknown", "schemas"] },
18+
},
19+
],
20+
};
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { assert } from "@effect/vitest";
2+
import type { ProviderReplayTranscript } from "@t3tools/contracts";
3+
4+
import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts";
5+
import {
6+
assertAllRuntimeRequestsResolved,
7+
assertAssistantTextIncludes,
8+
assertBaseProjection,
9+
assertRuntimeRequestKinds,
10+
assertSemanticProjectionIntegrity,
11+
assertTurnItemTypes,
12+
assertUserMessagesInclude,
13+
projectionFor,
14+
} from "../shared.ts";
15+
import { ACP_TITLED_MULTISELECT_PROMPT } from "./input.ts";
16+
17+
/** The transcript's expected `elicitation/create` response pins the typed answer. */
18+
export function assertAcpTitledMultiSelectOutput(
19+
result: OrchestratorV2ScenarioResult,
20+
transcript: ProviderReplayTranscript,
21+
) {
22+
assertBaseProjection({ result, transcript, runCount: 1, runStatuses: ["completed"] });
23+
const projection = projectionFor(result, transcript.scenario);
24+
assertSemanticProjectionIntegrity(projection);
25+
assertRuntimeRequestKinds(projection, ["user_input"]);
26+
assertAllRuntimeRequestsResolved(projection);
27+
assertTurnItemTypes(projection, ["user_message", "user_input_request", "assistant_message"]);
28+
assertUserMessagesInclude(projection, [ACP_TITLED_MULTISELECT_PROMPT]);
29+
assertAssistantTextIncludes(projection, "titled multi-select fixture complete");
30+
31+
const requestItem = projection.turnItems.find((item) => item.type === "user_input_request");
32+
assert.deepStrictEqual(requestItem?.type === "user_input_request" && requestItem.questions, [
33+
{
34+
id: "fixture_areas",
35+
header: "Areas",
36+
question: "Which areas should this fixture cover?",
37+
options: [
38+
{ label: "Strict schemas", description: "Typed wire shapes", value: "schemas" },
39+
{ label: "UI flexibility", description: "UI flexibility", value: "ui" },
40+
{ label: "Docs", description: "Docs", value: "docs" },
41+
],
42+
allowCustomAnswer: false,
43+
multiSelect: true,
44+
},
45+
]);
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{"type":"transcript_start","provider":"acpRegistry","protocol":"acp.ndjson-jsonrpc","version":"1","scenario":"acp_titled_multiselect","metadata":{"generatedBy":"protocol-semantic-fixture","nativeSessionId":"registry-replay-session-1"}}
2+
{"type":"expect_outbound","label":"initialize","frame":{"kind":"request","method":"initialize","params":{"protocolVersion":2,"info":"<any>","capabilities":"<any>","clientCapabilities":"<any>","clientInfo":"<any>"}}}
3+
{"type":"emit_inbound","label":"initialized","frame":{"kind":"response","method":"initialize","result":{"protocolVersion":1,"agentCapabilities":{"loadSession":true,"mcpCapabilities":{"http":true,"sse":true},"promptCapabilities":{"audio":false,"embeddedContext":true,"image":false}},"authMethods":[{"id":"replay","name":"Replay"}],"agentInfo":{"name":"generic-acp-replay","version":"1"}}}}
4+
{"type":"expect_outbound","label":"session.new","frame":{"kind":"request","method":"session/new","params":{"cwd":"<workspace>","mcpServers":"<any>"}}}
5+
{"type":"emit_inbound","label":"session.created","frame":{"kind":"response","method":"session/new","result":{"sessionId":"registry-replay-session-1"}}}
6+
{"type":"expect_outbound","label":"session.prompt","frame":{"kind":"request","method":"session/prompt","params":{"sessionId":"registry-replay-session-1","prompt":[{"type":"text","text":"<t3_code_instructions>\n<any>\n</t3_code_instructions>\n\n<user_request>\nAsk which areas this fixture should cover, allowing several. After receiving the answer, respond exactly: titled multi-select fixture complete\n</user_request>"}]}}}
7+
{"type":"emit_inbound","label":"elicitation.request","frame":{"kind":"request","method":"elicitation/create","params":{"sessionId":"registry-replay-session-1","mode":"form","message":"Choose the fixture areas.","requestedSchema":{"type":"object","title":"Fixture areas","properties":{"fixture_areas":{"type":"array","title":"Areas","description":"Which areas should this fixture cover?","minItems":1,"items":{"anyOf":[{"const":"schemas","title":"Strict schemas","description":"Typed wire shapes"},{"const":"ui","title":"UI flexibility"},{"const":"docs","title":"Docs"}]}}},"required":["fixture_areas"]}}}}
8+
{"type":"expect_outbound","label":"elicitation.response","frame":{"kind":"response","method":"elicitation/create","result":{"action":"accept","content":{"fixture_areas":["ui","schemas"]}}}}
9+
{"type":"emit_inbound","label":"assistant.final","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"registry-replay-session-1","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"titled multi-select fixture complete"}}}}}
10+
{"type":"emit_inbound","label":"prompt.completed","frame":{"kind":"response","method":"session/prompt","result":{"stopReason":"end_turn"}}}
11+
{"type":"runtime_exit","status":"success"}

‎apps/server/src/orchestration-v2/testkit/fixtures/index.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ import {
115115
} from "./plan_questions/codex_output.ts";
116116
import { assertOpenCodePlanQuestionsOutput } from "./plan_questions/opencode_output.ts";
117117
import { planQuestionsInput } from "./plan_questions/input.ts";
118+
import { acpTitledMultiSelectInput } from "./acp_titled_multiselect/input.ts";
119+
import { assertAcpTitledMultiSelectOutput } from "./acp_titled_multiselect/output.ts";
118120
import { assertProposedPlanOutput } from "./proposed_plan/codex_output.ts";
119121
import { assertProposedPlanCursorOutput } from "./proposed_plan/cursor_output.ts";
120122
import { proposedPlanInput } from "./proposed_plan/input.ts";
@@ -594,6 +596,22 @@ export const ORCHESTRATOR_REPLAY_FIXTURES: ReadonlyArray<OrchestratorReplayFixtu
594596
},
595597
],
596598
},
599+
{
600+
name: "acp_titled_multiselect",
601+
buildInput: acpTitledMultiSelectInput,
602+
providers: [
603+
{
604+
driver: ProviderDriverKind.make("acpRegistry"),
605+
transcriptFile: new URL(
606+
"./acp_titled_multiselect/registry_transcript.ndjson",
607+
import.meta.url,
608+
),
609+
modelSelection: ACP_REGISTRY_MODEL_SELECTION,
610+
runtimePolicyOverride: READ_ONLY_NEVER_POLICY,
611+
assertOutput: assertAcpTitledMultiSelectOutput,
612+
},
613+
],
614+
},
597615
{
598616
name: "simple",
599617
buildInput: simpleInput,

‎packages/effect-acp/scripts/generate.ts‎

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,37 @@ function isJsonArray(value: Schema.Json | undefined): value is ReadonlyArray<Sch
166166
return Array.isArray(value);
167167
}
168168

169+
// Keywords whose values are literal JSON data, not schemas.
170+
const DATA_KEYWORDS = new Set(["const", "default", "enum", "examples"]);
171+
172+
// Applies `transform` to every subschema of a schema object. `properties` maps names to
173+
// schemas, so its keys stay property names: ACP has properties named `anyOf`, `oneOf`, and
174+
// `type` that must not be read as keywords. Literal data values are left untouched.
175+
function mapSubschemas(
176+
value: { readonly [key: string]: Schema.Json },
177+
transform: (schema: Schema.Json) => Schema.Json,
178+
): Record<string, Schema.Json> {
179+
return Object.fromEntries(
180+
Object.entries(value).map(([key, child]) => {
181+
if (DATA_KEYWORDS.has(key)) return [key, child];
182+
if (
183+
key === "properties" &&
184+
child !== null &&
185+
typeof child === "object" &&
186+
!isJsonArray(child)
187+
) {
188+
return [
189+
key,
190+
Object.fromEntries(
191+
Object.entries(child).map(([name, schema]) => [name, transform(schema)]),
192+
),
193+
];
194+
}
195+
return [key, isJsonArray(child) ? child.map(transform) : transform(child)];
196+
}),
197+
);
198+
}
199+
169200
function normalizeSchemaKeywords(value: Schema.Json): Schema.Json {
170201
if (isJsonArray(value)) {
171202
return value.map(normalizeSchemaKeywords);
@@ -174,11 +205,7 @@ function normalizeSchemaKeywords(value: Schema.Json): Schema.Json {
174205
return value;
175206
}
176207

177-
const normalizedEntries = Object.entries(value).map(([key, child]) => [
178-
key,
179-
normalizeSchemaKeywords(child),
180-
]);
181-
const normalizedObject = Object.fromEntries(normalizedEntries) as Record<string, Schema.Json>;
208+
const normalizedObject = mapSubschemas(value, normalizeSchemaKeywords);
182209
// ACP's forward-compatible variants exclude known discriminator values.
183210
// The Effect generator does not support `not`; express this exact exclusion
184211
// as a string pattern while preserving validation of the known variants.
@@ -316,9 +343,7 @@ function flattenCompositions(
316343
): Schema.Json {
317344
if (isJsonArray(value)) return value.map((child) => flattenCompositions(child, definitions));
318345
if (value === null || typeof value !== "object") return value;
319-
const normalized = Object.fromEntries(
320-
Object.entries(value).map(([key, child]) => [key, flattenCompositions(child, definitions)]),
321-
);
346+
const normalized = mapSubschemas(value, (child) => flattenCompositions(child, definitions));
322347
const { allOf, anyOf, ...base } = normalized;
323348
const merge = (left: Schema.Json, right: Schema.Json): Schema.Json => {
324349
if (

0 commit comments

Comments
 (0)