feat(server): delegate_task to a linked environment #16719
Mergedjuliusmarmingemerged 9 commits into
t3code/peer/links-ui fromrefs/pull/16719/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/peer/RemoteDelegation.ts line 184OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +164,21 @@164+ input.interactionMode,165+ );166+ const projectId = yield* resolveRemoteProject(167+ scope,168+ target.environmentId,169+ parent.thread.projectId,170+ target.projectId,171+ );172+ // One key for the launch there and the record here, so a retry finds both.173+ const key = input.clientRequestId ?? (yield* crypto.randomUUIDv4.pipe(Effect.orDie));174+ const launched = yield* forwarding.call(175+ scope,176+ ProjectToolkit.tools.t3_thread_launch,177+ target.environmentId,178+ {179+ projectId,180+ title: input.title ?? parent.thread.title,181+ modelSelection: { instanceId: target.providerInstanceId, model: target.model },182+ runtimeMode,183+ interactionMode,184+ message: input.task,apps/server/src/peer/RemoteDelegation.ts line 269OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +249,21 @@249+ commandId: CommandId.make(`command:remote-task-complete:${parentThreadId}:${taskId}`),250+ parentThreadId,251+ taskId,252+ status,253+ result,254+ })255+ .pipe(Effect.asVoid);256+257+ /** The last reply on the task's thread there, which is its result. */258+ const lastReply = (scope: ThreadScope, remote: OrchestrationV2RemoteTaskChild) =>259+ Effect.gen(function* () {260+ let reply: string | null = null;261+ let afterPosition: number | undefined;262+ for (let page = 0; page < MAX_RESULT_PAGES; page += 1) {263+ const read = yield* forwarding.call(scope, tools.t3_thread_read, remote.environmentId, {264+ threadId: remote.threadId,265+ view: "messages",266+ limit: 100,267+ ...(afterPosition === undefined ? {} : { afterPosition }),268+ });269+ reply = read.items.findLast((item) => item.type === "assistant_message")?.text ?? reply;apps/server/src/peer/RemoteDelegation.ts line 262OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +242,21 @@242+ taskId: NodeId,243+ status: "completed" | "failed" | "cancelled" | "interrupted",244+ result: string,245+ ) =>246+ threads247+ .dispatch({248+ type: "delegated_task.remote.complete",249+ commandId: CommandId.make(`command:remote-task-complete:${parentThreadId}:${taskId}`),250+ parentThreadId,251+ taskId,252+ status,253+ result,254+ })255+ .pipe(Effect.asVoid);256+257+ /** The last reply on the task's thread there, which is its result. */258+ const lastReply = (scope: ThreadScope, remote: OrchestrationV2RemoteTaskChild) =>259+ Effect.gen(function* () {260+ let reply: string | null = null;261+ let afterPosition: number | undefined;262+ for (let page = 0; page < MAX_RESULT_PAGES; page += 1) {apps/server/src/peer/RemoteDelegation.ts line 214OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +194,21 @@194+ const recorded = yield* threads195+ .dispatch({196+ type: "delegated_task.remote.request",197+ commandId,198+ parentThreadId: scope.thread.threadId,199+ parentRunId: parentRun.id,200+ parentNodeId,201+ task: input.task,202+ ...(input.title === undefined ? {} : { title: input.title }),203+ // The driver runs there; this side only labels the task with it.204+ driver: ProviderDriverKind.make("remote"),205+ modelSelection: launched.modelSelection,206+ remoteChild: {207+ environmentId: target.environmentId,208+ threadId: launched.threadId,209+ label: link?.label ?? target.environmentId,210+ },211+ completionWake: input.mode === "wait" ? "settled_only" : "always",212+ })213+ .pipe(214+ Effect.mapError((error) =>apps/server/src/peer/RemoteDelegation.ts line 121OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +101,21 @@101+ // The project's own identity is a one-minute cache that reads blank when102+ // cold, so resolve it here, as the other side's t3_project_list does.103+ const key =104+ here === undefined105+ ? undefined106+ : (yield* repositoryIdentities.resolve(here.workspaceRoot))?.canonicalKey;107+ if (key === undefined) {108+ return yield* failure(109+ "target_required",110+ "Pass target.projectId: this thread's project has no repository to match there.",111+ );112+ }113+ const listed = yield* forwarding.call(114+ scope,115+ ProjectToolkit.tools.t3_project_list,116+ environmentId,117+ {118+ limit: 100,119+ },120+ );121+ const matches = listed.projects.filter(
- apps/server/src/mcp/toolkits/orchestrator/handlers.ts lines 50 to 53OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -45,4 +46,8 @@4546 Effect.gen(function* () {4647 const scope = yield* McpInvocationContext.McpInvocationContext;4748 const service = yield* OrchestratorMcpService.OrchestratorMcpService;48- return yield* service.delegateTask(scope, input);49+ const target = input.target;50+ const environmentId =51+ target === undefined ? undefined : PeerForwarding.remoteTarget(scope, target.environmentId);52+ if (target === undefined || environmentId === undefined) {53+ return yield* service.delegateTask(scope, input);apps/server/src/mcp/toolkits/orchestrator/handlers.ts lines 58 to 64OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -45,4 +46,19 @@4546 Effect.gen(function* () {4647 const scope = yield* McpInvocationContext.McpInvocationContext;4748 const service = yield* OrchestratorMcpService.OrchestratorMcpService;48- return yield* service.delegateTask(scope, input);49+ const target = input.target;50+ const environmentId =51+ target === undefined ? undefined : PeerForwarding.remoteTarget(scope, target.environmentId);52+ if (target === undefined || environmentId === undefined) {53+ return yield* service.delegateTask(scope, input);54+ }55+ // The task's child runs as an ordinary thread there; this thread keeps the task.56+ const threadScope = yield* McpInvocationContext.requireThreadScope(scope, "delegate_task");57+ const remote = yield* RemoteDelegation.RemoteDelegation;58+ const { taskId } = yield* remote.delegate(threadScope, {59+ ...input,60+ target: { ...target, environmentId },61+ });62+ return yield* input.mode === "wait"63+ ? service.awaitTask(threadScope, taskId, input.timeoutMs)64+ : service.taskStatus(scope, taskId);apps/server/src/peer/RemoteDelegation.ts lines 113 to 123OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +103,21 @@103+ const key =104+ here === undefined105+ ? undefined106+ : (yield* repositoryIdentities.resolve(here.workspaceRoot))?.canonicalKey;107+ if (key === undefined) {108+ return yield* failure(109+ "target_required",110+ "Pass target.projectId: this thread's project has no repository to match there.",111+ );112+ }113+ const listed = yield* forwarding.call(114+ scope,115+ ProjectToolkit.tools.t3_project_list,116+ environmentId,117+ {118+ limit: 100,119+ },120+ );121+ const matches = listed.projects.filter(122+ (project) => project.repositoryIdentity?.canonicalKey === key,123+ );apps/server/src/peer/RemoteDelegation.ts lines 240 to 255OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +235,21 @@235+ yield* follow(scope.thread.threadId, taskId).pipe(Effect.forkIn(followers));236+ return { taskId };237+ });238+239+ /** Completes `task` here with its thread there's final state. */240+ const complete = (241+ parentThreadId: ThreadId,242+ taskId: NodeId,243+ status: "completed" | "failed" | "cancelled" | "interrupted",244+ result: string,245+ ) =>246+ threads247+ .dispatch({248+ type: "delegated_task.remote.complete",249+ commandId: CommandId.make(`command:remote-task-complete:${parentThreadId}:${taskId}`),250+ parentThreadId,251+ taskId,252+ status,253+ result,254+ })255+ .pipe(Effect.asVoid);apps/server/src/peer/RemoteDelegation.ts lines 514 to 530Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +281,21 @@281+ const follow = (parentThreadId: ThreadId, taskId: NodeId): Effect.Effect<void> =>282+ followOnce(parentThreadId, taskId).pipe(283+ // `false` means it is still running there: follow again straight away.284+ Effect.repeat({ while: (done) => !done }),285+ Effect.catch((error) =>286+ error._tag === "OrchestratorMcpFailure" && error.code === "capability_denied"287+ ? // The client's message already says the link was refused and how to renew it.288+ complete(parentThreadId, taskId, "failed", error.message).pipe(289+ Effect.ignoreCause({ log: true }),290+ )291+ : Effect.fail(error),292+ ),293+ Effect.retry(294+ Schedule.exponential(Duration.seconds(2)).pipe(295+ Schedule.modifyDelay(({ duration }) =>296+ Effect.succeed(Duration.min(duration, FOLLOW_MAX_BACKOFF)),297+ ),298+ ),299+ ),300+ Effect.ignoreCause({ log: true }),301+ );apps/server/src/peer/RemoteDelegation.ts lines 332 to 366OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +346,21 @@346+ }347+ yield* forwarding.call(scope, tools.t3_thread_interrupt, remote.environmentId, {348+ threadId: remote.threadId,349+ ...(reason === undefined ? {} : { reason }),350+ clientRequestId: `cancel:${task.id}`,351+ });352+ yield* complete(353+ task.threadId,354+ task.id,355+ "cancelled",356+ reason === undefined ? "Cancelled." : `Cancelled: ${reason}`,357+ ).pipe(358+ Effect.mapError((error) =>359+ failure("orchestration_error", `Unable to record the cancellation: ${error.message}`),360+ ),361+ );362+ return {363+ taskId: task.id,364+ status: "cancel_requested",365+ } satisfies OrchestratorMcpTaskCancelResult;366+ });docs/user/remote-access.md line 248OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -244,3 +244,5 @@244244 removes it here.245245 Links last 30 days. Link again with a new pairing code to renew one.246246247+An agent can also hand a task to a linked machine with `delegate_task`: it runs248+there as an ordinary thread, in the project with the same repository, and this
- apps/server/src/peer/RemoteDelegation.ts line 185OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +165,21 @@165+ const runtimeMode = yield* resolveRuntimeMode(parent.thread.runtimeMode, input.runtimeMode);166+ const interactionMode = yield* resolveInteractionMode(167+ parent.thread.interactionMode,168+ input.interactionMode,169+ );170+ const projectId = yield* resolveRemoteProject(171+ scope,172+ target.environmentId,173+ parent.thread.projectId,174+ target.projectId,175+ );176+ // One key for the launch there and the record here, so a retry finds both.177+ const key = input.clientRequestId ?? (yield* crypto.randomUUIDv4.pipe(Effect.orDie));178+ const launched = yield* forwarding.call(179+ scope,180+ ProjectToolkit.tools.t3_thread_launch,181+ target.environmentId,182+ {183+ projectId,184+ title: input.title ?? parent.thread.title,185+ modelSelection: { instanceId: target.providerInstanceId, model: target.model },
- apps/mobile/src/features/threads/threadAgentsPresentation.ts lines 37 to 38Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -20 +20,21 @@2020 readonly canOpenThread: boolean;21+ /** The linked environment the task runs in, when it runs in one. */22+ readonly runsOn: string | null;23+}24+25+/**26+ * Where an agent's thread opens: here, or in the linked environment that runs27+ * it. Null when there is no thread, or this app is not connected to that28+ * environment.29+ */30+export function subagentThreadTarget(31+ subagent: Pick<OrchestrationV2Subagent, "childThreadId" | "remoteChild">,32+ environmentId: EnvironmentId,33+ isKnownEnvironment: (environmentId: EnvironmentId) => boolean,34+): { readonly environmentId: EnvironmentId; readonly threadId: ThreadId } | null {35+ if (subagent.childThreadId !== null) {36+ return { environmentId, threadId: subagent.childThreadId };37+ }38+ const remote = subagent.remoteChild;39+ return remote !== undefined && isKnownEnvironment(remote.environmentId)40+ ? { environmentId: remote.environmentId, threadId: remote.threadId }apps/web/src/components/ChatView.tsx line 861Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2167,0 +2165,21 @@2165+ const delegatedFrom = activeThread?.delegatedFrom ?? null;2166+ const delegatedFromEnvironment = useEnvironment(delegatedFrom?.environmentId ?? null);2167+ const parentThreadLink = useMemo(() => {2168+ if (parentSubagentThreadRef !== null) {2169+ return {2170+ title: parentSubagentThread?.title ?? "Parent thread",2171+ open: (): void => {2172+ void navigate({2173+ to: "/$environmentId/$threadId",2174+ params: buildThreadRouteParams(parentSubagentThreadRef),2175+ });2176+ },2177+ };2178+ }2179+ if (delegatedFrom === null) return null;2180+ const parentRef = scopeThreadRef(delegatedFrom.environmentId, delegatedFrom.threadId);2181+ return {2182+ title: delegatedFrom.title,2183+ environmentLabel: delegatedFromEnvironment?.label ?? activeThread?.linkOrigin?.label ?? "",2184+ // Only an environment this client is connected to can open the parent.2185+ ...(delegatedFromEnvironment === null
- apps/server/src/peer/RemoteDelegation.ts line 349OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +329,21 @@329+330+ /** One wait on the task's thread there; true once the task here is done. */331+ const followOnce = (parentThreadId: ThreadId, taskId: NodeId) =>332+ Effect.gen(function* () {333+ const records = yield* threads.getThreadRecords(parentThreadId, ["subagents"]);334+ const task = records.subagents.find((candidate) => candidate.id === taskId);335+ if (task?.remoteChild === undefined || task.result !== null) return true;336+ const remote = task.remoteChild;337+ const scope: ThreadScope = {338+ environmentId: remote.environmentId,339+ requestNamespace: `remote-task:${parentThreadId}`,340+ thread: {341+ threadId: parentThreadId,342+ providerSessionId: `remote-task:${taskId}`,343+ providerInstanceId: records.thread.providerInstanceId,344+ },345+ client: undefined,346+ capabilities: new Set(["orchestration"]),347+ issuedAt: 0,348+ };349+ const waited = yield* forwarding.waitForThread(scope, remote.environmentId, {
- @@ -0,0 +244,21 @@244+ );245+ const taskEvent = recorded.storedEvents.find(246+ (stored) => stored.event.type === "subagent.updated",247+ );248+ const taskId =249+ taskEvent?.event.type === "subagent.updated"250+ ? taskEvent.event.payload.id251+ : // A replayed request recorded the task the first time.252+ yield* threads.getThreadRecords(scope.thread.threadId, ["subagents"]).pipe(253+ Effect.map(254+ ({ subagents }) =>255+ subagents.find((task) => task.remoteChild?.threadId === launched.threadId)?.id,256+ ),257+ Effect.orElseSucceed(() => undefined),258+ );259+ if (taskId === undefined) {260+ return yield* failure("orchestration_error", "The delegated task was not recorded.");261+ }262+ yield* follow(scope.thread.threadId, taskId).pipe(Effect.forkIn(followers));263+ return { taskId };264+ });
- apps/server/src/peer/RemoteDelegation.ts line 395OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +375,21 @@375+ ...(remote.runId === undefined ? {} : { runId: remote.runId }),376+ ...(reason === undefined ? {} : { reason }),377+ clientRequestId: `interrupt:${remote.threadId}`,378+ })379+ .pipe(380+ Effect.asVoid,381+ Effect.catchIf(382+ (error) => error.code === "thread_not_interruptible",383+ () => Effect.void,384+ ),385+ );386+387+ /** Interrupts a task that ended here; only a dropped route is worth trying again. */388+ const stopThere = (scope: ThreadScope, remote: OrchestrationV2RemoteTaskChild) =>389+ interruptThere(scope, remote).pipe(390+ Effect.retry({391+ schedule: backoff,392+ times: 5,393+ while: (error) => error.code === "orchestration_error",394+ }),395+ Effect.ignoreCause({ log: true }),apps/web/src/components/chat/ThreadRelationshipsControl.tsx line 662OutdatedResolvedby juliusmarminge@@ -572,3 +653,10 @@572653 }573654 </ThreadLineageGroup>574655 ))}656+ {remoteSubagents.length > 0 ? (657+ <ThreadLineageRowList hiddenCount={0} onShowMore={() => {}}>658+ {remoteSubagents.map((agent) => (659+ <RemoteSubagentRow660+ key={agent.id}661+ agent={agent}662+ provider={providers?.find((entry) => entry.instanceId === agent.providerInstanceId)}
- apps/server/src/peer/RemoteDelegation.ts line 461Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +401,21 @@401+ * The last reply `runId` gave on the task's thread there, which is its402+ * result, read whole however long it is. A read only pages forward, so403+ * it pages through the thread.404+ */405+ const lastReply = (406+ scope: ThreadScope,407+ remote: OrchestrationV2RemoteTaskChild,408+ runId: RunId | null,409+ ) =>410+ Effect.gen(function* () {411+ let reply: OrchestratorMcpThreadTimelineItem | undefined;412+ let afterPosition: number | undefined;413+ while (true) {414+ const read = yield* forwarding.call(scope, tools.t3_thread_read, remote.environmentId, {415+ threadId: remote.threadId,416+ view: "messages",417+ limit: 100,418+ ...(afterPosition === undefined ? {} : { afterPosition }),419+ });420+ reply =421+ read.items.findLast(apps/server/src/peer/RemoteDelegation.ts line 569OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +549,21 @@549+ ...(remote.runId === undefined ? {} : { runId: remote.runId }),550+ timeoutMs: FOLLOW_WAIT_MS,551+ })552+ .pipe(Effect.raceFirst(endedHere));553+ // The next look reads the result and stops it there.554+ if ("endedHere" in waited) return false;555+ if (waited.timedOut) return false;556+ // A task recorded without its run waits on the thread's latest; a557+ // thread there with none has nothing left to wait for.558+ if (waited.runId === null) {559+ const reply = yield* lastReply(scope, remote, null);560+ yield* complete(561+ parentThreadId,562+ taskId,563+ reply === undefined ? "failed" : "completed",564+ reply ?? "The thread in the linked environment has no run to follow.",565+ "ran-out",566+ );567+ return yield* settled(parentThreadId, taskId);568+ }569+ if (!isTerminal(waited.status)) return false;
- apps/server/src/orchestration-v2/ThreadManagementService.ts line 859OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -851,4 +853,7 @@851853 const { subagents } = yield* orchestrator.getThreadRecords(input.threadId, ["subagents"]);852854 const failures: Array<Orchestrator.OrchestratorV2Error> = [];853855 for (const task of subagents) {854- if (task.origin !== "app_owned" || task.childThreadId === null) continue;856+ if (task.origin !== "app_owned") continue;857+ if (task.childThreadId === null) {858+ // A task in a linked environment ends here; its follower then stops it there.859+ if (task.remoteChild === undefined || task.result !== null) continue;
- apps/server/src/orchestration-v2/Orchestrator.ts line 7791Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -6958,0 +7158,21 @@7158+ task.status === "cancelled" ||7159+ task.status === "interrupted" ||7160+ task.remoteChild?.stoppedThere === false;7161+ if (7162+ command.stoppedThere === undefined ||7163+ task.remoteChild?.stoppedThere === true ||7164+ (owesStop && command.stoppedThere !== "stopped")7165+ )7166+ return;7167+ const now = yield* DateTime.now;7168+ yield* emit(7169+ events,7170+ command,7171+ )({7172+ type: "subagent.updated",7173+ threadId: command.parentThreadId,7174+ ...(task.runId === null ? {} : { runId: task.runId }),7175+ nodeId: task.id,7176+ driver: task.driver,7177+ occurredAt: now,7178+ payload: { ...task, remoteChild, updatedAt: now },
- apps/server/src/peer/RemoteDelegation.ts line 265Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +220,21 @@220+ : yield* resolveRuntimeMode(parent.thread.runtimeMode, input.runtimeMode);221+ const interactionMode =222+ input.interactionMode === undefined || input.interactionMode === "inherit"223+ ? undefined224+ : yield* resolveInteractionMode(parent.thread.interactionMode, input.interactionMode);225+ const projectId = yield* resolveRemoteProject(226+ scope,227+ target.environmentId,228+ parent.thread.projectId,229+ target.projectId,230+ );231+ // One key for the launch there and the record here, so a retry finds both.232+ // Both are scoped to the provider session, as every key a caller passes is:233+ // the forwarder scopes the launch's, and the record's names it.234+ const key = input.clientRequestId ?? (yield* crypto.randomUUIDv4().pipe(Effect.orDie));235+ const task = taskPrompt(input);236+ const launched = yield* forwarding.call(237+ scope,238+ ProjectToolkit.tools.t3_thread_launch,239+ target.environmentId,240+ {
- apps/server/src/peer/RemoteDelegation.ts line 320Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +268,21 @@268+ };269+ const recorded = yield* threads270+ .dispatch({271+ type: "delegated_task.remote.request",272+ commandId,273+ parentThreadId: scope.thread.threadId,274+ parentRunId: parentRun.id,275+ parentNodeId,276+ task,277+ ...(input.title === undefined ? {} : { title: input.title }),278+ // The driver runs there; this side only labels the task with it.279+ driver: ProviderDriverKind.make("remote"),280+ modelSelection: launched.modelSelection,281+ remoteChild,282+ completionWake: input.mode === "wait" ? "settled_only" : "always",283+ })284+ .pipe(285+ Effect.mapError(286+ (error) =>287+ new OrchestratorMcpFailure({288+ code: "orchestration_error",
juliusmarminge assignedjuliusmarminge
- @@ -880,7 +892,12 @@880892 isTerminalRunStatus(run.status) && (yield* orchestrator.restartContinuationPending(run));881893 return { run, pending, settled: isTerminalRunStatus(run.status) && !pending };882894 });883- const initial = yield* outcome(target.runs);884- if (initial.settled) {885- return { threadId: input.threadId, run: initial.run, timedOut: false };886- }895+ const untilDelegatedWorkSettled = input.untilDelegatedWorkSettled === true;896+ const delegatedWorkResult = Effect.gen(function* () {897+ const records = yield* getProjectThreadRecords(898+ input,899+ ["runs", "messages", "subagents", "providerThreads"],900+ { messageRoles: ["user"] },901+ );902+ const progress = delegatedTaskProgress(records);903+ if (progress.state !== "result_available") return undefined;@@ -184,5 +224,16 @@184- if (185- next.size === previous.size &&186- [...next].every(([threadId, request]) => previous.get(threadId) === request)187- ) {188- return previous;224+ if (sameRequests(previous, next)) return previous;225+ previous = next;226+ return next;227+ }).pipe(Atom.withLabel(`environment-local-subagent-requests:${environmentId}`));228+ });229+230+ const pendingSubagentRequestsAtom = Atom.family((environmentId: EnvironmentId) => {231+ let previous = EMPTY_SUBAGENT_REQUESTS;232+ return Atom.make((get) => {233+ const delegated: Array<{ parentThreadId: ThreadId; request: PendingSubagentRequest }> = [];234+ for (const other of enabledEnvironmentIds(get(input.catalogValueAtom))) {235+ if (other === environmentId) continue;236+ for (const thread of get(environmentThreadsAtom(other))) {237+ if (thread.delegatedFrom?.environmentId !== environmentId) continue;238+ const own = subagentRequest(thread);239+ const nested = get(localSubagentRequestsAtom(other)).get(thread.id);
Sign in to join this conversation.





Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
b7b14bf· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.