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, 13:30 UTC
fix(server): t3_thread_list leaves out tasks delegated from a linked environment (#36961)
Julius Marminge committed
Nov 14, 2026 at 14:46 UTC
35e65e6446caa383747e0561c85b74de1b219bb5
5 files changed
+61
-1
apps/server/src/mcp/OrchestratorMcpService.ts
+4
@@ -906,6 +906,7 @@ function listItemFromShell(
906
...threadBackgroundWork(shell),
907
parentThreadId: shell.lineage.parentThreadId,
908
relationshipToParent: shell.lineage.relationshipToParent,
909
+ ...(shell.delegatedFrom == null ? {} : { delegatedFrom: shell.delegatedFrom }),
910
itemCount: shell.visibleItemCount,
911
createdAt: DateTime.formatIso(shell.createdAt),
912
updatedAt: DateTime.formatIso(shell.updatedAt),
@@ -957,6 +958,9 @@ function threadDetail(
958
worktreePath: projection.thread.worktreePath,
959
parentThreadId: projection.thread.lineage.parentThreadId,
960
relationshipToParent: projection.thread.lineage.relationshipToParent,
961
+ ...(projection.thread.delegatedFrom == null
962
+ ? {}
963
+ : { delegatedFrom: projection.thread.delegatedFrom }),
964
runCount: projection.runs.length,
965
itemCount,
966
pendingRequestCount: projection.runtimeRequests.filter(
apps/server/src/orchestration-v2/ProjectionStore.ts
+17
@@ -74,6 +74,7 @@ import {
74
RuntimeRequestId,
75
CheckpointScopeId,
76
CheckpointId,
77
+ EnvironmentId,
78
ThreadId,
79
TurnItemId,
80
NodeId,
@@ -476,6 +477,7 @@ export type ActiveThreadListEntry = Pick<
477
| "projectId"
478
| "title"
479
| "lineage"
480
+ | "delegatedFrom"
481
| "settledOverride"
482
| "settledAt"
483
| "snoozedUntil"
@@ -8858,6 +8860,9 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
8860
readonly parent_thread_id: string | null;
8861
readonly root_thread_id: string;
8862
readonly side_chat: number | null;
8863
+ readonly delegated_from_environment_id: string | null;
8864
+ readonly delegated_from_thread_id: string | null;
8865
+ readonly delegated_from_title: string | null;
8866
readonly settled_override: string | null;
8867
readonly settled_at: string | null;
8868
readonly snoozed_until: string | null;
@@ -8871,6 +8876,9 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
8876
json_extract(t.payload_json, '$.lineage.parentThreadId') AS parent_thread_id,
8877
json_extract(t.payload_json, '$.lineage.rootThreadId') AS root_thread_id,
8878
json_extract(t.payload_json, '$.lineage.sideChat') AS side_chat,
8879
+ json_extract(t.payload_json, '$.delegatedFrom.environmentId') AS delegated_from_environment_id,
8880
+ json_extract(t.payload_json, '$.delegatedFrom.threadId') AS delegated_from_thread_id,
8881
+ json_extract(t.payload_json, '$.delegatedFrom.title') AS delegated_from_title,
8882
json_extract(t.payload_json, '$.settledOverride') AS settled_override,
8883
json_extract(t.payload_json, '$.settledAt') AS settled_at,
8884
json_extract(t.payload_json, '$.snoozedUntil') AS snoozed_until
@@ -8883,6 +8891,15 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
8891
projectId: ProjectId.make(row.project_id),
8892
title: row.title,
8893
lineage: shellIndexLineage(row),
8894
+ ...(row.delegated_from_environment_id === null || row.delegated_from_thread_id === null
8895
+ ? {}
8896
+ : {
8897
+ delegatedFrom: {
8898
+ environmentId: EnvironmentId.make(row.delegated_from_environment_id),
8899
+ threadId: ThreadId.make(row.delegated_from_thread_id),
8900
+ title: row.delegated_from_title ?? "",
8901
+ },
8902
+ }),
8903
settledOverride:
8904
row.settled_override === "settled" || row.settled_override === "active"
8905
? row.settled_override
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+33
@@ -17,6 +17,7 @@ import {
17
type ChatAttachment,
18
CommandId,
19
DEFAULT_SERVER_SETTINGS,
20
+ EnvironmentId,
21
GitCommandError,
22
MessageId,
23
ProjectId,
@@ -464,6 +465,38 @@ it.effect(
465
},
466
);
467
468
+it.effect("leaves a task delegated from a linked environment out of the top-level list", () => {
469
+ const harness = makeHarness();
470
+ return Effect.gen(function* () {
471
+ const launches = yield* ThreadLaunch.ThreadLaunchService;
472
+ const threads = yield* ThreadManagement.ThreadManagementService;
473
+ yield* launches.launch(
474
+ launchInput({ command: "command:top-level", thread: "thread:top-level" }),
475
+ );
476
+ const delegated = yield* launches.launch({
477
+ ...launchInput({ command: "command:delegated", thread: "thread:delegated" }),
478
+ createdBy: "agent",
479
+ creationSource: "mcp",
480
+ linkOrigin: { sessionId: "mcp-session:linked", label: "Linked laptop" },
481
+ delegatedFrom: {
482
+ environmentId: EnvironmentId.make("environment:linked"),
483
+ threadId: ThreadId.make("thread:remote-parent"),
484
+ title: "Remote parent",
485
+ },
486
+ });
487
+ const listed = yield* threads.listProjectThreads({ projectId, includeSubagents: false });
488
+ assert.deepEqual(
489
+ listed.map((thread) => thread.id),
490
+ [ThreadId.make("thread:top-level")],
491
+ );
492
+ const all = yield* threads.listProjectThreads({ projectId, includeSubagents: true });
493
+ assert.include(
494
+ all.map((thread) => thread.id),
495
+ delegated.threadId,
496
+ );
497
+ }).pipe(Effect.provide(harness.layer));
498
+});
499
+
500
it.effect("runs a thread-bound automation on the provider the thread uses now", () => {
501
const harness = makeHarness({ adapters: [adapter, claudeAdapter] });
502
const layerScheduledTasks = ScheduledTasks.layer.pipe(
apps/server/src/orchestration-v2/ThreadManagementService.ts
+2
-1
@@ -12,6 +12,7 @@ import type {
12
import {
13
type ChatAttachment,
14
CommandId,
15
+ isDelegatedAppThread,
16
isListedThreadLineage,
17
MessageId,
18
OrchestrationV2StopWorkflowError,
@@ -853,7 +854,7 @@ const make = Effect.gen(function* () {
854
.filter((thread) =>
855
input.includeSubagents
856
? thread.lineage.sideChat !== true
856
- : isListedThreadLineage(thread.lineage),
857
+ : isListedThreadLineage(thread.lineage) && !isDelegatedAppThread(thread),
858
)
859
.toSorted(
860
(left, right) =>
packages/contracts/src/orchestratorMcp.ts
+5
@@ -38,6 +38,7 @@ import { LastThreadTitleRegeneration, ThreadTitleRegeneration } from "./threadTi
38
import {
39
OrchestrationV2Actor,
40
OrchestrationV2CreationSource,
41
+ OrchestrationV2DelegatedFrom,
42
OrchestrationV2RunStatus,
43
OrchestrationV2TurnItemStatus,
44
} from "./orchestrationV2.ts";
@@ -419,6 +420,8 @@ export const OrchestratorMcpThreadListItem = Schema.Struct({
420
pendingBackgroundTasks: Schema.optional(Schema.Array(OrchestratorMcpThreadBackgroundTask)),
421
parentThreadId: Schema.NullOr(ThreadId),
422
relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
423
+ /** The linked environment's thread that delegated this one; absent otherwise. */
424
+ delegatedFrom: Schema.optional(OrchestrationV2DelegatedFrom),
425
itemCount: NonNegativeInt,
426
createdAt: IsoDateTime,
427
updatedAt: IsoDateTime,
@@ -476,6 +479,8 @@ export const OrchestratorMcpThreadDetail = Schema.Struct({
479
worktreePath: Schema.NullOr(Schema.String),
480
parentThreadId: Schema.NullOr(ThreadId),
481
relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
482
+ /** The linked environment's thread that delegated this one; absent otherwise. */
483
+ delegatedFrom: Schema.optional(OrchestrationV2DelegatedFrom),
484
runCount: NonNegativeInt,
485
itemCount: NonNegativeInt,
486
pendingRequestCount: NonNegativeInt,