feat(server): agents use linked environments through any T3 tool #16684
t3code/peer/links fromrefs/pull/16684/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
juliusmarminge added labelsmacroscope-review
- apps/server/src/mcp/toolkits/orchestrator/handlers.ts lines 163 to 166OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -113,8 +150,17 @@113- const scope = yield* McpInvocationContext.McpInvocationContext;114- const service = yield* OrchestratorMcpService.OrchestratorMcpService;115- return yield* service.sendToThread(scope, input);116- }),150+ routed(151+ tools.t3_thread_send,152+ input,153+ Effect.gen(function* () {154+ const scope = yield* McpInvocationContext.McpInvocationContext;155+ const service = yield* OrchestratorMcpService.OrchestratorMcpService;156+ return yield* service.sendToThread(scope, input);157+ }),158+ ),117159 ),118160 t3_thread_wait: McpToolAccess.reads((input) =>119161 Effect.gen(function* () {120162 const scope = yield* McpInvocationContext.McpInvocationContext;163+ const target = PeerForwarding.remoteTarget(scope, input.environmentId);164+ if (target !== undefined) {165+ const forwarding = yield* PeerForwarding.PeerForwarding;166+ return yield* forwarding.waitForThread(scope, target, input);
- @@ -2472,0 +2477,21 @@2477+ const commandId = stableCommandId({ scope, requestKey: key, operation: "thread-stop" });2478+ const stopFailed = (error: unknown) =>2479+ failure(2480+ "orchestration_error",2481+ `Unable to stop thread ${input.threadId}: ${errorMessage(error)}`,2482+ );2483+ yield* threadManagement2484+ .dispatch({2485+ type: "thread.stop",2486+ commandId,2487+ threadId: input.threadId,2488+ ...(input.reason === undefined ? {} : { reason: input.reason }),2489+ })2490+ .pipe(Effect.mapError(stopFailed));2491+ // A retry with the same clientRequestId repeats only the stops that failed.2492+ yield* threadManagement2493+ .stopDelegatedTasks({ threadId: input.threadId, commandId, reason: input.reason })2494+ .pipe(Effect.mapError(stopFailed));2495+ return {2496+ threadId: input.threadId,2497+ runId: running?.id ?? null,
- apps/server/src/mcp/toolkits/orchestrator/tools.ts line 201OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -192,4 +198,4 @@192198193199 const ThreadReadTool = Tool.make("t3_thread_read", {194200 description:195- "Read durable state and a paginated timeline from any T3 thread in this environment. The default messages view returns user messages, assistant messages, and proposed plans; activity returns all summarized timeline items. Reading an untruncated terminal assistant result from this parent thread's direct app-owned child acknowledges that child's automatic completion delivery. Continue with afterPosition=nextPosition. Recover long item text with itemId and textOffset=nextTextOffset until nextTextOffset is null; offsets count UTF-16 code units. The thread also reports its snooze state. To link a thread for the user, write `[title](t3-thread://v1/<threadId>)` with the threadId exactly as returned, not URL-encoded; T3 Code shows the thread's current title.",201+ "Read durable state and a paginated timeline from any T3 thread in this environment, or in a linked one with environmentId. The default messages view returns user messages, assistant messages, and proposed plans; activity returns all summarized timeline items. Reading an untruncated terminal assistant result from this parent thread's direct app-owned child acknowledges that child's automatic completion delivery. Continue with afterPosition=nextPosition. Recover long item text with itemId and textOffset=nextTextOffset until nextTextOffset is null; offsets count UTF-16 code units. The thread also reports its snooze state. To link a thread for the user, write `[title](t3-thread://v1/<threadId>)` with the threadId exactly as returned, not URL-encoded; T3 Code shows the thread's current title.",
- apps/server/src/mcp/toolkits/project/handlers.ts line 77OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -56,8 +59,19 @@5659 yield* readCaller();5760 return yield* Project.ProjectService;5861 });62+63+/** The linked environment a call names, or nothing for this one. */64+const remoteTarget = (input: { readonly environmentId?: EnvironmentId | undefined }) =>65+ McpInvocationContext.McpInvocationContext.pipe(66+ Effect.map((scope) => ({67+ scope,68+ target: PeerForwarding.remoteTarget(scope, input.environmentId),69+ })),70+ );5971 export const layer = McpToolAccess.toLayer(ProjectToolkit, {6072 t3_thread_launch: McpToolAccess.startsThreads(6173 (input) => input,6274 (input, { runtimeMode, interactionMode }) =>6375 Effect.gen(function* () {76+ const { scope, target } = yield* remoteTarget(input);77+ if (target !== undefined) {
juliusmarminge changed the title
juliusmarminge changed the title
juliusmarminge assignedjuliusmarminge
juliusmarminge closed this
juliusmarminge reopened this
- apps/server/src/mcp/OrchestratorMcpService.ts line 2942Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2772,0 +2783,21 @@2783+ Effect.andThen(2784+ Effect.fail(2785+ failure("orchestration_error", `Unable to stop thread ${input.threadId}.`),2786+ ),2787+ ),2788+ );2789+ const stopped = yield* threadManagement2790+ .dispatch({2791+ type: "thread.stop",2792+ commandId,2793+ threadId: input.threadId,2794+ ...(input.reason === undefined ? {} : { reason: input.reason }),2795+ })2796+ .pipe(Effect.catch(stopFailed));2797+ // A retry with the same clientRequestId repeats only the stops that failed.2798+ yield* threadManagement2799+ .stopDelegatedTasks({ threadId: input.threadId, commandId, reason: input.reason })2800+ .pipe(Effect.catch(stopFailed));2801+ // The run this stop interrupted, from its own events, so a retry2802+ // reports the same run even if another has started since.2803+ const interrupted = stopped.storedEvents.find(
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
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -224,4 +232,6 @@224232 const ThreadUpdateTool = Tool.make("t3_thread_update", {225233 description:226234 "Update metadata for a thread. Omit threadId to update this thread. Use action='rename' with title, action='regenerate_title' with no extra field, action='link_pull_request' with pullRequest, or action='unlink_pull_request'. Workspace and branch changes are intentionally not supported. clientRequestId makes retries idempotent.",227- parameters: ThreadMetadataMcpUpdateInput,235+ parameters: Schema.Struct({236+ environmentId: OrchestratorMcpEnvironmentTarget,237+ ...ThreadMetadataMcpUpdateInput.fields,
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
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/server/src/mcp/OrchestratorMcpService.ts lines 2930 to 2930Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2910,2 +2910,21 @@29102910 yield* resolveInteractionMode(limits.interactionMode, target.thread.interactionMode);29112911 const key = yield* requestKey(input.clientRequestId);2912+ // A peer from before `stop` drops it when decoding, so it interrupts2913+ // the run instead, as this call did then.2914+ if (input.stop === true) {2915+ const commandId = stableCommandId({ scope, requestKey: key, operation: "thread-stop" });2916+ // The cause goes to the log; the caller learns only that the stop failed.2917+ const stopFailed = (error: unknown) =>2918+ Effect.logWarning("orchestrator-mcp.thread-stop-failed", {2919+ threadId: input.threadId,2920+ error,2921+ }).pipe(2922+ Effect.andThen(2923+ Effect.fail(2924+ failure("orchestration_error", `Unable to stop thread ${input.threadId}.`),2925+ ),2926+ ),2927+ );2928+ const stopped = yield* threadManagement2929+ .dispatch({2930+ type: "thread.stop",
juliusmarminge added labelsagent-context-increase
juliusmarminge merged thiscb98850
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
65a1499· 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.