[Bug]: Provider agent sessions inherit ELECTRON_RUN_AS_NODE=1 on macOS, so Electron apps launched from agent shells run as Node and exit #26966
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- On macOS, start a Claude (or Codex) thread in the desktop app.
- Ask the agent to run
echo $ELECTRON_RUN_AS_NODEwith its shell tool. It prints1. - Ask it to launch any Electron app from that shell, for example
/Applications/Slack.app/Contents/MacOS/Slack --remote-debugging-port=9222.
Expected behavior#
Agent shells don't have ELECTRON_RUN_AS_NODE, so an Electron app launched from one opens normally.
Actual behavior#
The Electron app starts as plain Node and exits without opening a window. Agents that drive desktop apps over CDP (Slack, VS Code, Discord, etc.) can't start them.
The desktop app starts the server with ELECTRON_RUN_AS_NODE=1 on purpose (apps/desktop/src/backend/DesktopBackendConfiguration.ts), and mergeProviderInstanceEnvironment passes it through unchanged to provider sessions, so every tool shell inherits it. The integrated terminal (TERMINAL_ENV_BLOCKLIST in apps/server/src/terminal/Manager.ts) and the external launcher (#20206) already drop it; provider sessions are the remaining path.
This is the provider-session part of #16456, which was closed with a request for a new issue covering only that part. It isn't Linux-specific: the same leak happens on macOS without any AppImage variables.
#16679 (maintainer takeover) fixes this: its mergeProviderInstanceEnvironment deletes ELECTRON_RUN_AS_NODE on every platform before applying provider overrides, and Claude, Codex, Grok, Antigravity and the ACP registry adapters all build their session environment through it. T3's own helpers that need Node mode (agent-device wrappers since #18301, the Claude history worker, document text extraction) set the variable themselves, so they're unaffected.
Impact#
Major degradation or frequent failure
Version or commit#
T3 Code (Nightly) 0.1.5-nightly.20261029.3877; code references are upstream/main at 20497e4890.
Environment#
macOS 27 (Apple Silicon), desktop app, Claude provider. Same code path for Codex.
Logs or stack traces#
$ echo "ELECTRON_RUN_AS_NODE=${ELECTRON_RUN_AS_NODE-<unset>}" # inside a Claude agent's Bash tool
ELECTRON_RUN_AS_NODE=1
Workaround#
Prefix the launch with env -u ELECTRON_RUN_AS_NODE, or unset ELECTRON_RUN_AS_NODE in the agent's shell first.
tanstack-source added labelsbug
Even after
#16679(and the follow-up branch above) stops inheritingELECTRON_RUN_AS_NODE=1from the desktop app, Antigravity sessions will still exportELECTRON_RUN_AS_NODE=1on every platform — including headless Linuxt3 serve.Why:
apps/server/src/provider/antigravityAuthSupport.ts:241setsELECTRON_RUN_AS_NODE: "1"unconditionally inantigravityEnvironment(), which runs aftermergeProviderInstanceEnvironment().Impact: Any Electron or CEF app launched from an Antigravity agent shell runs as plain Node (or aborts) instead of starting normally, even when T3 Code is running as standalone
t3 serveandBROWSERis not an Electron binary.Suggested fix: Remove
ELECTRON_RUN_AS_NODE: "1"fromantigravityEnvironment(). If theBROWSERauth helper needs it when T3 runs inside packaged Electron, setELECTRON_RUN_AS_NODE=1only inside a small wrapper for that helper (the same pattern proposed above for Codex'smanaged-token), rather than exporting it intoagyand every child shell it spawns.Hit this exact Antigravity case on macOS (Apple Silicon) with T3 Code Nightly
0.1.14-nightly.20261128.5372(9ceb8bfb), and it has an even nastier transitive blast radius than directly launching an Electron app from an agent shell:- Because
antigravityEnvironment()exportsELECTRON_RUN_AS_NODE=1into the Antigravity ACP process and its tool shells, any/usr/bin/open -a <App>run by the agent passesELECTRON_RUN_AS_NODE=1via LaunchServices into non-Electron resident apps too (e.g., an app launcher like Tinycast, or menu-bar tools like SwiftBar). - Those non-Electron apps keep running normally, so the leaked env var goes completely unnoticed—until you later launch an Electron app (such as VS Code
1.148.0/Electron 43.8.10) from that launcher. - VS Code inherits
ELECTRON_RUN_AS_NODE=1, takes theRunAsNodepath instead of_ElectronMain, logs[ERROR:electron/shell/common/mac/codesign_util.cc:79] task_name_for_pid: (os/kern) failure (5), and exits cleanly in ~20ms (termination reported by launchd (0, 0, 0)) with no window, no crash report, and no~/Library/Application Support/Codecreated. - Quitting and relaunching the launcher outside T3 Code removes
ELECTRON_RUN_AS_NODEand immediately restores VS Code.
Strong +1 to @viktortar98's suggestion above: in addition to #35447 stripping inherited
ELECTRON_RUN_AS_NODEinmergeProviderInstanceEnvironment(), please also remove the unconditionalELECTRON_RUN_AS_NODE: "1"fromantigravityEnvironment()and scope it strictly to a wrapper for theBROWSERauth helper when running inside packaged Electron.- Because
Sign in to join this conversation.
#16679 is the right general fix for the agent-shell part of this issue, but on its own it breaks managed Codex in packaged desktop builds. One extra change fixes that. I tested all three builds end to end in a Linux VM.
Why #16679 isn't enough on its own. It drops
ELECTRON_RUN_AS_NODEinmergeProviderInstanceEnvironment, so Claude, Codex, ACP and terminal shells all lose it in one place. But managed Codex configures T3's own binary as Codex's token command (__managed-chatgpt-token, seemanagedCodexLaunchArgsinCodexManagedRuntime.ts). That command only runs as Node because it inherits the variable through Codex. With the variable removed, the desktop's Electron binary starts as an app, and every managed Codex turn fails:The extra change. When the server itself is running in Node mode, point Codex's token command at a small launcher,
<stateDir>/codex/bin/managed-token, that setsELECTRON_RUN_AS_NODE=1for that one command. Codex's providerauthconfig has noenvfield, so a launcher is needed. Branch: https://github.com/ajbarryiii/t3code/tree/fix/electron-run-as-node-everywhere (changes on top of #16679 + main: https://github.com/ajbarryiii/t3code/compare/d5ea7ee842...fix/electron-run-as-node-everywhere)It is main merged into #16679 (three small conflicts), then the launcher (with
%and code-page handling for the Windows.cmd, as inDesktopCliShim). Two probes that main added after #16679 re-merged the server's environment, so the merge also needed small fixes: the Codex--versionfallback (extendEnv: true) and the configured npm version lookup. It also gives the ACP child-environment test theSecureRandomservice that main now requires. TheCodexManagedRuntime.test.tstable gains an Electron-hosted row: a fake Electron that acts as Node only when the variable is set. That row runs the real token helper with Codex's environment; it fails without the launcher (exit 9) and passes with it.I checked the other places T3 starts its own binary from inside a provider: the ACP and Claude MCP bridges, document text, device tools and the
t3CLI shim. Each setsELECTRON_RUN_AS_NODEexplicitly, so the token command is the only one that relied on inheriting it.VM evidence. Ubuntu 24.04, unsigned packaged AppImages built in CI order from main
61c3794c32, #16679 merged with main, and the branch. Real Claude (Haiku) and managed Codex (Luna) turns ran a probe from the agent's own shell. The probe prints the variable, then launches a stock Electron 44.10.0 app with--no-sandbox.ELECTRON_RUN_AS_NODE=1; Electron:bad option: --no-sandbox, exit 9=1; Electron exit 9In all three builds, the
t3CLI ran from the agent shells and opened no second window. Transcripts, process environments and the launcher file: https://gist.github.com/ajbarryiii/1db56828302085411f41f72c8d89bcf4Not covered: Windows (the
.cmdlauncher is untested), macOS, and ACP agents in the VM (#16679's real-child test covers ACP). #29413 fixes only the Claude path, and this covers it too.Once this is triaged, I can open a PR to main with #16679's commits plus these, or target #16679's branch, whichever you prefer.