Skip to content

Commit ca846dd

Browse files
committed
fix(server): blank question option descriptions no longer fail the run
Claude's AskUserQuestion and Pi's extension select dialogs can produce an option with an empty description. The user-input question contract requires a non-empty one, so the turn item failed to decode during event ingestion and the run was marked failed while the provider still waited for the answer. Fall back to the option label, as the Codex and OpenCode adapters already do. Fixes #15316
1 parent 429c625 commit ca846dd

4 files changed

Lines changed: 78 additions & 8 deletions

File tree

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
NodeId,
2020
type OrchestrationV2AppThread,
2121
type OrchestrationV2ProviderThread,
22+
OrchestrationV2UserInputQuestion,
2223
ProjectId,
2324
ProviderInstanceId,
2425
type ProviderApprovalDecision,
@@ -118,6 +119,10 @@ function makeClaudeTestAppThread(input: {
118119
};
119120
}
120121

122+
const decodeUserInputQuestions = Schema.decodeUnknownExit(
123+
Schema.Array(OrchestrationV2UserInputQuestion),
124+
);
125+
121126
function makeClaudeTestTurnInput(input: {
122127
readonly threadId: ThreadId;
123128
readonly providerThread: OrchestrationV2ProviderThread;
@@ -268,6 +273,31 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
268273
);
269274
});
270275

276+
it("fills blank AskUserQuestion option descriptions from the label", () => {
277+
// A question with a blank description used to fail event ingestion, which
278+
// failed the run while Claude still waited for the answer.
279+
const questions = ClaudeAdapterV2.claudeUserInputQuestions({
280+
questions: [
281+
{
282+
header: "Naming",
283+
question: "Which name?",
284+
options: [
285+
{ label: "Recorder", description: "Matches the package name." },
286+
{ label: "Keep", description: "" },
287+
{ label: "Other", description: " " },
288+
{ label: "Ask later" },
289+
],
290+
multiSelect: false,
291+
},
292+
],
293+
});
294+
assert.deepEqual(
295+
questions[0]?.options.map((option) => option.description),
296+
["Matches the package name.", "Keep", "Other", "Ask later"],
297+
);
298+
assert.isTrue(Exit.isSuccess(decodeUserInputQuestions(questions)));
299+
});
300+
271301
it("normalizes Claude todo and proposed-plan tool input", () => {
272302
assert.deepEqual(
273303
ClaudeAdapterV2.claudeTodoSteps({

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,13 +2840,10 @@ export function claudeUserInputQuestions(
28402840
const optionRecord = option as Record<string, unknown>;
28412841
const label = typeof optionRecord.label === "string" ? optionRecord.label.trim() : "";
28422842
if (label.length === 0) return [];
2843-
return [
2844-
{
2845-
label,
2846-
description:
2847-
typeof optionRecord.description === "string" ? optionRecord.description.trim() : "",
2848-
},
2849-
];
2843+
const description =
2844+
typeof optionRecord.description === "string" ? optionRecord.description.trim() : "";
2845+
// The question contract requires a description; Claude may send it blank.
2846+
return [{ label, description: description.length > 0 ? description : label }];
28502847
})
28512848
: [];
28522849
return [

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import {
1515
type OrchestrationV2AppThread,
1616
type OrchestrationV2ProviderThread,
1717
type OrchestrationV2ProviderTurn,
18+
OrchestrationV2UserInputQuestion,
1819
} from "@t3tools/contracts";
1920
import * as Cause from "effect/Cause";
2021
import * as DateTime from "effect/DateTime";
2122
import * as Duration from "effect/Duration";
2223
import * as Effect from "effect/Effect";
24+
import * as Exit from "effect/Exit";
2325
import * as Fiber from "effect/Fiber";
2426
import * as FileSystem from "effect/FileSystem";
2527
import * as Layer from "effect/Layer";
@@ -50,6 +52,9 @@ const serverConfigLayer = ServerConfig.layerTest(process.cwd(), {
5052
const testLayer = Layer.mergeAll(NodeServices.layer, IdAllocator.layer, serverConfigLayer);
5153

5254
const decodeJsonLine = Schema.decodeSync(Schema.fromJsonString(Schema.Unknown));
55+
const decodeUserInputQuestions = Schema.decodeUnknownExit(
56+
Schema.Array(OrchestrationV2UserInputQuestion),
57+
);
5358
const encodeJsonLine = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
5459

5560
const PI_INSTANCE_ID = ProviderInstanceId.make("pi");
@@ -1446,6 +1451,40 @@ describe("PiAdapterV2", () => {
14461451
}).pipe(Effect.scoped, Effect.provide(testLayer)),
14471452
);
14481453

1454+
it.effect("describes an empty extension select option", () =>
1455+
Effect.gen(function* () {
1456+
const fake = yield* makeFakePi;
1457+
const { runtime, takeEvent } = yield* openRuntime(fake);
1458+
yield* runtime.ensureThread({
1459+
threadId: THREAD_ID,
1460+
modelSelection: modelSelection("default"),
1461+
runtimePolicy,
1462+
});
1463+
yield* fake.emit({
1464+
type: "extension_ui_request",
1465+
id: "ui-select",
1466+
method: "select",
1467+
title: "Pick a tag",
1468+
options: ["stable", ""],
1469+
});
1470+
const event = yield* takeEvent(
1471+
(event) =>
1472+
event.type === "turn_item.updated" && event.turnItem.type === "user_input_request",
1473+
);
1474+
if (event.type !== "turn_item.updated" || event.turnItem.type !== "user_input_request") {
1475+
return assert.fail("expected a user input request");
1476+
}
1477+
assert.deepEqual(
1478+
event.turnItem.questions[0]?.options.map((option) => [option.label, option.value]),
1479+
[
1480+
["stable", "stable"],
1481+
["Empty value", ""],
1482+
],
1483+
);
1484+
assert.isTrue(Exit.isSuccess(decodeUserInputQuestions(event.turnItem.questions)));
1485+
}).pipe(Effect.scoped, Effect.provide(testLayer)),
1486+
);
1487+
14491488
it.effect("raises bridge edit confirmations as file-change approvals", () =>
14501489
Effect.gen(function* () {
14511490
const fake = yield* makeFakePi;

‎apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2900,7 +2900,11 @@ function piQuestion(
29002900
method === "select" && Array.isArray(event["options"])
29012901
? event["options"]
29022902
.filter((option): option is string => typeof option === "string")
2903-
.map((option) => ({ label: option || "Empty value", description: option, value: option }))
2903+
.map((option) => ({
2904+
label: option || "Empty value",
2905+
description: option || "Empty value",
2906+
value: option,
2907+
}))
29042908
: [
29052909
{
29062910
label: "Submit empty value",

0 commit comments

Comments
 (0)