Skip to content
Source
Sign inSign up
pingdotgg/t3code

[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

Opendavisonio(GitHub profile, opens in a new tab) opened this issue 3 comments

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

  1. On macOS, start a Claude (or Codex) thread in the desktop app.
  2. Ask the agent to run echo $ELECTRON_RUN_AS_NODE with its shell tool. It prints 1.
  3. 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.

  1. #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_NODE in mergeProviderInstanceEnvironment, 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, see managedCodexLaunchArgs in CodexManagedRuntime.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:

    provider auth command `/tmp/.mount_T3-CodFpNAci/t3code` exited with status exit status: 130

    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 sets ELECTRON_RUN_AS_NODE=1 for that one command. Codex's provider auth config has no env field, 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 in DesktopCliShim). Two probes that main added after #16679 re-merged the server's environment, so the merge also needed small fixes: the Codex --version fallback (extendEnv: true) and the configured npm version lookup. It also gives the ACP child-environment test the SecureRandom service that main now requires. The CodexManagedRuntime.test.ts table 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 t3 CLI shim. Each sets ELECTRON_RUN_AS_NODE explicitly, 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.

    BuildClaude agent shellManaged Codex
    mainELECTRON_RUN_AS_NODE=1; Electron: bad option: --no-sandbox, exit 9turn works; shell has =1; Electron exit 9
    #16679 + mainunset; Electron app startsturn fails: auth command exit 130
    branchunset; Electron app startsturn works; shell unset; Electron app starts

    In all three builds, the t3 CLI ran from the agent shells and opened no second window. Transcripts, process environments and the launcher file: https://gist.github.com/ajbarryiii/1db56828302085411f41f72c8d89bcf4

    Not covered: Windows (the .cmd launcher 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.

  2. tanstack-source added labelsbug

  3. Even after #16679 (and the follow-up branch above) stops inheriting ELECTRON_RUN_AS_NODE=1 from the desktop app, Antigravity sessions will still export ELECTRON_RUN_AS_NODE=1 on every platform — including headless Linux t3 serve.

    Why: apps/server/src/provider/antigravityAuthSupport.ts:241 sets ELECTRON_RUN_AS_NODE: "1" unconditionally in antigravityEnvironment(), which runs after mergeProviderInstanceEnvironment().

    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 serve and BROWSER is not an Electron binary.

    Suggested fix: Remove ELECTRON_RUN_AS_NODE: "1" from antigravityEnvironment(). If the BROWSER auth helper needs it when T3 runs inside packaged Electron, set ELECTRON_RUN_AS_NODE=1 only inside a small wrapper for that helper (the same pattern proposed above for Codex's managed-token), rather than exporting it into agy and every child shell it spawns.

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

    1. Because antigravityEnvironment() exports ELECTRON_RUN_AS_NODE=1 into the Antigravity ACP process and its tool shells, any /usr/bin/open -a <App> run by the agent passes ELECTRON_RUN_AS_NODE=1 via LaunchServices into non-Electron resident apps too (e.g., an app launcher like Tinycast, or menu-bar tools like SwiftBar).
    2. 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.
    3. VS Code inherits ELECTRON_RUN_AS_NODE=1, takes the RunAsNode path 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/Code created.
    4. Quitting and relaunching the launcher outside T3 Code removes ELECTRON_RUN_AS_NODE and immediately restores VS Code.

    Strong +1 to @viktortar98's suggestion above: in addition to #35447 stripping inherited ELECTRON_RUN_AS_NODE in mergeProviderInstanceEnvironment(), please also remove the unconditional ELECTRON_RUN_AS_NODE: "1" from antigravityEnvironment() and scope it strictly to a wrapper for the BROWSER auth helper when running inside packaged Electron.

Sign in to join this conversation.