@devries-cameron20 / t3code-1 / commits / fe1f1a5732
Fork 0

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

fix(acp): Devin terminals no longer inherit the launching thread's T3 MCP credentials (#26652)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Ian Rowe committed Nov 18, 2026 at 05:08 UTC fe1f1a5732d8a72f435ee4981bef303d88d7dc7f
2 files changed +69 -17
packages/provider-acp/src/server/clientTerminals.test.ts
+38 -7
@@ -99,28 +99,59 @@ describe("AcpClientTerminals", () => {
99
100 it.live("resolves terminal environment from the requesting ACP session", () =>
101 Effect.gen(function* () {
102 + const inheritedEnvironment = yield* HostProcess.Environment;
103 const terminals = yield* makeAcpClientTerminals({
104 defaultCwd: process.cwd(),
104 - environmentForSession: (sessionId) => ({
105 - T3_TEST_ACP_SESSION_TOKEN: sessionId === "session-a" ? "token-a" : "token-b",
106 - }),
105 + environmentForSession: (sessionId) =>
106 + sessionId === "unknown"
107 + ? undefined
108 + : {
109 + T3_ACP_MCP_AUTHORIZATION: sessionId === "session-a" ? "token-a" : "token-b",
110 + T3CODE_THREAD_ID: sessionId,
111 + },
112 });
113 yield* Effect.addFinalizer(() => terminals.disposeAll);
114 + inheritedEnvironment.T3_TEST_INHERITED = "refreshed";
115
116 for (const [sessionId, expected] of [
111 - ["session-a", "token-a"],
112 - ["session-b", "token-b"],
117 + ["session-a", "token-a||session-a|refreshed|T3_TEST_OVERRIDE=request"],
118 + ["session-b", "token-b||session-b|refreshed|T3_TEST_OVERRIDE=request"],
119 + ["unknown", "|||refreshed|T3_TEST_OVERRIDE=inherited"],
120 ] as const) {
121 const created = yield* terminals.create({
122 sessionId,
123 command: process.execPath,
117 - args: ["-e", "process.stdout.write(process.env.T3_TEST_ACP_SESSION_TOKEN ?? '')"],
124 + args: [
125 + "-e",
126 + "const env = process.env; process.stdout.write([env.T3_ACP_MCP_AUTHORIZATION ?? '', env.t3_Acp_Mcp_Endpoint ?? '', env.T3CODE_THREAD_ID ?? '', env.T3_TEST_INHERITED, ...Object.keys(env).filter((name) => name.toUpperCase() === 'T3_TEST_OVERRIDE').map((name) => name + '=' + env[name])].join('|'))",
127 + ],
128 + ...(sessionId === "unknown"
129 + ? {}
130 + : {
131 + env: [
132 + { name: "T3_TEST_OVERRIDE", value: "first" },
133 + { name: "t3_Test_Override", value: "second" },
134 + { name: "T3_TEST_OVERRIDE", value: "request" },
135 + ],
136 + }),
137 });
138 yield* terminals.waitForExit({ sessionId, terminalId: created.terminalId });
139 const output = yield* terminals.output({ sessionId, terminalId: created.terminalId });
140 expect(output.output).toBe(expected);
141 }
123 - }).pipe(Effect.provide(NodeServices.layer)),
142 + }).pipe(
143 + Effect.provideService(HostProcess.Environment, {
144 + ...process.env,
145 + T3_ACP_MCP_AUTHORIZATION: "launching-thread-token",
146 + t3_Acp_Mcp_Endpoint: "launching-thread-endpoint",
147 + T3CODE_THREAD_ID: "launching-thread",
148 + T3_TEST_INHERITED: "kept",
149 + T3_TEST_OVERRIDE: "inherited",
150 + }),
151 + // Exercise Windows' case-insensitive variable names on every OS.
152 + Effect.provideService(HostProcess.Platform, "win32"),
153 + Effect.provide(NodeServices.layer),
154 + ),
155 );
156
157 it.live("runs Devin shell source with arguments, pipes, and session fallback variables", () =>
packages/provider-acp/src/server/clientTerminals.ts
+31 -10
@@ -12,6 +12,7 @@ import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
12 import * as EffectAcpErrors from "effect-acp/errors";
13 import type * as EffectAcpSchema from "effect-acp/compat";
14 import * as NodeBuffer from "node:buffer";
15 +import * as HostProcess from "@t3tools/shared/HostProcess";
16
17 const MAX_LIVE_TERMINALS = 16;
18 const MAX_UNRELEASED_TERMINALS = 64;
@@ -137,22 +138,38 @@ function acpTerminalCommand(input: {
138 readonly request: EffectAcpSchema.CreateTerminalRequest;
139 readonly shellCommands?: boolean | undefined;
140 readonly defaultCwd: string;
140 - readonly environment?: NodeJS.ProcessEnv | undefined;
141 + readonly environment: NodeJS.ProcessEnv;
142 readonly forceKillAfter: Duration.Input;
143 }) {
144 return ChildProcess.make(input.request.command, input.request.args ?? [], {
145 cwd: input.request.cwd ?? input.defaultCwd,
145 - ...(input.environment === undefined ? {} : { env: input.environment }),
146 + env: input.environment,
147 shell: input.shellCommands === true && (input.request.args?.length ?? 0) === 0,
148 forceKillAfter: input.forceKillAfter,
149 });
150 }
151
152 +// Windows variable names are case-insensitive and Node passes only one spelling to the child,
153 +// so a later layer's `Path` must replace an earlier `PATH` rather than sit beside it.
154 +function mergeEnvironments(
155 + isWindows: boolean,
156 + layers: ReadonlyArray<Iterable<readonly [string, string | undefined]>>,
157 +) {
158 + const variables = new Map<string, readonly [string, string | undefined]>();
159 + for (const layer of layers) {
160 + for (const [name, value] of layer) {
161 + variables.set(isWindows ? name.toUpperCase() : name, [name, value]);
162 + }
163 + }
164 + return Object.fromEntries(variables.values());
165 +}
166 +
167 export const makeAcpClientTerminals = Effect.fn("makeAcpClientTerminals")(function* (
168 options: AcpClientTerminalsOptions,
169 ): Effect.fn.Return<AcpClientTerminals, never, ChildProcessSpawner.ChildProcessSpawner> {
170 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
171 const forceKillAfter = options.forceKillAfter ?? "5 seconds";
172 + const isWindows = yield* HostProcess.isWindows;
173 const creationPermit = yield* Semaphore.make(1);
174 const terminals = new Map<string, ManagedAcpTerminal>();
175 let nextTerminalNumber = 1;
@@ -215,16 +232,20 @@ export const makeAcpClientTerminals = Effect.fn("makeAcpClientTerminals")(functi
232 `ACP terminal/create exceeded the limit of ${MAX_LIVE_TERMINALS} concurrent terminals.`,
233 );
234 }
218 - const requestEnvironment = Object.fromEntries(
219 - (request.env ?? []).map((variable) => [variable.name, variable.value] as const),
235 + // Thread credentials and identity must come from the requesting session.
236 + const inheritedEnvironment = Object.fromEntries(
237 + Object.entries(options.environment ?? (yield* HostProcess.Environment)).filter(
238 + ([name]) =>
239 + !name.toUpperCase().startsWith("T3_ACP_MCP_") &&
240 + name.toUpperCase() !== "T3CODE_THREAD_ID",
241 + ),
242 );
243 const sessionEnvironment = options.environmentForSession?.(request.sessionId);
222 - const environment =
223 - options.environment === undefined &&
224 - sessionEnvironment === undefined &&
225 - (request.env?.length ?? 0) === 0
226 - ? undefined
227 - : { ...options.environment, ...sessionEnvironment, ...requestEnvironment };
244 + const environment = mergeEnvironments(isWindows, [
245 + Object.entries(inheritedEnvironment),
246 + Object.entries(sessionEnvironment ?? {}),
247 + (request.env ?? []).map((variable) => [variable.name, variable.value] as const),
248 + ]);
249 const terminalScope = yield* Scope.make();
250 const child = yield* restore(
251 spawner