The best way to control Claude Code, Codex and more from any computer or phone
fix(server): archive refuses a thread with running delegated tasks (#26078)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Fuksss committed
Nov 13, 2026 at 01:34 UTC
ac1cb9232dde82f13c2bd9ac7fc9650a3073ea19
4 files changed
+148
apps/server/src/orchestration-v2/Orchestrator.ts
+19
@@ -3994,6 +3994,25 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3994
cause: `Thread ${command.threadId} is already archived.`,
3995
});
3996
}
3997
+ if (command.type === "thread.archive") {
3998
+ const records = yield* projectionStore
3999
+ .getThreadRecords(command.threadId, ["subagents"])
4000
+ .pipe(mapDispatchError(command));
4001
+ if (
4002
+ records.subagents.some(
4003
+ (task) =>
4004
+ task.origin === "app_owned" &&
4005
+ task.childThreadId !== null &&
4006
+ isOrchestrationV2WorkActive(task.status),
4007
+ )
4008
+ ) {
4009
+ return yield* new OrchestratorDispatchError({
4010
+ commandId: command.commandId,
4011
+ commandType: command.type,
4012
+ cause: `Thread ${command.threadId} has running delegated tasks. Wait for them or cancel them before archiving.`,
4013
+ });
4014
+ }
4015
+ }
4016
if (command.type === "thread.unarchive" && thread.archivedAt === null) {
4017
return yield* new OrchestratorDispatchError({
4018
commandId: command.commandId,
apps/server/src/orchestration-v2/RemoteDelegatedTask.test.ts
+7
@@ -226,6 +226,13 @@ it.layer(layerTest)("a delegated task in a linked environment", (it) => {
226
const index = yield* (yield* ProjectionStore.ProjectionStoreV2).listActiveShellIndex();
227
assert.isTrue(index.find((entry) => entry.id === parent.threadId)?.hasRemoteTasks);
228
assert.isFalse(index.find((entry) => entry.id === other.threadId)?.hasRemoteTasks);
229
+ // Nothing here can cancel the task there, so it must not block archiving.
230
+ yield* orchestrator.dispatch({
231
+ type: "thread.archive",
232
+ commandId: CommandId.make("command:archive:records"),
233
+ threadId: parent.threadId,
234
+ });
235
+ assert.isNotNull((yield* orchestrator.getThreadShell(parent.threadId))?.archivedAt);
236
}),
237
);
238
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+121
@@ -6394,6 +6394,127 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
6394
}),
6395
);
6396
6397
+ it.effect("rejects archiving an idle parent until its delegated child completes", () =>
6398
+ Effect.gen(function* () {
6399
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
6400
+ const sink = yield* EventSink.EventSinkV2;
6401
+ const threadId = ThreadId.make("archive-delegated-parent");
6402
+ const projectId = ProjectId.make("archive-delegated-project");
6403
+ yield* seedProject({
6404
+ projectId,
6405
+ title: "Delegated archive",
6406
+ workspaceRoot: "/workspace/archive-delegated",
6407
+ defaultModelSelection: null,
6408
+ createdAt: "2026-09-07T00:00:00.000Z",
6409
+ });
6410
+ yield* orchestrator.dispatch({
6411
+ type: "thread.create",
6412
+ createdBy: "user",
6413
+ creationSource: "web",
6414
+ commandId: CommandId.make("archive-delegated-create"),
6415
+ threadId,
6416
+ projectId,
6417
+ title: "Delegated archive",
6418
+ modelSelection,
6419
+ runtimeMode: "full-access",
6420
+ interactionMode: "default",
6421
+ branch: null,
6422
+ worktreePath: null,
6423
+ });
6424
+ yield* orchestrator.dispatch({
6425
+ type: "message.dispatch",
6426
+ createdBy: "user",
6427
+ creationSource: "web",
6428
+ commandId: CommandId.make("archive-delegated-message"),
6429
+ threadId,
6430
+ messageId: MessageId.make("archive-delegated-message"),
6431
+ text: "Delegate the work, then finish your turn.",
6432
+ attachments: [],
6433
+ modelSelection,
6434
+ dispatchMode: { type: "start_immediately" },
6435
+ });
6436
+ const parentRun = (yield* orchestrator.getThreadProjection(threadId)).runs[0]!;
6437
+ yield* orchestrator.dispatch({
6438
+ type: "delegated_task.request",
6439
+ createdBy: "agent",
6440
+ creationSource: "mcp",
6441
+ commandId: CommandId.make("archive-delegated-request"),
6442
+ parentThreadId: threadId,
6443
+ parentRunId: parentRun.id,
6444
+ parentNodeId: parentRun.rootNodeId!,
6445
+ task: "Keep working after the parent finishes.",
6446
+ modelSelection,
6447
+ runtimeMode: "full-access",
6448
+ interactionMode: "default",
6449
+ completionWake: "always",
6450
+ });
6451
+ const delegatedParentRun = (yield* orchestrator.getThreadProjection(threadId)).runs[0]!;
6452
+ const now = yield* DateTime.now;
6453
+ yield* sink.write({
6454
+ events: [
6455
+ {
6456
+ id: EventId.make("archive-delegated-parent-completed"),
6457
+ type: "run.updated",
6458
+ threadId,
6459
+ runId: parentRun.id,
6460
+ occurredAt: now,
6461
+ payload: { ...delegatedParentRun, status: "completed", completedAt: now },
6462
+ },
6463
+ ],
6464
+ });
6465
+ const parent = yield* orchestrator.getThreadProjection(threadId);
6466
+ const task = parent.subagents[0]!;
6467
+ assert.equal(parent.runs[0]?.status, "completed");
6468
+ assert.equal(task.origin, "app_owned");
6469
+ assert.equal(task.status, "running");
6470
+ assert.isNotNull(task.childThreadId);
6471
+
6472
+ // Archive must preserve the idle parent's path for receiving this child's result.
6473
+ const error = yield* orchestrator
6474
+ .dispatch({
6475
+ type: "thread.archive",
6476
+ commandId: CommandId.make("archive-delegated-blocked"),
6477
+ threadId,
6478
+ })
6479
+ .pipe(Effect.flip);
6480
+ assert.instanceOf(error, Orchestrator.OrchestratorDispatchError);
6481
+ assert.equal(
6482
+ error.cause,
6483
+ `Thread ${threadId} has running delegated tasks. Wait for them or cancel them before archiving.`,
6484
+ );
6485
+ assert.isNull((yield* orchestrator.getThreadProjection(threadId)).thread.archivedAt);
6486
+
6487
+ const childThreadId = task.childThreadId!;
6488
+ const childRun = (yield* orchestrator.getThreadProjection(childThreadId)).runs[0]!;
6489
+ yield* sink.write({
6490
+ events: [
6491
+ {
6492
+ id: EventId.make("archive-delegated-child-run-completed"),
6493
+ type: "run.updated",
6494
+ threadId: childThreadId,
6495
+ runId: childRun.id,
6496
+ occurredAt: now,
6497
+ payload: { ...childRun, status: "completed", completedAt: now },
6498
+ },
6499
+ {
6500
+ id: EventId.make("archive-delegated-child-completed"),
6501
+ type: "subagent.updated",
6502
+ threadId,
6503
+ nodeId: task.id,
6504
+ occurredAt: now,
6505
+ payload: { ...task, status: "completed", result: "Done", completedAt: now },
6506
+ },
6507
+ ],
6508
+ });
6509
+ yield* orchestrator.dispatch({
6510
+ type: "thread.archive",
6511
+ commandId: CommandId.make("archive-delegated-allowed"),
6512
+ threadId,
6513
+ });
6514
+ assert.isNotNull((yield* orchestrator.getThreadProjection(threadId)).thread.archivedAt);
6515
+ }),
6516
+ );
6517
+
6518
it.effect("cancels preparing work on archive and keeps it cancelled through replay", () =>
6519
Effect.gen(function* () {
6520
const orchestrator = yield* Orchestrator.OrchestratorV2;
docs/user/thread-sidebar.md
+1
@@ -273,6 +273,7 @@ On mobile, open a subagent from its conversation card or **Agents**. On iOS
273
layouts with an inspector, its thread opens beside the parent. Maximize it to
274
fill the screen; close the full-screen view to return to the parent and inspector.
275
Stop on a thread also stops the subagents it delegated to.
276
+Before archiving the parent, wait for its delegated tasks to finish or cancel them.
277
278
Subagent threads started by the agent can't take messages; message the parent
279
thread instead. When such a subagent needs an approval or an answer, the parent