@devries-cameron20 / t3code-1 / commits / 396e646c4f
Fork 0

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

fix(server): ACP agents get T3CODE_THREAD_ID like Claude and Codex sessions (#30361)

Frank Hommers committed Nov 6, 2026 at 05:26 UTC 396e646c4fd387f021340b8945f813c78c67eaea
3 files changed +96 -2
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+12 -2
@@ -4431,7 +4431,10 @@ describe("AcpAdapterV2", () => {
4431 {
4432 sessionId: "mock-session-1-fork",
4433 command: process.execPath,
4434 - args: ["-e", "process.stdout.write(process.env.T3_ACP_MCP_AUTHORIZATION ?? '')"],
4434 + args: [
4435 + "-e",
4436 + "process.stdout.write(`${process.env.T3CODE_THREAD_ID ?? ''}\n${process.env.T3_ACP_MCP_AUTHORIZATION ?? ''}`)",
4437 + ],
4438 },
4439 { requestId: "test-terminal-create", method: "terminal/create" },
4440 );
@@ -4449,7 +4452,10 @@ describe("AcpAdapterV2", () => {
4452 },
4453 { requestId: "test-terminal-output", method: "terminal/output" },
4454 );
4452 - assert.equal(terminalOutput.output, "Bearer target-thread-token");
4455 + assert.equal(
4456 + terminalOutput.output,
4457 + "thread-acp-native-fork-target\nBearer target-thread-token",
4458 + );
4459 }).pipe(Effect.provide(layerTest), Effect.scoped),
4460 );
4461
@@ -5081,6 +5087,10 @@ describe("AcpAdapterV2", () => {
5087 runtimeInputs[1]?.processEnvironment?.T3_ACP_MCP_AUTHORIZATION,
5088 "Bearer rollback-target-token",
5089 );
5090 + assert.equal(
5091 + runtimeInputs[1]?.processEnvironment?.T3CODE_THREAD_ID,
5092 + "thread-acp-rollback-session-target",
5093 + );
5094 const replacementMcpServer = runtimeInputs[1]?.mcpServers[0];
5095 const replacementMcpEnvironment =
5096 replacementMcpServer !== undefined &&
apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
+79
@@ -1248,6 +1248,85 @@ describe("AcpRegistryAdapterV2", () => {
1248 }).pipe(Effect.provide(layerTest), Effect.scoped),
1249 );
1250
1251 + it.effect("the agent process env names the thread it serves", () =>
1252 + Effect.gen(function* () {
1253 + const selfInvocation = yield* resolveSelfInvocation();
1254 + const mockAgentPath = yield* (yield* Path.Path).fromFileUrl(
1255 + new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
1256 + );
1257 + const endpoint = "http://127.0.0.1:43123/mcp";
1258 + const instanceId = ProviderInstanceId.make("acp-registry-thread-env");
1259 + const threadId = ThreadId.make("thread-acp-registry-thread-env");
1260 + yield* (yield* McpProviderSessions.McpProviderSessions).set({
1261 + environmentId: EnvironmentId.make("environment-acp-registry-thread-env"),
1262 + threadId,
1263 + providerSessionId: "mcp-session-acp-registry-thread-env",
1264 + providerInstanceId: instanceId,
1265 + endpoint,
1266 + authorizationHeader: "Bearer thread-env-token",
1267 + browserToolsAvailable: false,
1268 + });
1269 + // Several agents can run from one directory at once; the spawn env is how
1270 + // a process the agent starts (an MCP server, a shell tool) finds its own
1271 + // T3 thread, the same way Claude and Codex sessions do.
1272 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
1273 + const spawnEnvironments: Array<Record<string, unknown> | undefined> = [];
1274 + const capturingSpawner = ChildProcessSpawner.make((command) =>
1275 + Effect.sync(() => {
1276 + if (command._tag === "StandardCommand") spawnEnvironments.push(command.options.env);
1277 + }).pipe(Effect.andThen(spawner.spawn(command))),
1278 + );
1279 + const withCapturedSpawns = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
1280 + effect.pipe(
1281 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, capturingSpawner),
1282 + );
1283 + const adapter = yield* withCapturedSpawns(
1284 + makeAcpRegistryAdapterV2({
1285 + selfInvocation,
1286 + instanceId,
1287 + settings: yield* decodeAcpRegistryAdapterSettings({ agentId: "claude-acp" }),
1288 + environment: {},
1289 + }).pipe(
1290 + Effect.provide(
1291 + Layer.mock(AcpRegistrySupport.AcpRegistryCatalog)({
1292 + resolve: () =>
1293 + Effect.succeed({
1294 + distribution: "local" as const,
1295 + spawn: {
1296 + command: process.execPath,
1297 + args: [mockAgentPath],
1298 + env: { T3_ACP_SESSION_LIFECYCLE: "1" },
1299 + },
1300 + }),
1301 + }),
1302 + ),
1303 + ),
1304 + );
1305 + const modelSelection = { instanceId, model: "default" } as const;
1306 + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1307 + runtimeMode: "full-access",
1308 + interactionMode: "default",
1309 + cwd: process.cwd(),
1310 + });
1311 + const runtime = yield* withCapturedSpawns(
1312 + adapter.openSession({
1313 + threadId,
1314 + providerSessionId: ProviderSessionId.make("provider-session-acp-registry-thread-env"),
1315 + modelSelection,
1316 + runtimePolicy,
1317 + }),
1318 + );
1319 + yield* withCapturedSpawns(runtime.ensureThread({ threadId, modelSelection, runtimePolicy }));
1320 + const agentEnvironment = spawnEnvironments.find(
1321 + (environment) => environment?.T3_ACP_SESSION_LIFECYCLE === "1",
1322 + );
1323 + assert.isDefined(agentEnvironment, "the agent itself must have been spawned");
1324 + assert.equal(agentEnvironment?.T3CODE_THREAD_ID, "thread-acp-registry-thread-env");
1325 + assert.equal(agentEnvironment?.T3_ACP_MCP_ENDPOINT, endpoint);
1326 + assert.equal(agentEnvironment?.T3_ACP_MCP_AUTHORIZATION, "Bearer thread-env-token");
1327 + }).pipe(Effect.provide(layerTest), Effect.scoped),
1328 + );
1329 +
1330 it.effect.each(["before", "after"] as const)(
1331 "reconciles a full prompt echo %s acknowledgment",
1332 (ordering) =>
packages/provider-acp/src/server/adapter.ts
+5
@@ -870,6 +870,11 @@ function acpMcpContext(
870 endpoint: session.endpoint,
871 authorization: session.authorizationHeader,
872 processEnvironment: {
873 + // The thread id every process the agent starts inherits, so a tool run
874 + // from its shell can find its T3 thread. Claude and Codex sessions set
875 + // the same variable (PortScanner.AGENT_THREAD_ENV; a string literal here
876 + // because this package cannot reach apps/server).
877 + T3CODE_THREAD_ID: session.threadId,
878 T3_ACP_MCP_ENDPOINT: session.endpoint,
879 T3_ACP_MCP_AUTHORIZATION: session.authorizationHeader,
880 T3_ACP_MCP_NODE: self.command,