Unify launch env resolution on the server + introduce project/worktree/thread env vars#3004
Unify launch env resolution on the server + introduce project/worktree/thread env vars#3004tarik02 wants to merge 17 commits into
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 introduces a new server-side environment resolution service (LaunchEnv) that changes how T3CODE_* environment variables are computed and propagated to terminals and providers. The architectural scope and runtime behavior changes warrant human review, as does an unresolved comment about missing project binding validation. 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>
Bind the terminal launch-env resolver at manager construction without unsafe casts, strip managed T3CODE_* keys in ACP spawns, merge per-session env for Grok, and pass projectId from setup scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
LaunchEnv no longer explicitly provides OrchestrationProjectionSnapshotQuery and RepositoryIdentityResolver since these dependencies are already available through the main application's OrchestrationLayerLive context. Changes: - LaunchEnvLayerLive now directly exports LaunchEnvLive (simplified from factory) - Dependencies auto-wire via Effect's context propagation - Removed makeLaunchEnvLayerLive factory which was building redundant layers - Updated ProviderCommandReactor.test to use simplified LaunchEnvLayerLive - Cleaner layer composition with no duplicate OrchestrationProjectionSnapshotQuery provision This reduces PR scope from 154 changed files to 3, maintaining the same functionality while improving architectural clarity by eliminating unnecessary layer wrapping. Co-authored-by: Cursor <cursoragent@cursor.com>
… line - Delete LaunchEnvLive.ts from Layers/ - it was just re-exporting LaunchEnvLive from Services/LaunchEnv.ts with no additional composition or transformation - Update imports to get LaunchEnvLive directly from Services/LaunchEnv.ts - Fix duplicate line in OrchestrationEngineHarness.integration.ts (378-379) - Cleaner architecture: no unnecessary layer wrapper files This simplifies the LaunchEnv module structure - the Services file already exports the Layer, so an intermediate Layers file added no value and just increased indirection. Co-authored-by: Cursor <cursoragent@cursor.com>
Follow app architecture pattern: Service files define only interface and class, implementation and Layer creation live in Layers/ files. Changes: - Services/LaunchEnv.ts: Contract only (Shape, types, service class with JSDoc) - Layers/LaunchEnvLive.ts: Implementation (makeResolveLaunchEnv, makeResolveForThread, Layer) - Update imports in server.ts, ProviderCommandReactor.test.ts, OrchestrationEngineHarness This matches the architectural pattern used throughout the codebase (e.g., OrchestrationEngine, ProviderService) where Shape and class live in Services/ and concrete implementations live in Layers/. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>


What Changed
Server now owns
T3CODE_*launch env for terminal and provider child processes.LaunchEnvto resolve home, project, thread, and worktree context from server state.projectId.T3CODE_*keys stripped from inherited and client-supplied env.T3CODE_*; they send cwd/worktree context plusprojectIdwhen needed.Closes #3003
Why
Make t3code provide
T3CODE_PROJECT_ROOT/T3CODE_WORKTREE_PATH(and related launch context) from one authoritative server path. Unified environment resolution between terminal and provider child processes, with managed-key filtering so parent/custom/client env cannot override or leak extraT3CODE_*values.UI Changes
No UI changes.
Checklist
Note
Unify launch environment resolution on the server and introduce T3CODE_* project/worktree/thread env vars
LaunchEnvservice (LaunchEnv.ts) that resolvesT3CODE_HOME,T3CODE_PROJECT_ROOT,T3CODE_PROJECT_ID, andT3CODE_THREAD_IDenv vars server-side from thread/project context, replacing client-computed envs.projectId; the terminal manager uses it withLaunchEnvto resolve worktree path and env at open/attach/restart time.mergeProviderSessionEnvironment, combining adapter-level and session-level env while stripping managedT3CODE_*keys.projectScriptRuntimeEnvis removed from web, mobile, and server setup runner; clients passprojectIdinstead and the server resolves env internally.isManagedRuntimeEnvKeyandstripManagedRuntimeEnvKeysutilities (launchEnv.ts) canonicalize managed-key detection across the codebase.T3CODE_*keys sent by clients are now stripped before use; provider and terminal environments are built server-side and will differ from previously client-supplied values.Macroscope summarized 4d5d682.
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.