@devries-cameron20 / t3code-1 / commits / 33542a53be
Fork 0

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

fix(server): delegating a task no longer records failed projection read spans (#38083)

Co-authored-by: Martin Bergo <14320143+mInrOz@users.noreply.github.com>

Martin Bergo committed Nov 17, 2026 at 12:29 UTC 33542a53be7c5dd952457c4c2b479813f5cab32e
2 files changed +37 -24
apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts
+28 -12
@@ -1252,19 +1252,35 @@ it.effect("keeps delegated child pull-request links independent of the parent",
1252 });
1253 const parent = yield* projections.getThreadProjection(parentThreadId);
1254 const parentRun = parent.runs[0]!;
1255 - yield* orchestrator.dispatch({
1256 - type: "delegated_task.request",
1257 - commandId: CommandId.make("delegate-parent-pr"),
1258 - parentThreadId,
1259 - parentRunId: parentRun.id,
1260 - parentNodeId: parentRun.rootNodeId!,
1261 - task: "Review the changes",
1262 - modelSelection,
1263 - runtimeMode: "full-access",
1264 - interactionMode: "default",
1265 - createdBy: "agent",
1266 - creationSource: "mcp",
1255 + const failedSpans: Array<string> = [];
1256 + const tracer = Tracer.make({
1257 + span(options) {
1258 + const span = new Tracer.NativeSpan(options);
1259 + const end = span.end.bind(span);
1260 + span.end = (time, exit) => {
1261 + end(time, exit);
1262 + if (Exit.isFailure(exit)) failedSpans.push(span.name);
1263 + };
1264 + return span;
1265 + },
1266 });
1267 + yield* orchestrator
1268 + .dispatch({
1269 + type: "delegated_task.request",
1270 + commandId: CommandId.make("delegate-parent-pr"),
1271 + parentThreadId,
1272 + parentRunId: parentRun.id,
1273 + parentNodeId: parentRun.rootNodeId!,
1274 + task: "Review the changes",
1275 + modelSelection,
1276 + runtimeMode: "full-access",
1277 + interactionMode: "default",
1278 + createdBy: "agent",
1279 + creationSource: "mcp",
1280 + })
1281 + .pipe(Effect.withTracer(tracer));
1282 + // The child thread is created by this command; a failed span here reads as an error in traces.
1283 + assert.deepEqual(failedSpans, []);
1284 const updatedParent = yield* projections.getThreadProjection(parentThreadId);
1285 assert.deepEqual(updatedParent.subagents[0]!.modelSelection, modelSelection);
1286 const childThreadId = updatedParent.subagents[0]!.childThreadId!;
apps/server/src/orchestration-v2/Orchestrator.ts
+9 -12
@@ -1827,20 +1827,17 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1827 recent?: ProjectionRecordFilter["sinceLastCompaction"],
1828 ) {
1829 const pending = (yield* Ref.get(events)).filter((event) => event.threadId === threadId);
1830 - const stored = yield* Effect.option(readCommandProjection(threadId, recent));
1830 + const created = pending.find(
1831 + (
1832 + event,
1833 + ): event is Extract<OrchestrationV2DomainEvent, { readonly type: "thread.created" }> =>
1834 + event.type === "thread.created",
1835 + );
1836 + // A thread created here has no stored row: create and fork refuse used ids, delegation derives a fresh one.
1837 let projection: OrchestrationV2ThreadProjection;
1832 - if (Option.isSome(stored)) {
1833 - projection = stored.value;
1838 + if (created === undefined) {
1839 + projection = yield* readCommandProjection(threadId, recent);
1840 } else {
1835 - const created = pending.find(
1836 - (
1837 - event,
1838 - ): event is Extract<OrchestrationV2DomainEvent, { readonly type: "thread.created" }> =>
1839 - event.type === "thread.created",
1840 - );
1841 - if (created === undefined) {
1842 - return yield* new OrchestratorProjectionError({ threadId });
1843 - }
1841 projection = emptyProjection(created);
1842 }
1843