@devries-cameron20 / t3code-1 / commits / 9cc4018c75
Fork 0

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

fix(server): idle threads compact while a delegated task runs (#39766)

Julius Marminge committed Nov 20, 2026 at 07:59 UTC 9cc4018c75ff4c61be8e86a6391d49a6c2d79830
2 files changed +37 -2
apps/server/src/orchestration-v2/IdleCompaction.test.ts
+32
@@ -12,6 +12,7 @@ import {
12 ProviderTurnId,
13 RunId,
14 ThreadId,
15 + TurnItemId,
16 } from "@t3tools/contracts";
17 import * as DateTime from "effect/DateTime";
18 import * as Deferred from "effect/Deferred";
@@ -190,6 +191,37 @@ describe("idleCompactionWindow", () => {
191 };
192 expect(idleCompactionWindow(sideChat, NOW_MS)).toBeNull();
193 });
194 +
195 + it("still compacts while a delegated child thread runs on its own", () => {
196 + const delegating = records({ cacheExpiresInMs: 60 * MINUTE_MS });
197 + delegating.turnItems = [
198 + {
199 + id: TurnItemId.make("delegate-item"),
200 + threadId,
201 + runId,
202 + nodeId: NodeId.make("delegate-node"),
203 + providerThreadId,
204 + providerTurnId: null,
205 + nativeItemRef: null,
206 + parentItemId: null,
207 + ordinal: 1,
208 + status: "running",
209 + title: "Implement the feature",
210 + startedAt: at(-MINUTE_MS),
211 + completedAt: null,
212 + updatedAt: at(-MINUTE_MS),
213 + type: "subagent",
214 + subagentId: NodeId.make("delegate-node"),
215 + origin: "app_owned",
216 + driver: ProviderDriverKind.make("codex"),
217 + providerInstanceId: ProviderInstanceId.make("codex"),
218 + childThreadId: ThreadId.make("delegate-child"),
219 + prompt: "Implement the feature",
220 + result: null,
221 + },
222 + ];
223 + expect(idleCompactionWindow(delegating, NOW_MS)?.runId).toBe(runId);
224 + });
225 });
226
227 describe("IdleCompactionService", () => {
apps/server/src/orchestration-v2/IdleCompaction.ts
+5 -2
@@ -71,12 +71,15 @@ export function idleCompactionWindow(
71 transfer.targetThreadId === thread.id &&
72 transfer.status === "pending",
73 ) ||
74 - // Background work reports into the next turn; compaction would swallow it.
74 + // Background work reports into the next turn; compaction would swallow it. A delegated
75 + // child's result arrives later as its own message, so it does not count.
76 derivePendingBackgroundWork({
77 latestRun,
78 runs,
79 providerThreads,
79 - turnItems,
80 + turnItems: turnItems.filter(
81 + (item) => item.type !== "subagent" || item.origin !== "app_owned",
82 + ),
83 activeProviderThreadId: thread.activeProviderThreadId,
84 }).length > 0
85 )