@devries-cameron20 / t3code-1 / commits / e2f1a21262
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): a failed delegated task keeps its child's final report (#34915)

Julius Marminge committed Nov 12, 2026 at 00:09 UTC e2f1a2126293cb0348def61ad5582d5f1d60e251
2 files changed +54 -1
apps/server/src/orchestration-v2/SubagentProjection.test.ts
+45
@@ -393,6 +393,51 @@ it("exposes the provider failure rather than a progress message from the failed
393 assert.isNull(result.messageId);
394 });
395
396 +it("keeps the final report of a run that failed after its turn ended", () => {
397 + const { projection, run } = taskFixture();
398 + const failedRun = { ...run, status: "failed" as const };
399 + const artifacts = makeSubagentConversationArtifacts({
400 + messageId: MessageId.make("report"),
401 + turnItemId: TurnItemId.make("report"),
402 + threadId: parentThreadId,
403 + rootNodeId: NodeId.make("root"),
404 + providerThreadId: null,
405 + providerTurnId: null,
406 + nativeItemRef: null,
407 + role: "assistant",
408 + text: "Review complete: no blocking issues.",
409 + ordinal: 1,
410 + now: childCreatedAt,
411 + });
412 + if (artifacts.turnItem.type !== "assistant_message") throw new Error("Expected assistant item");
413 + const failure = {
414 + class: "unknown" as const,
415 + message: "Connection failed repeatedly",
416 + code: null,
417 + retryable: false,
418 + };
419 + const result = subagentResultForRun(
420 + {
421 + ...projection,
422 + messages: [{ ...artifacts.message, runId: run.id }],
423 + turnItems: [
424 + { ...artifacts.turnItem, runId: run.id },
425 + {
426 + ...artifacts.turnItem,
427 + id: TurnItemId.make("error"),
428 + ordinal: 2,
429 + type: "error",
430 + runId: run.id,
431 + failure,
432 + },
433 + ],
434 + },
435 + failedRun,
436 + );
437 + assert.include(result.text, failure.message);
438 + assert.include(result.text, "Review complete: no blocking issues.");
439 +});
440 +
441 it("orders a task's assistant messages by turn item, not by timestamps", () => {
442 const { projection, run } = taskFixture();
443 const at = DateTime.makeUnsafe("2026-07-24T10:05:00.000Z");
packages/provider-core/src/server/subagentProjection.ts
+9 -1
@@ -227,8 +227,16 @@ export function subagentResultForRun(
227 .filter((item) => item.runId === run.id && item.type === "error")
228 .toSorted((left, right) => right.ordinal - left.ordinal)[0]
229 : undefined;
230 + const reportBeforeFailure =
231 + failure !== undefined && turnItem !== null && turnItem.ordinal < failure.ordinal
232 + ? (message?.text ?? turnItem.text)
233 + : undefined;
234 const text =
231 - (failure?.type === "error" ? failure.failure.message : undefined) ??
235 + (failure?.type === "error"
236 + ? reportBeforeFailure === undefined
237 + ? failure.failure.message
238 + : `${failure.failure.message}\n\nLast assistant message before the run failed:\n\n${reportBeforeFailure}`
239 + : undefined) ??
240 message?.text ??
241 turnItem?.text ??
242 (run.status === "completed"