@devries-cameron20 / t3code-1 / commits / 2a21f411a3
Fork 0

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

fix(server): parent turns no longer duplicate delegated task thread items (#36473)

Julius Marminge committed Nov 13, 2026 at 17:44 UTC 2a21f411a3ab85e2b3465df8a7d4fc5c4e500c50
2 files changed +49 -2
apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts
+44
@@ -1552,6 +1552,50 @@ effectIt.effect.each([
1552 }),
1553 );
1554
1555 +effectIt.effect("leaves delegated children to their own runs when the parent starts a turn", () =>
1556 + Effect.gen(function* () {
1557 + const harness = makeLocalCommandHarness({
1558 + text: "Continue",
1559 + previousTurn: { runStatus: "completed", turnStatus: "completed" },
1560 + });
1561 + const projection = harness.projection();
1562 + const completedChild = (origin: "provider_native" | "app_owned") => ({
1563 + id: NodeId.make(`node:${origin}`),
1564 + threadId: projection.thread.id,
1565 + runId: projection.runs[0]!.id,
1566 + parentNodeId: NodeId.make(`node:${origin}:parent`),
1567 + origin,
1568 + createdBy: "agent" as const,
1569 + driver: ProviderDriverKind.make("codex"),
1570 + providerInstanceId: ProviderInstanceId.make("codex"),
1571 + providerThreadId: ProviderThreadId.make(`provider-thread:${origin}`),
1572 + childThreadId: ThreadId.make(`thread:${origin}`),
1573 + nativeTaskRef: null,
1574 + prompt: "work",
1575 + title: null,
1576 + model: null,
1577 + status: "completed" as const,
1578 + result: "done",
1579 + startedAt: null,
1580 + completedAt: null,
1581 + updatedAt: projection.updatedAt,
1582 + });
1583 + harness.setProjection({
1584 + ...projection,
1585 + subagents: [completedChild("provider_native"), completedChild("app_owned")],
1586 + });
1587 +
1588 + yield* harness.start;
1589 +
1590 + // A delegated child thread has its own run on the shared session; a parent run that also
1591 + // owns it ingests every one of the child's later items a second time.
1592 + expect(harness.startRootRun.mock.calls[0]?.[0]).toMatchObject({
1593 + relatedThreadIds: [ThreadId.make("thread:provider_native")],
1594 + relatedProviderThreadIds: [ProviderThreadId.make("provider-thread:provider_native")],
1595 + });
1596 + }),
1597 +);
1598 +
1599 effectIt.effect("does not start another turn when abandoned-turn cleanup fails", () =>
1600 Effect.gen(function* () {
1601 const harness = makeLocalCommandHarness({
apps/server/src/orchestration-v2/ProviderTurnStartService.ts
+5 -2
@@ -1592,8 +1592,11 @@ export const layer: Layer.Layer<
1592 if (!runningWrite.committed) {
1593 return;
1594 }
1595 - const routableSubagents = projection.subagents.filter((subagent) =>
1596 - RunExecutionService.canRouteRelatedSubagent(subagent.status),
1595 + // Delegated (app_owned) children run their own runs; routing them here ingests their items twice.
1596 + const routableSubagents = projection.subagents.filter(
1597 + (subagent) =>
1598 + subagent.origin === "provider_native" &&
1599 + RunExecutionService.canRouteRelatedSubagent(subagent.status),
1600 );
1601 const persistHandoff = Effect.fn("ProviderTurnStartService.persist")(function* (
1602 handoff: OrchestrationV2ContextHandoff,