Skip to content

Commit 96ccee7

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(upstream-fixes): agents no longer inherit the live server's port settings (#1828)
## Problem A service unit can pass `T3CODE_PORT`, `T3CODE_HOST`, `T3CODE_MODE`, and `T3CODE_NO_BROWSER` as env. The server passed them on to every agent and terminal. A plain `vp run dev` there resolved `serverPort=3773`, the live server, so the dev web proxied to the live install. The removed dev-app launcher hid this; #1827 makes plain `vp run dev` the agent path. ## Change - `stripInheritedProviderEnvironment` also drops those four keys - it now runs after `resolveServerConfig`, which reads them - `T3CODE_HOME` stays: worktree dev outranks it ## Scope and approval Found by aftercare A1 on #1827. Upstream desktop never passes these to its backend, so this stays fork-only. ## Verification ```text vp test run src/provider/providerSessionEnvironment.fork.test.ts src/provider/providerSessionEnvironment.test.ts src/cli → exit 0 (97 passed) vp run typecheck → exit 0 vp run fork:ci → exit 0 ``` `vp run dev --dry-run` in an agent shell: | Env | serverPort | | --- | --- | | inherited | 3773 (live) | | stripped | 15977 | Claude Opus 5.5, via Claude Code. ## Fork trailers Squashes: - 6c1ea93 fix(upstream-fixes): agents no longer inherit the live server's port settings (#1828) (#1828) - 2ca7974 fixup! fix(upstream-fixes): agents no longer inherit the live server's port settings (#1828) (#1828) Fork-Domain: upstream-fixes Fork-Tier: bugfix Fork-Upstreamable: no Co-authored-by: donjor <[email protected]>
1 parent 5d5f3eb commit 96ccee7

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎apps/server/src/cli/server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const runServerCommand = Effect.fn("server.runServerCommand")(function* (
2929
readonly rejectRunningServer?: boolean;
3030
},
3131
) {
32-
yield* stripInheritedProviderEnvironment; // fork-hook: upstream-fixes/server-inherited-session-identity
3332
const logLevel = yield* GlobalFlag.LogLevel;
3433
const config = yield* resolveServerConfig(flags, logLevel, options);
34+
yield* stripInheritedProviderEnvironment; // fork-hook: upstream-fixes/server-inherited-session-identity
3535
const run = runServer.pipe(Effect.provideService(ServerConfig.ServerConfig, config));
3636
if (config.mode !== "desktop" || config.desktopBootstrapToken === undefined) return yield* run;
3737
yield* Effect.sync(() => {

‎apps/server/src/provider/providerSessionEnvironment.fork.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ describe("provider session identity helpers", () => {
5050

5151
describe("stripInheritedProviderEnvironment", () => {
5252
it.effect(
53-
"drops inherited session ids and desktop launcher settings from the server environment",
53+
"drops inherited session ids, server runtime, and desktop launcher settings from the server environment",
5454
() =>
5555
Effect.gen(function* () {
5656
const environment: NodeJS.ProcessEnv = {
5757
...leaked,
58-
T3CODE_DESKTOP_AGENT_WORKSPACE: "agent-workspace",
59-
T3CODE_DESKTOP_AGENT_PLACEMENT_TITLE: "placement",
58+
T3CODE_PORT: "3773",
59+
T3CODE_HOST: "127.0.0.1",
60+
T3CODE_MODE: "web",
61+
T3CODE_NO_BROWSER: "true",
62+
T3CODE_HOME: "/home/user/.t3",
6063
T3CODE_DESKTOP_REMOTE_DEBUGGING_PORT: "9222",
6164
T3CODE_DESKTOP_USER_DATA_DIR: "/desktop/data",
6265
T3CODE_DESKTOP_DEVTOOLS: "0",
@@ -70,6 +73,7 @@ describe("stripInheritedProviderEnvironment", () => {
7073
);
7174
expect(environment).toEqual({
7275
PATH: "/bin",
76+
T3CODE_HOME: "/home/user/.t3",
7377
T3CODE_DESKTOP: "not-prefixed",
7478
ANTHROPIC_API_KEY: "test-key",
7579
});

‎packages/provider-core/src/server/providerSessionEnvironment.fork.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,22 @@ export function withProviderSessionIdentity(
4141
}
4242

4343
/**
44-
* Removes inherited session identity and desktop launcher settings once at server
45-
* start. Providers (including in-process SDKs) and terminals inherit this environment:
46-
* none should name a parent thread or receive desktop placement and CDP settings.
47-
* Electron keeps its own launcher environment in its separate process.
44+
* The server's own runtime settings, which a service unit may pass as env.
45+
* A dev runner a child starts would otherwise reuse the live server's port.
46+
*/
47+
const SERVER_RUNTIME_ENV = ["T3CODE_PORT", "T3CODE_HOST", "T3CODE_MODE", "T3CODE_NO_BROWSER"];
48+
49+
/**
50+
* Removes inherited session identity, server runtime settings, and desktop launcher settings
51+
* once the server config is resolved. Providers, including in-process SDKs, and terminals inherit
52+
* this environment; none should name a parent thread, target this server's port, or receive
53+
* desktop placement and CDP settings.
4854
*/
4955
export const stripInheritedProviderEnvironment = Effect.gen(function* () {
5056
const environment = yield* HostProcess.Environment;
5157
delete environment[PROVIDER_SESSION_IDENTITY_ENV.projectId];
5258
delete environment[PROVIDER_SESSION_IDENTITY_ENV.threadId];
59+
for (const key of SERVER_RUNTIME_ENV) delete environment[key];
5360
for (const key of Object.keys(environment)) {
5461
if (key.toUpperCase().startsWith("T3CODE_DESKTOP_")) {
5562
delete environment[key];

0 commit comments

Comments
 (0)