Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(server): key AskUserQuestion answers by question text (#2404)

Bas Milius44b39fe2ec47
diff --git a/apps/server/src/provider/Layers/ClaudeAdapter.test.ts b/apps/server/src/provider/Layers/ClaudeAdapter.test.ts
index 14cca34b2..4c71a016f 100644
--- a/apps/server/src/provider/Layers/ClaudeAdapter.test.ts
+++ b/apps/server/src/provider/Layers/ClaudeAdapter.test.ts
@@ -3296,6 +3296,9 @@ describe("ClaudeAdapterLive", () => {
assert.equal(typeof requestId, "string");
assert.equal(requestedEvent.value.payload.questions.length, 1);
assert.equal(requestedEvent.value.payload.questions[0]?.question, "Which framework?");
+ // Regression for #2388: `id` must equal the full question text so the
+ // UI's draft-answer key matches what the SDK looks up downstream.
+ assert.equal(requestedEvent.value.payload.questions[0]?.id, "Which framework?");
assert.deepEqual(requestedEvent.value.providerRefs, {
providerItemId: ProviderItemId.make("tool-ask-1"),
});
@@ -3330,6 +3333,34 @@ describe("ClaudeAdapterLive", () => {
assert.deepEqual(updatedInput.answers, { "Which framework?": "React" });
// Original questions should be passed through.
assert.deepEqual(updatedInput.questions, askInput.questions);
+
+ // Compatibility check for #2388: the answers shape we hand to the SDK
+ // must produce a non-empty rendered tool_result on BOTH SDK iteration
+ // patterns we have seen, so we don't regress the issue and we don't
+ // break users still on the older Claude CLI.
+ const sdkAnswers = updatedInput.answers as Record<string, unknown>;
+ const sdkQuestions = updatedInput.questions as ReadonlyArray<{
+ readonly question: string;
+ }>;
+
+ // Claude CLI 2.1.119 — key-agnostic Object.entries iteration. Any key
+ // works here, but it must at least round-trip into a non-empty string.
+ const v119Rendered = Object.entries(sdkAnswers)
+ .map(([key, value]) => `"${key}"="${String(value)}"`)
+ .join(", ");
+ assert.equal(v119Rendered, '"Which framework?"="React"');
+
+ // Claude CLI 2.1.121 — lookup by full question text. This is the path
+ // that regressed in #2388 when the answers were keyed by `header`.
+ const v121Rendered = sdkQuestions
+ .map(({ question }) => {
+ const answer = sdkAnswers[question];
+ return answer === undefined ? null : `"${question}"="${String(answer)}"`;
+ })
+ .filter((entry): entry is string => entry !== null)
+ .join(", ");
+ assert.notEqual(v121Rendered, "", "Expected non-empty SDK 2.1.121 tool_result (#2388)");
+ assert.equal(v121Rendered, '"Which framework?"="React"');
}).pipe(
Effect.provideService(Random.Random, makeDeterministicRandomService()),
Effect.provide(harness.layer),
diff --git a/apps/server/src/provider/Layers/ClaudeAdapter.ts b/apps/server/src/provider/Layers/ClaudeAdapter.ts
index c4cffbb16..2fd40f6ec 100644
--- a/apps/server/src/provider/Layers/ClaudeAdapter.ts
+++ b/apps/server/src/provider/Layers/ClaudeAdapter.ts
@@ -2563,10 +2563,14 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
const requestId = ApprovalRequestId.make(yield* Random.nextUUIDv4);
// Parse questions from the SDK's AskUserQuestion input.
+ // `id` MUST equal the full question text — Claude SDK >= 2.1.121 looks
+ // up answers by question text in `mapToolResultToToolResultBlockParam`,
+ // so the key the UI uses to keep its draft answer must match the SDK's
+ // expected lookup key. See https://github.com/pingdotgg/t3code/issues/2388
const rawQuestions = Array.isArray(toolInput.questions) ? toolInput.questions : [];
const questions: Array<UserInputQuestion> = rawQuestions.map(
(q: Record<string, unknown>, idx: number) => ({
- id: typeof q.header === "string" ? q.header : `q-${idx}`,
+ id: typeof q.question === "string" && q.question.length > 0 ? q.question : `q-${idx}`,
header: typeof q.header === "string" ? q.header : `Question ${idx + 1}`,
question: typeof q.question === "string" ? q.question : "",
options: Array.isArray(q.options)