The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 00:30 UTC
fix(server): reject unusable user-input answers before the request resolves (#14884)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Jonas B. committed
Oct 19, 2026 at 19:09 UTC
128846e399e63a4be23418a8572b5fd752f462e6
2 files changed
+81
-6
apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts
+54
-1
@@ -28,6 +28,7 @@ import * as SqlClient from "effect/sql/SqlClient";
28
import * as SqlitePersistence from "../persistence/Sqlite.ts";
29
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
30
import * as DelegatedTaskQuestionReactor from "./DelegatedTaskQuestionReactor.ts";
31
+import * as EffectOutbox from "./EffectOutbox.ts";
32
import * as EventSink from "./EventSink.ts";
33
import * as Orchestrator from "./Orchestrator.ts";
34
import * as ProjectionStore from "./ProjectionStore.ts";
@@ -48,6 +49,7 @@ const layerDatabase = SqlitePersistence.layerMemory;
49
const layerTest = Layer.mergeAll(
50
layerDatabase,
51
ProjectionStore.layer.pipe(Layer.provide(layerDatabase)),
52
+ EffectOutbox.layer.pipe(Layer.provide(layerDatabase)),
53
ProviderReplayHarness.layerWithRegistry(
54
{ name: "control-reads" },
55
ProviderAdapterRegistry.layerFromAdapters([adapter]),
@@ -124,6 +126,7 @@ it.effect(
126
const orchestrator = yield* Orchestrator.OrchestratorV2;
127
const projections = yield* ProjectionStore.ProjectionStoreV2;
128
const sql = yield* SqlClient.SqlClient;
129
+ const outbox = yield* EffectOutbox.EffectOutboxV2;
130
const threadId = ThreadId.make("thread:control-dispatch");
131
const now = yield* DateTime.now;
132
yield* orchestrator.dispatch({
@@ -270,6 +273,37 @@ it.effect(
273
questions: [],
274
},
275
});
276
+ const answers = { text: "Blue", list: ["Red"], codex: { answers: ["Green"] } };
277
+ const normalizedAnswers = { ...answers, codex: ["Green"] };
278
+ if (mode === "live") {
279
+ const pending = yield* projections.getRuntimeResponseContext(threadId, requestId);
280
+ const sequence = yield* orchestrator.getThreadEventSequence(threadId);
281
+ for (const [index, value] of [
282
+ null,
283
+ 42,
284
+ { choice: "Blue" },
285
+ ["Blue", 42],
286
+ { answers: [42] },
287
+ ].entries()) {
288
+ const commandId = CommandId.make(`invalid-answer:${index}`);
289
+ const result = yield* orchestrator
290
+ .dispatch({
291
+ type: "runtime-request.respond",
292
+ commandId,
293
+ threadId,
294
+ requestId,
295
+ answers: { ...answers, invalid: value },
296
+ })
297
+ .pipe(Effect.result);
298
+ assert.isTrue(Result.isFailure(result));
299
+ assert.deepEqual(
300
+ yield* projections.getRuntimeResponseContext(threadId, requestId),
301
+ pending,
302
+ );
303
+ assert.equal(yield* orchestrator.getThreadEventSequence(threadId), sequence);
304
+ assert.deepEqual(yield* outbox.listByCommandId(commandId), []);
305
+ }
306
+ }
307
yield* orchestrator.dispatch(
308
mode === "live"
309
? {
@@ -277,7 +311,7 @@ it.effect(
311
commandId: CommandId.make(`respond:${mode}`),
312
threadId,
313
requestId,
280
- decision: "accept",
314
+ answers,
315
}
316
: {
317
type: "thread.user-input.dismiss",
@@ -293,6 +327,25 @@ it.effect(
327
const response = yield* projections.getRuntimeResponseContext(threadId, requestId);
328
assert.equal(response.node?.status, mode === "live" ? "completed" : "cancelled");
329
assert.equal(response.item?.status, mode === "live" ? "completed" : "cancelled");
330
+ if (mode === "live") {
331
+ assert.deepEqual(response.request?.answers, normalizedAnswers);
332
+ assert.equal(response.item?.type, "user_input_request");
333
+ if (response.item?.type === "user_input_request") {
334
+ assert.deepEqual(response.item.questionAnswer?.answers, normalizedAnswers);
335
+ }
336
+ const effects = yield* outbox.listByCommandId(CommandId.make(`respond:${mode}`));
337
+ assert.deepEqual(
338
+ effects.map((effect) => effect.request),
339
+ [
340
+ {
341
+ type: "runtime-request.respond",
342
+ providerSessionId: sessionId,
343
+ requestId,
344
+ answers: normalizedAnswers,
345
+ },
346
+ ],
347
+ );
348
+ }
349
}
350
yield* orchestrator.dispatch({
351
type: "thread.metadata.update",
apps/server/src/orchestration-v2/Orchestrator.ts
+27
-5
@@ -498,6 +498,18 @@ function commandThreadId(command: OrchestrationV2ServerCommand): ThreadId {
498
}
499
}
500
501
+// Validate before resolving the request: adapters may otherwise coerce unusable answers.
502
+const decodeUserInputAnswers = Schema.decodeUnknownEffect(
503
+ Schema.Record(
504
+ Schema.String,
505
+ Schema.Union([
506
+ Schema.String,
507
+ Schema.Array(Schema.String),
508
+ Schema.Struct({ answers: Schema.Array(Schema.String) }),
509
+ ]),
510
+ ),
511
+);
512
+
513
function pendingThreadTitleGenerationEffect(
514
commandId: CommandId,
515
threadId: ThreadId,
@@ -7514,6 +7526,16 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7526
cause: `Provider session ${providerSessionId} was not found.`,
7527
});
7528
}
7529
+ let answers = command.answers;
7530
+ if (runtimeRequest.kind === "user_input" && answers !== undefined) {
7531
+ const decoded = yield* decodeUserInputAnswers(answers).pipe(mapDispatchError(command));
7532
+ answers = Object.fromEntries(
7533
+ Object.entries(decoded).map(([questionId, answer]) => [
7534
+ questionId,
7535
+ typeof answer === "object" && "answers" in answer ? answer.answers : answer,
7536
+ ]),
7537
+ );
7538
+ }
7539
7540
const now = yield* DateTime.now;
7541
const resolvedRequest = {
@@ -7521,7 +7543,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7543
status: "resolved" as const,
7544
resolvedAt: now,
7545
...(command.decision === undefined ? {} : { decision: command.decision }),
7524
- ...(command.answers === undefined ? {} : { answers: command.answers }),
7546
+ ...(answers === undefined ? {} : { answers }),
7547
};
7548
const emitEvent = emit(events, command);
7549
const requestNode = context.node;
@@ -7580,11 +7602,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7602
occurredAt: now,
7603
payload: {
7604
...approvalTurnItem,
7583
- ...(approvalTurnItem.type === "user_input_request" && command.answers !== undefined
7605
+ ...(approvalTurnItem.type === "user_input_request" && answers !== undefined
7606
? {
7607
questionAnswer: {
7608
requestId: command.requestId,
7587
- answers: command.answers ?? {},
7609
+ answers,
7610
attachmentsByQuestionId: command.attachmentsByQuestionId ?? {},
7611
questionTextById: Object.fromEntries(
7612
approvalTurnItem.questions.map((question) => [
@@ -7612,7 +7634,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7634
}
7635
const replies: string[] = [];
7636
for (const question of approvalTurnItem.questions) {
7615
- const answer = command.answers?.[question.id];
7637
+ const answer = answers?.[question.id];
7638
if (typeof answer !== "string" || answer.trim().length === 0) {
7639
if (question.required === false) continue;
7640
return yield* new OrchestratorDispatchError({
@@ -7691,7 +7713,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7713
providerSessionId,
7714
requestId: command.requestId,
7715
...(command.decision === undefined ? {} : { decision: command.decision }),
7694
- ...(command.answers === undefined ? {} : { answers: command.answers }),
7716
+ ...(answers === undefined ? {} : { answers }),
7717
},
7718
} satisfies PendingOrchestrationEffectV2,
7719
]);