The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
fix(server): archiving a thread also archives its side chats (#32213)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Jackson Miller committed
Nov 19, 2026 at 01:14 UTC
ae3c7a68b4d430a8f763d90a24203fb14d4b4713
3 files changed
+208
-22
apps/server/src/orchestration-v2/Orchestrator.ts
+60
-21
@@ -1538,6 +1538,14 @@ const nativeSubagentRef = (subagent: OrchestrationV2Subagent): DyingNativeSubage
1538
providerInstanceId: subagent.providerInstanceId,
1539
});
1540
1541
+const hasRunningDelegatedTasks = (subagents: ReadonlyArray<OrchestrationV2Subagent>) =>
1542
+ subagents.some(
1543
+ (task) =>
1544
+ task.origin === "app_owned" &&
1545
+ task.childThreadId !== null &&
1546
+ isOrchestrationV2WorkActive(task.status),
1547
+ );
1548
+
1549
const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(function* () {
1550
const checkpointService = yield* CheckpointServiceV2;
1551
const commandPolicy = yield* CommandPolicyV2;
@@ -1817,7 +1825,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1825
.findThread(threadId)
1826
.pipe(Effect.mapError((cause) => new OrchestratorProjectionError({ threadId, cause })));
1827
1820
- /** Side chats live inside their parent, so deleting the parent deletes them too. */
1828
+ /** Side chats live inside their parent, so deleting or archiving the parent takes them too. */
1829
const liveSideChatIds = Effect.fn("Orchestrator.liveSideChatIds")(
1830
function* (threadId: ThreadId) {
1831
const { contextTransfers } = yield* projectionStore
@@ -4260,14 +4268,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
4268
const records = yield* projectionStore
4269
.getThreadRecords(command.threadId, ["subagents"])
4270
.pipe(mapDispatchError(command));
4263
- if (
4264
- records.subagents.some(
4265
- (task) =>
4266
- task.origin === "app_owned" &&
4267
- task.childThreadId !== null &&
4268
- isOrchestrationV2WorkActive(task.status),
4269
- )
4270
- ) {
4271
+ if (hasRunningDelegatedTasks(records.subagents)) {
4272
return yield* new OrchestratorDispatchError({
4273
commandId: command.commandId,
4274
commandType: command.type,
@@ -15207,7 +15208,39 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
15208
};
15209
}
15210
case "thread.archive":
15210
- case "thread.unarchive":
15211
+ case "thread.unarchive": {
15212
+ const parentArchivedAt = (yield* findThread(command.threadId))?.archivedAt ?? null;
15213
+ yield* dispatchThreadMutation(command, events, effects);
15214
+ // Unarchive restores the side chats this parent's archive took, not ones archived before it.
15215
+ for (const threadId of sideChatIds) {
15216
+ const sideChatArchivedAt = (yield* findThread(threadId))?.archivedAt ?? null;
15217
+ const follows =
15218
+ command.type === "thread.archive"
15219
+ ? sideChatArchivedAt === null
15220
+ : sideChatArchivedAt !== null &&
15221
+ parentArchivedAt !== null &&
15222
+ DateTime.toEpochMillis(sideChatArchivedAt) >=
15223
+ DateTime.toEpochMillis(parentArchivedAt);
15224
+ if (!follows) continue;
15225
+ // Archive refuses a side chat still waiting on delegated tasks, so it stays active.
15226
+ if (command.type === "thread.archive") {
15227
+ const { subagents } = yield* projectionStore
15228
+ .getThreadRecords(threadId, ["subagents"])
15229
+ .pipe(mapDispatchError(command));
15230
+ if (hasRunningDelegatedTasks(subagents)) continue;
15231
+ }
15232
+ yield* dispatchThreadMutation(
15233
+ {
15234
+ ...command,
15235
+ commandId: CommandId.make(`${command.commandId}:side-chat:${threadId}`),
15236
+ threadId,
15237
+ },
15238
+ events,
15239
+ effects,
15240
+ );
15241
+ }
15242
+ break;
15243
+ }
15244
case "thread.settle":
15245
case "thread.unsettle":
15246
case "thread.snooze":
@@ -15552,7 +15585,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
15585
} satisfies OrchestratorV2DispatchResult;
15586
});
15587
15555
- /** `sideChatIds` are the live side chats a `thread.delete` cascades to, read under their locks. */
15588
+ /** `sideChatIds` are the live side chats a delete, archive, or unarchive cascades to, read under their locks. */
15589
const dispatchWithReceiptEffect = Effect.fn("orchestrationV2.dispatch.withReceipt")(function* (
15590
command: OrchestrationV2ServerCommand,
15591
sideChatIds: ReadonlyArray<ThreadId> = [],
@@ -15853,20 +15886,26 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
15886
? dispatch
15887
: threadDispatch.withLock(command.sourceThreadId, dispatch);
15888
}
15856
- if (command.type === "thread.delete")
15857
- return yield* threadDispatch.withDeletionLock(
15858
- threadDispatch.withLock(
15859
- command.threadId,
15860
- liveSideChatIds(command.threadId).pipe(
15861
- Effect.flatMap((sideChatIds) =>
15862
- sideChatIds.reduce(
15863
- (locked, sideChatId) => threadDispatch.withLock(sideChatId, locked),
15864
- dispatchWithReceiptEffect(command, sideChatIds),
15865
- ),
15889
+ if (
15890
+ command.type === "thread.delete" ||
15891
+ command.type === "thread.archive" ||
15892
+ command.type === "thread.unarchive"
15893
+ ) {
15894
+ const cascade = threadDispatch.withLock(
15895
+ command.threadId,
15896
+ liveSideChatIds(command.threadId).pipe(
15897
+ Effect.flatMap((sideChatIds) =>
15898
+ sideChatIds.reduce(
15899
+ (locked, sideChatId) => threadDispatch.withLock(sideChatId, locked),
15900
+ dispatchWithReceiptEffect(command, sideChatIds),
15901
),
15902
),
15903
),
15904
);
15905
+ return yield* command.type === "thread.delete"
15906
+ ? threadDispatch.withDeletionLock(cascade)
15907
+ : cascade;
15908
+ }
15909
// Taken before the lineage read, so a message whose read yields keeps its
15910
// place ahead of later messages to the same thread.
15911
const message =
apps/server/src/orchestration-v2/ThreadFork.execution.test.ts
+146
@@ -10,6 +10,7 @@ import {
10
ProjectId,
11
ProviderDriverKind,
12
ProviderInstanceId,
13
+ ProviderSessionId,
14
ProviderThreadId,
15
ProviderTurnId,
16
RunAttemptId,
@@ -1230,6 +1231,151 @@ it.effect("closing a side chat deletes it only while unused; a deleted parent ta
1231
}).pipe(Effect.provide(forkCases[0]!.layer)),
1232
);
1233
1234
+it.effect(
1235
+ "archiving a parent stops and archives its side chats; unarchiving brings them back",
1236
+ () =>
1237
+ Effect.gen(function* () {
1238
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
1239
+ const eventSink = yield* EventSink.EventSinkV2;
1240
+ const { driver, instanceId } = forkCases[0]!;
1241
+ const parentId = ThreadId.make("side-chat-archive-parent");
1242
+ const busy = ThreadId.make("side-chat-archive-busy");
1243
+ const archivedFirst = ThreadId.make("side-chat-archive-archived-first");
1244
+ const delegating = ThreadId.make("side-chat-archive-delegating");
1245
+ yield* createParent(parentId);
1246
+ yield* writeParentRun({
1247
+ threadId: parentId,
1248
+ runId: RunId.make("side-chat-archive-parent-run"),
1249
+ ordinal: 1,
1250
+ status: "completed",
1251
+ text: "Parent work",
1252
+ stable: true,
1253
+ });
1254
+ yield* forkSideChat("side-chat-archive-fork-busy", parentId, busy);
1255
+ yield* forkSideChat("side-chat-archive-fork-archived-first", parentId, archivedFirst);
1256
+ yield* forkSideChat("side-chat-archive-fork-delegating", parentId, delegating);
1257
+ const runningRunId = RunId.make("side-chat-archive-busy-running");
1258
+ const queuedRunId = RunId.make("side-chat-archive-busy-queued");
1259
+ yield* writeParentRun({
1260
+ threadId: busy,
1261
+ runId: runningRunId,
1262
+ ordinal: 1,
1263
+ status: "running",
1264
+ text: "Run a long command",
1265
+ });
1266
+ yield* writeParentRun({
1267
+ threadId: busy,
1268
+ runId: queuedRunId,
1269
+ ordinal: 2,
1270
+ status: "queued",
1271
+ text: "Then this",
1272
+ });
1273
+ const now = yield* DateTime.now;
1274
+ for (const threadId of [parentId, busy]) {
1275
+ yield* eventSink.write({
1276
+ events: [
1277
+ {
1278
+ id: EventId.make(`${threadId}:session`),
1279
+ type: "provider-session.attached",
1280
+ threadId,
1281
+ driver,
1282
+ providerInstanceId: instanceId,
1283
+ occurredAt: now,
1284
+ payload: {
1285
+ id: ProviderSessionId.make(`${threadId}:session`),
1286
+ driver,
1287
+ providerInstanceId: instanceId,
1288
+ status: "running",
1289
+ cwd: "/workspace",
1290
+ model: "test-model",
1291
+ capabilities: CodexProviderCapabilitiesV2,
1292
+ createdAt: now,
1293
+ updatedAt: now,
1294
+ lastError: null,
1295
+ },
1296
+ },
1297
+ ],
1298
+ });
1299
+ }
1300
+ const delegatingRunId = RunId.make("side-chat-archive-delegating-run");
1301
+ yield* writeParentRun({
1302
+ threadId: delegating,
1303
+ runId: delegatingRunId,
1304
+ ordinal: 1,
1305
+ status: "completed",
1306
+ text: "Delegate a review",
1307
+ });
1308
+ const taskId = NodeId.make("side-chat-archive-delegated-task");
1309
+ yield* eventSink.write({
1310
+ events: [
1311
+ {
1312
+ id: EventId.make(`${taskId}:running`),
1313
+ type: "subagent.updated",
1314
+ threadId: delegating,
1315
+ occurredAt: now,
1316
+ payload: {
1317
+ id: taskId,
1318
+ threadId: delegating,
1319
+ runId: delegatingRunId,
1320
+ parentNodeId: NodeId.make("side-chat-archive-delegating-node"),
1321
+ origin: "app_owned",
1322
+ createdBy: "agent",
1323
+ driver,
1324
+ providerInstanceId: instanceId,
1325
+ providerThreadId: null,
1326
+ childThreadId: ThreadId.make("side-chat-archive-delegated-child"),
1327
+ nativeTaskRef: null,
1328
+ prompt: "Review the changes",
1329
+ title: null,
1330
+ model: null,
1331
+ status: "running",
1332
+ result: null,
1333
+ startedAt: now,
1334
+ completedAt: null,
1335
+ updatedAt: now,
1336
+ },
1337
+ },
1338
+ ],
1339
+ });
1340
+ const archive = (commandId: string, threadId: ThreadId) =>
1341
+ orchestrator.dispatch({
1342
+ type: "thread.archive",
1343
+ commandId: CommandId.make(commandId),
1344
+ threadId,
1345
+ });
1346
+ const archivedAt = (threadId: ThreadId) =>
1347
+ orchestrator
1348
+ .getThreadProjection(threadId)
1349
+ .pipe(Effect.map(({ thread }) => thread.archivedAt));
1350
+
1351
+ // Archiving a side chat on its own leaves its parent alone.
1352
+ yield* archive("side-chat-archive-only-child", archivedFirst);
1353
+ const childArchivedAt = yield* archivedAt(archivedFirst);
1354
+ assert.isNotNull(childArchivedAt);
1355
+ assert.isNull(yield* archivedAt(parentId));
1356
+ yield* TestClock.adjust("1 second");
1357
+
1358
+ yield* archive("side-chat-archive-parent", parentId);
1359
+ assert.isNotNull(yield* archivedAt(parentId));
1360
+ const archivedBusy = yield* orchestrator.getThreadProjection(busy);
1361
+ assert.isNotNull(archivedBusy.thread.archivedAt);
1362
+ assert.equal(archivedBusy.runs.find((run) => run.id === queuedRunId)?.status, "cancelled");
1363
+ assert.isEmpty(archivedBusy.providerSessions);
1364
+ assert.deepEqual(yield* archivedAt(archivedFirst), childArchivedAt);
1365
+ // Archive refuses a thread still waiting on delegated tasks, so the cascade leaves it active.
1366
+ assert.isNull(yield* archivedAt(delegating));
1367
+
1368
+ yield* orchestrator.dispatch({
1369
+ type: "thread.unarchive",
1370
+ commandId: CommandId.make("side-chat-archive-unarchive-parent"),
1371
+ threadId: parentId,
1372
+ });
1373
+ assert.isNull(yield* archivedAt(parentId));
1374
+ assert.isNull(yield* archivedAt(busy));
1375
+ assert.deepEqual(yield* archivedAt(archivedFirst), childArchivedAt);
1376
+ }).pipe(Effect.provide(forkCases[0]!.layer)),
1377
+);
1378
+
1379
it.effect("a side chat opened during the parent's first turn starts from a digest", () =>
1380
Effect.gen(function* () {
1381
const orchestrator = yield* Orchestrator.OrchestratorV2;
docs/user/thread-sidebar.md
+2
-1
@@ -317,7 +317,8 @@ your next message there. Bring back is available while the thread is idle.
317
318
Closing a side chat you never sent a message in deletes it. To delete one you used,
319
choose **Delete** at the top of the side chat. Deleting a thread also deletes its
320
-side chats.
320
+side chats. Archiving a thread also archives its side chats and stops their work, and
321
+unarchiving the thread brings them back.
322
323
On mobile, a thread lists its side chats above the composer. Tap one to open it and
324
answer its questions.