Unify launch env resolution on the server.#3004
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Resolve authoritative T3CODE_* vars server-side for terminals and provider sessions, strip inherited runtime keys from spawns, and simplify clients to pass only cwd/thread context. Consolidate managed env helpers in shared and collapse terminal launch env wiring. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 767954b. Configure here.
| ...input, | ||
| env, | ||
| }; | ||
| }); |
There was a problem hiding this comment.
Open ignores thread project binding
Medium Severity
resolveTerminalOpenInput and resolveTerminalRestartInput build authoritative T3CODE_* env from client-supplied projectId only. They never load the thread and check that projectId matches the thread’s project. A caller can pass a different projectId while keeping another cwd/worktree, so spawned terminals get wrong project metadata even though managed keys in env are stripped.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 767954b. Configure here.
ApprovabilityVerdict: Needs human review This PR centralizes environment resolution on the server, introducing new services and changing how terminal/provider sessions receive environment variables. The architectural scope plus an unresolved review comment about missing project binding validation warrants careful review. You can customize Macroscope's approvability policy. Learn more. |
Resolve launch env at RPC time instead of layer construction, and derive project context from threadId server-side so terminal open/restart no longer trust client projectId. Co-authored-by: Cursor <cursoragent@cursor.com>
Allow optional client projectId when the thread is not yet persisted, while still resolving project context from the server thread when it exists. Co-authored-by: Cursor <cursoragent@cursor.com>


What Changed
Server now owns injection of
T3CODE_*launch environment for terminals and provider sessions.LaunchEnvservice (apps/server/src/launchEnv/) that builds authoritative env:T3CODE_HOMET3CODE_PROJECT_ROOTT3CODE_PROJECT_ID(new)T3CODE_THREAD_ID(new)T3CODE_WORKTREE_PATH(when a worktree is active)open,restart, andattachviaresolveTerminalLaunchEnv.ProviderCommandReactorpasses the same env into provider session starts; all four adapters merge it viamergeProviderSessionEnvironment.T3CODE_*keys are stripped before spawn so values cannot be spoofed.T3CODE_*; they passprojectId+ cwd/worktree context only.projectIdis now required onTerminalOpenInput/TerminalRestartInput.@t3tools/shared/launchEnvcentralizes managed-key detection/stripping.Closes #3003
Why
Make t3code provide
T3CODE_PROJECT_ROOT/T3CODE_WORKTREE_PATH. Unified environment resolution between terminal and provider child processes. Made env variables resolution mostly server-side + added variable filtering (don't passT3CODE_*from parent/custom vars)UI Changes
No UI changes.
Checklist
Note
Unify launch environment resolution for terminals and provider sessions on the server
LaunchEnvservice that resolvesT3CODE_*environment variables (project root, project ID, thread ID, worktree path) from project/thread context usingServerConfig.baseDirasT3CODE_HOME.projectIdand have their launch env resolved server-side viaresolveTerminalLaunchEnvbefore session start, replacing client-suppliedT3CODE_*env vars.ProviderCommandReactorwith instance-level env viamergeProviderSessionEnvironment, stripping managedT3CODE_*keys from user-supplied overrides.isManagedRuntimeEnvKeyandstripManagedRuntimeEnvKeysare extracted to@t3tools/shared/launchEnvas shared utilities;projectScriptRuntimeEnvis removed from@t3tools/shared/projectScripts.T3CODE_*env vars when opening terminals;projectIdis now required interminalOpenandterminalRestartAPI calls.TerminalOpenInputandTerminalRestartInputschema validation now requiresprojectId, making this a breaking contract change for any callers not yet updated.Macroscope summarized 767954b. (Automatic summaries will resume when PR exits draft mode or review begins).
Note
Medium Risk
Contract-breaking
projectIdon terminal open/restart and changed env injection paths affect all terminal/provider spawns; managed-key stripping is intentional but any external caller relying on client-setT3CODE_*will break.Overview
Centralizes
T3CODE_*launch environment on the server so terminals and provider child processes get the same authoritative context instead of clients building it locally.A new
LaunchEnvservice mergesT3CODE_HOME, project/thread/worktree fields (includingT3CODE_PROJECT_IDandT3CODE_THREAD_ID), strips client-suppliedT3CODE_*keys via@t3tools/shared/launchEnv, and is wired into the server runtime and integration tests.Terminals:
TerminalOpenInput/TerminalRestartInputnow requireprojectId; open, restart, and attach resolve env throughresolveTerminalLaunchEnvbefore spawn. Web/mobile stop sending synthesizedT3CODE_*(only cwd/worktree and optional non-managed custom env).Providers:
ProviderCommandReactorresolves launch env forstartSession; adapters merge per-session env withmergeProviderSessionEnvironment.projectScriptRuntimeEnvis removed from shared and clients.Reviewed by Cursor Bugbot for commit 767954b. Bugbot is set up for automated code reviews on this repo. Configure here.