fix(server): ACP agents get T3CODE_THREAD_ID like Claude and Codex sessions#30361
Problem
Claude sessions get T3CODE_THREAD_ID since #22542, and Codex sessions since #28604. Agents that run through the ACP layer (the ACP Registry agents such as Copilot CLI, claude-acp, Devin, Factory Droid, GLM and Mistral Vibe, plus local ACP executables) still do not: the per-thread process environment they are spawned with carries T3_ACP_MCP_*, but not the thread id.
So a process such an agent starts cannot find its T3 thread. Concretely: two ACP agents working from the same directory are indistinguishable to an MCP server they both launch (same host, same cwd, same client name), so an external resource broker hands a tmux pane reserved for one thread to the other, and a tool run from the agent's shell cannot reach its thread with t3 thread send.
Change
acpMcpContext already builds the per-thread processEnvironment. It now also carries T3CODE_THREAD_ID. That one spot covers the agent process spawn for ACP Registry agents (and the fx and kiro runtimes), and the per-session client terminals for every ACP flavor; a native child session's terminals get the child's own thread id. The variable name is a string literal with a comment pointing at PortScanner.AGENT_THREAD_ENV, since this package cannot reach apps/server (the Codex replay normalizer does the same).
Scope and approval
A small, focused fix for an obvious gap: it gives ACP agents the variable that #22542 gave Claude and #28604 gave Codex.
Verification
Unit tests, each failing without the fix: a registry agent spawned through the real AcpSessionRuntime (captured via a wrapping ChildProcessSpawner) has T3CODE_THREAD_ID beside T3_ACP_MCP_* in its process env; a terminal created on a forked session prints the fork target thread's id; after a session rollback the replacement runtime input names the rollback target thread. vpr check:changed passes (format, lint, knip, typecheck, tests). Tested on macOS only; I did not run a live registry agent in vp run dev.
Known limitation
The Grok and Antigravity drivers build their agent spawn env from the provider-instance environment and do not consume the per-thread processEnvironment, so those agent processes still do not see the variable; their per-session ACP client terminals do. Giving those spawns a per-thread id is left out of scope here.
Checks
Added 1 commit
- fix(server): ACP agents get T3CODE_THREAD_ID like Claude and Codex sessions66536ae
Approvability
Verdict: Approved at 66536ae
Macroscope's review found this PR approvable — ACP agents and their session terminals receive the same thread-identification variable already used by Claude and Codex. The change is limited to existing session-scoped environment plumbing, with no new permissions or persistent-data changes.
You can add or adjust custom eligibility rules. Learn more.
No actionable comments were generated in the recent review.
Walkthrough
ACP agent processes now receive the MCP session’s thread ID in
T3CODE_THREAD_ID. Tests verify this environment variable alongside existing MCP connection values and in forked-session and rollback scenarios.Changes: ACP Thread ID Environment
Layer / File(s) Summary Add thread ID to ACP process environment
packages/provider-acp/src/server/adapter.tsacpMcpContextadds the MCP session’s thread ID to the environment passed to ACP agent processes.Verify thread ID propagation
apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts,apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tsTests check the thread ID and MCP connection values in agent process environments, including forked-session and rollback cases. Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related PRs
- pingdotgg/t3code#28604: Both changes pass
T3CODE_THREAD_IDto provider processes; this PR targets Codex per-thread configuration.
Suggested labels:
bugfix,size:SSuggested reviewers:
juliusmarminge,maria-rcks,macroscopeapp- pingdotgg/t3code#28604: Both changes pass
Merge Risk: External image Low · up to 66536
A server started by a forked agent may appear under the source thread rather than the target. The impact is limited to this forked-session path.
Pre-merge checks: Passed 4
Check name Status Explanation Title check Passed The title names the main change: ACP agent processes now receive T3CODE_THREAD_ID, matching the existing Claude and Codex behavior. It uses a conventional commit prefix and is specific. The title is 7… Description check Passed The description covers the problem, the change, scope and approval, verification, and a known limitation. It follows the template's section headings. The problem and change sections are clear. The sco… Linked Issues check Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request. Full details: Title check
Explanation
The title names the main change: ACP agent processes now receive T3CODE_THREAD_ID, matching the existing Claude and Codex behavior. It uses a conventional commit prefix and is specific. The title is 75 characters, which is slightly long but acceptable.
Full details: Description check
Explanation
The description covers the problem, the change, scope and approval, verification, and a known limitation. It follows the template's section headings. The problem and change sections are clear. The scope section justifies the change as a small, focused fix of an obvious gap, which the template allows without a prior issue. The verification section lists focused unit tests, the command run, and what was not checked (live registry agent, non-macOS platforms). The description is mostly complete. The template asks for a conventional commit title, and the PR title follows that format.
Finishing Touches
Generate unit tests (beta)
- Create a new PR
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Tip
🎯 Customize your risk assessments
Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.
✅ Automatic approvals, with your rules
Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.
CodeRabbit Verify
- Run CodeRabbit Verify to test the changes in this pull request.
External image Recent review info
-
External image Run configuration
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 260297b
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
17cea8a8-6680-4924-9afa-65aaa9054203
External image Commits
Reviewing files that changed from the base of the PR and between 260297b55fc97c5b10ff55511967f6d20c622e54 and 66536ae27ec6807b2e378550b74a8adf35291322.
External image Files selected for processing: 3
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.tspackages/provider-acp/src/server/adapter.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
External image Recent review info
-
External image Run configuration
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 260297b
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
17cea8a8-6680-4924-9afa-65aaa9054203
External image Commits
Reviewing files that changed from the base of the PR and between 260297b55fc97c5b10ff55511967f6d20c622e54 and 66536ae27ec6807b2e378550b74a8adf35291322.
External image Files selected for processing: 3
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.tspackages/provider-acp/src/server/adapter.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Note
Written by gpt-6.1-sol on behalf of Maria
Verified in a real dev environment
verified head 66536ae27ec6807b2e378550b74a8adf35291322 on a disposable linux vm. no source changes were needed.
installed and ran github/main at 7c22e24e3f in a separate worktree first, then stopped its dev server and ran the exact pr head. used playwright from the repo dependencies with /usr/bin/google-chrome. created the project and local acp provider through settings, pointing at a real git repo. the provider was the real codex-acp 0.16.0 executable, using gpt-6.1-sol through the local proxy. no mocks, fixtures, replay provider, or seeded demo data.
the same prompt ran this shell command through the acp agent on both revisions. i expanded the actual tool output in the client to confirm it:
| 1 | printf 'THREAD_ID=%s\n' "${T3CODE_THREAD_ID-UNSET}"; pwd |
| 1 | main, client thread 3ea6b9a9-1459-4eea-b908-393d2ce92f12: |
| 2 | THREAD_ID=UNSET |
| 3 | /home/user/t3code |
| 4 | |
| 5 | pr, client thread bf8db3c1-c5e0-490e-8016-9d62223b47d3: |
| 6 | THREAD_ID=bf8db3c1-c5e0-490e-8016-9d62223b47d3 |
| 7 | /home/user/t3code |
| 8 | |
| 9 | pr, second successful acp thread in the same directory: |
| 10 | THREAD_ID=70d6a852-1744-42d9-ba6f-514709de5036 |
| 11 | /home/user/t3code |
nearby behavior: a follow-up in the first pr session kept its own id. a second successful acp session received a different id matching its final client url. native codex with gpt-6.1-sol also returned its own client thread id, 32bf2014-0ca1-49db-92e9-37120514aab1.
main:
main acp shell reports THREAD_ID=UNSET
pr, same prompt and directory:
pr acp shell reports its client thread id
another real acp turn, from submission to output:
second acp thread runs the shell command and returns its own id
blacksmith checks passed: both focused adapter suites, 118 tests; vp run check:changed 9def583f8e315f644708501ebcf1f3d4bb320444 against the pr's parent, including format, lint, knip, graphql, 14 affected package typechecks, and 119 tests in 3 files. github reported 23 successful checks and 7 skipped checks.
Not verified
one intervening acp session failed before producing output with WebSocket protocol error: Connection reset without closing handshake, followed by an internal error on retry. a fresh session subsequently succeeded. this does not establish that the proxy transport is reliable; the failed session was retained in the evidence.
native desktop, ios/android, macos/windows, remote/relay/tunnel connections, other acp executables, and grok/antigravity process environments were not exercised. native fork terminal and rollback paths passed automated checks but were not exercised with a live provider. external resource-broker integration and t3 thread send were not exercised.