The best way to control Claude Code, Codex and more from any computer or phone
fix(server): command projection failures keep their cause (#28389)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Nov 1, 2026 at 16:06 UTC
b08d559a1de3f16847943d0bf61323c10c384cd1
2 files changed
+84
-37
apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts
+49
@@ -656,6 +656,55 @@ it.effect(
656
}).pipe(Effect.provide(layerTest)),
657
);
658
659
+it.effect("keeps the store's read failure as the cause when a command projection fails", () =>
660
+ Effect.gen(function* () {
661
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
662
+ const sql = yield* SqlClient.SqlClient;
663
+ const now = DateTime.formatIso(yield* DateTime.now);
664
+ const unreadableMessage = ThreadId.make("thread:control-unreadable-message");
665
+ const unreadableRequest = ThreadId.make("thread:control-unreadable-request");
666
+ for (const threadId of [unreadableMessage, unreadableRequest]) {
667
+ yield* orchestrator.dispatch({
668
+ type: "thread.create",
669
+ commandId: CommandId.make(`create:${threadId}`),
670
+ threadId,
671
+ projectId: ProjectId.make("project:control-unreadable"),
672
+ title: "Unreadable",
673
+ modelSelection,
674
+ runtimeMode: "full-access",
675
+ interactionMode: "default",
676
+ branch: null,
677
+ worktreePath: null,
678
+ createdBy: "user",
679
+ creationSource: "web",
680
+ });
681
+ }
682
+ yield* sql`INSERT INTO orchestration_v2_projection_messages
683
+ (message_id, thread_id, run_id, node_id, role, streaming, created_at, updated_at, payload_json)
684
+ VALUES ('obsolete-user', ${unreadableMessage}, NULL, NULL, 'user', 0, ${now}, ${now}, '{"obsolete":true}')`;
685
+ yield* sql`INSERT INTO orchestration_v2_projection_runtime_requests
686
+ (runtime_request_id, thread_id, node_id, kind, status, created_at, payload_json)
687
+ VALUES ('request:unreadable', ${unreadableRequest}, 'node:unreadable', 'user-input', 'pending', ${now}, '{}')`;
688
+ for (const command of [
689
+ {
690
+ type: "queue.resume",
691
+ commandId: CommandId.make("resume-unreadable"),
692
+ threadId: unreadableMessage,
693
+ },
694
+ {
695
+ type: "thread.user-input.dismiss",
696
+ commandId: CommandId.make("dismiss-unreadable"),
697
+ threadId: unreadableRequest,
698
+ requestId: RuntimeRequestId.make("request:unreadable"),
699
+ },
700
+ ] as const) {
701
+ const failure = yield* orchestrator.dispatch(command).pipe(Effect.flip);
702
+ assert.instanceOf(failure, Orchestrator.OrchestratorProjectionError);
703
+ assert.instanceOf(failure.cause, ProjectionStore.ProjectionStoreReadError);
704
+ }
705
+ }).pipe(Effect.provide(layerTest)),
706
+);
707
+
708
it.effect("implements a proposed plan that the command projection leaves out", () =>
709
Effect.gen(function* () {
710
const orchestrator = yield* Orchestrator.OrchestratorV2;
apps/server/src/orchestration-v2/Orchestrator.ts
+35
-37
@@ -8881,7 +8881,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
8881
const context = yield* projectionStore
8882
.getRuntimeResponseContext(command.threadId, command.requestId)
8883
.pipe(
8884
- Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })),
8884
+ Effect.mapError(
8885
+ (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
8886
+ ),
8887
);
8888
const runtimeRequest = context.request;
8889
if (runtimeRequest === undefined) {
@@ -9294,7 +9296,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
9296
const request = yield* projectionStore
9297
.getRuntimeRequest(command.threadId, command.requestId)
9298
.pipe(
9297
- Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })),
9299
+ Effect.mapError(
9300
+ (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
9301
+ ),
9302
);
9303
if (request === undefined || request.status !== "pending") {
9304
return yield* new OrchestratorDispatchError({
@@ -9331,24 +9335,22 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
9335
events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
9336
effects: Ref.Ref<Array<PendingOrchestrationEffectV2>>,
9337
) {
9334
- const projection = yield* projectionStore
9335
- .getThreadRecords(
9336
- command.threadId,
9337
- [
9338
- "runs",
9339
- "nodes",
9340
- "attempts",
9341
- "messages",
9342
- "providerThreads",
9343
- "providerTurns",
9344
- "providerSessions",
9345
- "turnItems",
9346
- "runtimeRequests",
9347
- "subagents",
9348
- ],
9349
- { turnItemTypes: [], messageRoles: ["user"] },
9350
- )
9351
- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9338
+ const projection = yield* loadProjectionForCommand(
9339
+ command,
9340
+ [
9341
+ "runs",
9342
+ "nodes",
9343
+ "attempts",
9344
+ "messages",
9345
+ "providerThreads",
9346
+ "providerTurns",
9347
+ "providerSessions",
9348
+ "turnItems",
9349
+ "runtimeRequests",
9350
+ "subagents",
9351
+ ],
9352
+ { turnItemTypes: [], messageRoles: ["user"] },
9353
+ );
9354
if (projection.thread.archivedAt !== null || projection.thread.deletedAt !== null) {
9355
return yield* new OrchestratorDispatchError({
9356
commandId: command.commandId,
@@ -9542,9 +9544,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
9544
command: Extract<OrchestrationV2Command, { readonly type: "queued-run.reorder" }>,
9545
events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
9546
) {
9545
- const projection = yield* projectionStore
9546
- .getThreadRecords(command.threadId, ["runs", "messages"], { messageRoles: ["user"] })
9547
- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9547
+ const projection = yield* loadProjectionForCommand(command, ["runs", "messages"], {
9548
+ messageRoles: ["user"],
9549
+ });
9550
const queuedRuns = queuedRunsInDeliveryOrder(projection);
9551
const moving = queuedRuns.find((run) => run.id === command.runId);
9552
if (moving === undefined) {
@@ -9628,13 +9630,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
9630
command: Extract<OrchestrationV2Command, { readonly type: "queued-run.cancel" }>,
9631
events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
9632
) {
9631
- const projection = yield* projectionStore
9632
- .getThreadRecords(
9633
- command.threadId,
9634
- ["runs", "messages", "nodes", "attempts", "subagents", "turnItems"],
9635
- { turnItemTypes: [], messageRoles: ["user"] },
9636
- )
9637
- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9633
+ const projection = yield* loadProjectionForCommand(
9634
+ command,
9635
+ ["runs", "messages", "nodes", "attempts", "subagents", "turnItems"],
9636
+ { turnItemTypes: [], messageRoles: ["user"] },
9637
+ );
9638
const queuedRun = projection.runs.find((candidate) => candidate.id === command.runId);
9639
if (queuedRun === undefined || queuedRun.status !== "queued") {
9640
return yield* new OrchestratorDispatchError({
@@ -9739,12 +9739,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
9739
cause: `Queued run ${command.runId} cannot be edited to an empty message.`,
9740
});
9741
}
9742
- const projection = yield* projectionStore
9743
- .getThreadRecords(command.threadId, ["runs", "messages", "turnItems"], {
9744
- turnItemTypes: ["user_message"],
9745
- messageRoles: ["user"],
9746
- })
9747
- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9742
+ const projection = yield* loadProjectionForCommand(command, ["runs", "messages", "turnItems"], {
9743
+ turnItemTypes: ["user_message"],
9744
+ messageRoles: ["user"],
9745
+ });
9746
const queuedRun = projection.runs.find((candidate) => candidate.id === command.runId);
9747
if (queuedRun === undefined || queuedRun.status !== "queued") {
9748
return yield* new OrchestratorDispatchError({
@@ -9842,7 +9840,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
9840
.getThreadRecords(commandThreadId(command), fields, filter)
9841
.pipe(
9842
Effect.mapError(
9845
- () => new OrchestratorProjectionError({ threadId: commandThreadId(command) }),
9843
+ (cause) => new OrchestratorProjectionError({ threadId: commandThreadId(command), cause }),
9844
),
9845
);
9846