Skip to content

Commit 3bb83d3

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(server): strip desktop launcher environment before providers start (#1766)
## Problem Provider children inherit desktop placement and CDP settings from the development launcher. Closes #1615 (`Closes #1615`). ## Change Scrub every `T3CODE_DESKTOP_*` key at the existing server-start environment boundary, alongside inherited session IDs. This covers adapters that re-inherit `process.env` and in-process SDKs; Electron retains its separate launcher environment. Rename the helper and update its one startup call and existing test. ```ts for (const key of Object.keys(environment)) { if (key.toUpperCase().startsWith("T3CODE_DESKTOP_")) { delete environment[key]; } } ``` ## Scope and approval Host-approved, focused fix for the existing launcher leak; no UI, wire contract, or provider-specific implementation. The initial per-provider environment patch was removed. Claim was skipped at the host's direction after this refusal; the issue remains unassigned and untriaged: ```text ✗ Error: #1615 is parentless and still Untriaged 📥, and a claim moves it off the entry Status, so Standalone 📍 would be written by nobody's judgement. Review the open trackers, projects, and slices with ghb work, then take one of the two moves: home it ghb issue edit #1615 --parent ISSUE --no-relationship — use the truthful relationship flag judge it ghb issue claim #1615 --standalone — records independence from the other open work ``` ### Close conditions - [x] **Children:** no `T3CODE_DESKTOP_*` values ## Verification - [x] Focused tests: 17 passed, 0 failed `vp test run apps/server/src/provider/providerSessionEnvironment.fork.test.ts apps/server/src/provider/providerSessionEnvironment.test.ts` → exit 0 The extended test covers current launcher keys, a future key with an empty value, case-insensitive matching, inherited session IDs, and preservation of PATH, credentials, and the non-prefix `T3CODE_DESKTOP` key. - [x] Targeted typecheck: both packages passed `vp run --filter @t3tools/provider-core --filter t3 typecheck` → exit 0 - [x] Targeted lint and formatting passed - [x] Server production bundle passed `vp run --filter t3 build:bundle` → exit 0 - [x] Fork gate: 762 script tests passed `vp run fork:ci` → exit 0 ## Grounding **Claim:** with `T3CODE_DESKTOP_*` set on the server, its terminal and provider children see none. - **Build:** local `ground/wave1` `e81b07cb04` - **Contents:** heads of three wave-1 PRs - **Server env:** two `T3CODE_DESKTOP_*` probe keys - **Server environ:** both keys present - **Plain shell:** `PPID` is the server; 0 keys - **Claude turn:** Bash `env` reports `count=0 none` - **Provider process environ:** 0 keys ![proof-1766.png](https://github.com/user-attachments/assets/2081b493-df3f-423c-a399-e5255a864bd7) ![k1-crop.png](https://github.com/user-attachments/assets/398000c6-81fb-4ae6-a686-f5b931e605fc) **Not grounded:** Electron desktop placement and CDP debugging. No server code reads `T3CODE_DESKTOP_*`; Electron keeps its own launcher environment. Model/harness: gpt-6.1-sol / Pi. ## Fork trailers Fork-Domain: upstream-fixes Fork-Tier: bugfix Fork-Upstreamable: no Co-authored-by: donjor <[email protected]>
1 parent 545c871 commit 3bb83d3

3 files changed

Lines changed: 39 additions & 17 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Command, GlobalFlag } from "effect/cli";
77
import * as CliError from "effect/cli/CliError";
88

99
import * as ServerConfig from "../config.ts";
10-
import { stripInheritedProviderSessionIdentity } from "@t3tools/provider-core/server/providerSessionEnvironment.fork"; // fork-hook: upstream-fixes/server-inherited-session-identity-import
10+
import { stripInheritedProviderEnvironment } from "@t3tools/provider-core/server/providerSessionEnvironment.fork"; // fork-hook: upstream-fixes/server-inherited-session-identity-import
1111
import { awaitLauncherLoss } from "../launcherWatch.ts";
1212
import { runServer } from "../server.ts";
1313
import { type CliServerFlags, resolveServerConfig, sharedServerCommandFlags } from "./config.ts";
@@ -29,7 +29,7 @@ const runServerCommand = Effect.fn("server.runServerCommand")(function* (
2929
readonly rejectRunningServer?: boolean;
3030
},
3131
) {
32-
yield* stripInheritedProviderSessionIdentity; // fork-hook: upstream-fixes/server-inherited-session-identity
32+
yield* stripInheritedProviderEnvironment; // fork-hook: upstream-fixes/server-inherited-session-identity
3333
const logLevel = yield* GlobalFlag.LogLevel;
3434
const config = yield* resolveServerConfig(flags, logLevel, options);
3535
const run = runServer.pipe(Effect.provideService(ServerConfig.ServerConfig, config));

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
codexThreadIdentityConfig,
1414
providerSessionIdentity,
1515
providerSessionProjectId,
16-
stripInheritedProviderSessionIdentity,
16+
stripInheritedProviderEnvironment,
1717
withoutProviderSessionIdentity,
1818
withSessionIdentityWhenKnown,
1919
withThreadProjects,
@@ -48,15 +48,32 @@ describe("provider session identity helpers", () => {
4848
});
4949
});
5050

51-
describe("stripInheritedProviderSessionIdentity", () => {
52-
it.effect("drops the launcher's ids from the server's own environment", () =>
53-
Effect.gen(function* () {
54-
const environment: NodeJS.ProcessEnv = { ...leaked };
55-
yield* stripInheritedProviderSessionIdentity.pipe(
56-
Effect.provideService(HostProcess.Environment, environment),
57-
);
58-
expect(environment).toEqual({ PATH: "/bin" });
59-
}),
51+
describe("stripInheritedProviderEnvironment", () => {
52+
it.effect(
53+
"drops inherited session ids and desktop launcher settings from the server environment",
54+
() =>
55+
Effect.gen(function* () {
56+
const environment: NodeJS.ProcessEnv = {
57+
...leaked,
58+
T3CODE_DESKTOP_AGENT_WORKSPACE: "agent-workspace",
59+
T3CODE_DESKTOP_AGENT_PLACEMENT_TITLE: "placement",
60+
T3CODE_DESKTOP_REMOTE_DEBUGGING_PORT: "9222",
61+
T3CODE_DESKTOP_USER_DATA_DIR: "/desktop/data",
62+
T3CODE_DESKTOP_DEVTOOLS: "0",
63+
T3CODE_DESKTOP_FUTURE_FLAG: "",
64+
t3code_desktop_windows_case: "1",
65+
T3CODE_DESKTOP: "not-prefixed",
66+
ANTHROPIC_API_KEY: "test-key",
67+
};
68+
yield* stripInheritedProviderEnvironment.pipe(
69+
Effect.provideService(HostProcess.Environment, environment),
70+
);
71+
expect(environment).toEqual({
72+
PATH: "/bin",
73+
T3CODE_DESKTOP: "not-prefixed",
74+
ANTHROPIC_API_KEY: "test-key",
75+
});
76+
}),
6077
);
6178
});
6279

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

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

4343
/**
44-
* Removes the session identity the server inherited from whatever launched it,
45-
* such as a shell inside another T3-hosted agent. Run once at server start:
46-
* in-process providers (the Cursor SDK) and terminals spawn from the server's
47-
* own environment, and would otherwise name that other thread as theirs.
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.
4848
*/
49-
export const stripInheritedProviderSessionIdentity = Effect.gen(function* () {
49+
export const stripInheritedProviderEnvironment = Effect.gen(function* () {
5050
const environment = yield* HostProcess.Environment;
5151
delete environment[PROVIDER_SESSION_IDENTITY_ENV.projectId];
5252
delete environment[PROVIDER_SESSION_IDENTITY_ENV.threadId];
53+
for (const key of Object.keys(environment)) {
54+
if (key.toUpperCase().startsWith("T3CODE_DESKTOP_")) {
55+
delete environment[key];
56+
}
57+
}
5358
});
5459

5560
/** Environment for a process every thread of an instance shares. */

0 commit comments

Comments
 (0)