Skip to content

Commit 44caa0f

Browse files
fix(server): a recovered question accepts an empty multi-select answer
After a restart, pending questions are answered as a message. An optional multi-select answered with nothing checked now replies "None selected" instead of failing. Adds an OpenCode 2 transcript test for the empty multiselect reply and the minItems requirement. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent fa1ba13 commit 44caa0f

3 files changed

Lines changed: 80 additions & 3 deletions

File tree

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,75 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
21822182
}).pipe(Effect.scoped),
21832183
);
21842184

2185+
it.effect("answers an optional multiselect with none and keeps a minimum choice required", () =>
2186+
Effect.gen(function* () {
2187+
const formID = "frm_0eb79ab35001fkvFECSh3wYNVE";
2188+
const { runtime, thread } = yield* resumed([
2189+
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
2190+
promptAccepted,
2191+
event("session.execution.started", { sessionID: SESSION }),
2192+
event("form.created", {
2193+
form: {
2194+
id: formID,
2195+
sessionID: SESSION,
2196+
title: "Setup",
2197+
fields: [
2198+
{
2199+
key: "extras",
2200+
type: "multiselect",
2201+
title: "Extras",
2202+
options: [
2203+
{ value: "lint", label: "Lint" },
2204+
{ value: "tests", label: "Tests" },
2205+
],
2206+
},
2207+
{
2208+
key: "targets",
2209+
type: "multiselect",
2210+
title: "Targets",
2211+
minItems: 1,
2212+
options: [{ value: "web", label: "Web" }],
2213+
},
2214+
],
2215+
},
2216+
}),
2217+
out("session.form.reply", {
2218+
sessionID: SESSION,
2219+
formID,
2220+
answer: { extras: [], targets: ["web"] },
2221+
}),
2222+
reply("session.form.reply", null),
2223+
event("session.execution.succeeded", { sessionID: SESSION }),
2224+
]);
2225+
const shown = yield* runtime.events.pipe(
2226+
Stream.takeUntil((event) => event.type === "runtime_request.updated"),
2227+
Stream.runCollect,
2228+
Effect.forkScoped,
2229+
);
2230+
yield* runtime.startTurn(turnInput(thread));
2231+
const events = yield* Fiber.join(shown);
2232+
const questions = events.flatMap((event) =>
2233+
event.type === "turn_item.updated" && event.turnItem.type === "user_input_request"
2234+
? event.turnItem.questions
2235+
: [],
2236+
);
2237+
assert.deepEqual(
2238+
questions.map((question) => [question.id, question.required]),
2239+
[
2240+
["extras", undefined],
2241+
["targets", true],
2242+
],
2243+
);
2244+
const request = events.find((event) => event.type === "runtime_request.updated");
2245+
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
2246+
yield* runtime.respondToRuntimeRequest({
2247+
requestId: request!.runtimeRequest.id,
2248+
answers: { extras: [], targets: ["web"] },
2249+
});
2250+
assert.equal((yield* Fiber.join(terminal))?.status, "completed");
2251+
}).pipe(Effect.scoped),
2252+
);
2253+
21852254
it.effect("asks a subagent's permission request on the parent thread's turn", () =>
21862255
Effect.gen(function* () {
21872256
const child = "ses_f0e5aa64cffelFnoQRL0DAA9BH";

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9386,6 +9386,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
93869386
}
93879387
for (const question of approvalTurnItem.questions) {
93889388
const answer = answers?.[question.id];
9389+
if (
9390+
question.multiSelect === true &&
9391+
question.required !== true &&
9392+
Array.isArray(answer) &&
9393+
answer.length === 0
9394+
) {
9395+
replies.push(`${question.question}\nNone selected`);
9396+
continue;
9397+
}
93899398
const answered = isMessageQuestionAnswer(answer);
93909399
// Clients send "" for a skipped optional question, such as an attachment-only answer.
93919400
if (!answered && question.required === false) continue;

‎apps/server/src/orchestration-v2/runtimeLayer.test.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,6 @@ it.layer(layerTest)("OrchestrationV2LayerLive", (it) => {
16681668
const beforeSequence = yield* eventSink.latestSequence();
16691669
for (const [index, answers] of [
16701670
{ color: " ", sizes: ["Small"] },
1671-
{ color: "Blue", sizes: [] },
16721671
{ color: "Blue", sizes: ["Small", " "] },
16731672
{ color: "Blue", sizes: ["Small"], extra: " " },
16741673
].entries()) {
@@ -1693,7 +1692,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive", (it) => {
16931692
commandId: CommandId.make("runtime-async-question-answer"),
16941693
threadId,
16951694
requestId,
1696-
answers: { color: " Blue ", sizes: ["Small", "Large"], note: "" },
1695+
answers: { color: " Blue ", sizes: [], note: "" },
16971696
};
16981697
const accepted = yield* orchestrator.dispatch(command);
16991698
const repeated = yield* orchestrator.dispatch(command);
@@ -1718,7 +1717,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive", (it) => {
17181717
});
17191718
}
17201719
assert.equal(answered.messages.length, 1);
1721-
assert.equal(answered.messages[0]?.text, "Which color?\nBlue\n\nWhich sizes?\nSmall, Large");
1720+
assert.equal(answered.messages[0]?.text, "Which color?\nBlue\n\nWhich sizes?\nNone selected");
17221721
assert.equal(answered.messages[0]?.role, "user");
17231722
assert.equal(answered.runs.length, 1);
17241723
assert.deepEqual(

0 commit comments

Comments
 (0)