Skip to content

Unify launch env resolution on the server + introduce project/worktree/thread env vars#3004

Open
tarik02 wants to merge 17 commits into
pingdotgg:mainfrom
tarik02:unify-launch-env
Open

Unify launch env resolution on the server + introduce project/worktree/thread env vars#3004
tarik02 wants to merge 17 commits into
pingdotgg:mainfrom
tarik02:unify-launch-env

Conversation

@tarik02

@tarik02 tarik02 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

What Changed

Server now owns T3CODE_* launch env for terminal and provider child processes.

  • Added LaunchEnv to resolve home, project, thread, and worktree context from server state.
  • Terminals resolve launch env on open/restart/attach, including draft-thread opens with a supplied projectId.
  • Provider sessions use the same env path, with managed T3CODE_* keys stripped from inherited and client-supplied env.
  • Web/mobile stop synthesizing T3CODE_*; they send cwd/worktree context plus projectId when 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 extra T3CODE_* values.

Знімок екрана 2026-06-10 о 21 02 28

UI Changes

No UI changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (N/A)
  • I included a video for animation/interaction changes (N/A)

Note

Unify launch environment resolution on the server and introduce T3CODE_* project/worktree/thread env vars

  • Introduces a new LaunchEnv service (LaunchEnv.ts) that resolves T3CODE_HOME, T3CODE_PROJECT_ROOT, T3CODE_PROJECT_ID, and T3CODE_THREAD_ID env vars server-side from thread/project context, replacing client-computed envs.
  • All terminal open/attach/restart inputs now optionally accept projectId; the terminal manager uses it with LaunchEnv to resolve worktree path and env at open/attach/restart time.
  • Provider adapters (Claude, Codex, Cursor, Grok, OpenCode) now receive a merged per-session env via mergeProviderSessionEnvironment, combining adapter-level and session-level env while stripping managed T3CODE_* keys.
  • Client-side projectScriptRuntimeEnv is removed from web, mobile, and server setup runner; clients pass projectId instead and the server resolves env internally.
  • Shared isManagedRuntimeEnvKey and stripManagedRuntimeEnvKeys utilities (launchEnv.ts) canonicalize managed-key detection across the codebase.
  • Behavioral Change: managed 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 projectId on 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-set T3CODE_* 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 LaunchEnv service merges T3CODE_HOME, project/thread/worktree fields (including T3CODE_PROJECT_ID and T3CODE_THREAD_ID), strips client-supplied T3CODE_* keys via @t3tools/shared/launchEnv, and is wired into the server runtime and integration tests.

Terminals: TerminalOpenInput / TerminalRestartInput now require projectId; open, restart, and attach resolve env through resolveTerminalLaunchEnv before spawn. Web/mobile stop sending synthesized T3CODE_* (only cwd/worktree and optional non-managed custom env).

Providers: ProviderCommandReactor resolves launch env for startSession; adapters merge per-session env with mergeProviderSessionEnvironment. projectScriptRuntimeEnv is 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.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b18412e6-a56f-4842-81d7-8a7ae34c4d96

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XL 500-999 changed lines (additions + deletions). labels Jun 8, 2026
Comment thread apps/server/src/terminal/resolveTerminalLaunchEnv.ts Outdated
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>
@tarik02 tarik02 force-pushed the unify-launch-env branch from f456ef5 to 767954b Compare June 9, 2026 16:24
@tarik02 tarik02 marked this pull request as ready for review June 9, 2026 16:39

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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,
};
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 767954b. Configure here.

@macroscopeapp

macroscopeapp Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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.

@tarik02 tarik02 marked this pull request as draft June 9, 2026 17:19
tarik02 and others added 11 commits June 9, 2026 20:33
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>
Comment thread apps/server/src/launchEnv/Layers/LaunchEnvLive.ts Outdated
@github-actions github-actions Bot added size:XXL 1,000+ changed lines (additions + deletions). and removed size:XL 500-999 changed lines (additions + deletions). labels Jun 10, 2026
Comment thread apps/web/src/cloud/linkEnvironment.ts Outdated
Comment thread apps/web/src/cloud/linkEnvironment.ts Outdated
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:XXL 1,000+ changed lines (additions + deletions). labels Jun 10, 2026
@tarik02 tarik02 changed the title Unify launch env resolution on the server. Unify launch env resolution on the server + introduce project/worktree/thread env vars Jun 10, 2026
@tarik02 tarik02 marked this pull request as ready for review June 10, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Expose current thread info via environment variables

1 participant