Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(terminal): strip AppImage runtime env from spawned terminals #3108

Mergedleorivastech(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/3108/headmerged by juliusmarminge View on GitHub

If you build T3 Code as a Linux AppImage and open the integrated terminal, the terminal ends up carrying the AppImage's own environment around. AppImage mounts the app under a temp dir like /tmp/.mount_T3-XXXX and sets APPIMAGE, APPDIR, ARGV0 and OWD, and it also prepends that mount onto PATH and LD_LIBRARY_PATH. Electron inherits all of that, the backend inherits it from Electron, and the terminal inherits it from the backend, so it leaks the whole way down into your shell.

The tricky part is that everything looks fine until something actually reads those variables. The case from the issue: type php reports /usr/bin/php like you'd expect, but php -r 'echo PHP_BINARY;' prints the AppImage path instead, and PATH still has the /tmp/.mount_T3-... entries in it. Anything that trusts ARGV0 or those paths gets the wrong answer.

So when we build the environment for a terminal session I strip the AppImage bits back out: drop the APPIMAGE/APPDIR/ARGV0/OWD markers, and remove just the mount segments from PATH and LD_LIBRARY_PATH while leaving the user's real entries alone. It only runs when we're actually launched from an AppImage, so a normal install isn't touched and someone's own LD_LIBRARY_PATH is never stripped.

I kept this in createTerminalSpawnEnv, right next to the env blocklist that's already there, since that's the one place the terminal environment gets curated. I scoped it to the terminal on purpose rather than scrubbing higher up, since that's what the issue is about and touching the shared backend env would also affect the agent CLIs.

Two tests come with it: one feeds in a fake AppImage environment and checks the markers and mount paths are gone while unrelated vars survive, and one checks that without an AppImage nothing changes at all.

Fixes #1699


Note

Low Risk Change is limited to terminal PTY spawn env curation behind AppImage detection, with unit tests; server-wide env and non-AppImage sessions are unaffected.

Overview Fixes integrated terminals on Linux AppImage builds inheriting the AppImage mount environment (APPIMAGE, APPDIR, ARGV0, OWD, and mount segments on PATH / LD_LIBRARY_PATH), which could make tools resolve against the temporary mount instead of the user's real install.

createTerminalSpawnEnv now runs stripAppImageRuntimeEnv after the existing blocklist: marker vars are dropped, path-like vars keep only segments outside APPDIR, and the scrub runs only when APPIMAGE or APPDIR is present so normal installs (including a standalone OWD) are unchanged.

Tests cover a fake AppImage env and a non-AppImage case.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 95d7c70baeb57ae035ece7c3e24cfe2025237df2. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Strip AppImage runtime env variables from spawned terminals

  • Adds stripAppImageRuntimeEnv in Manager.ts that removes APPIMAGE, APPDIR, ARGV0, and OWD from the terminal spawn environment when the process was launched from an AppImage.
  • Filters PATH and LD_LIBRARY_PATH to remove any segments equal to or nested under the AppImage mount dir (APPDIR), deleting the variable entirely if no segments remain.
  • createTerminalSpawnEnv now pipes its output through stripAppImageRuntimeEnv before returning; environments without APPIMAGE or APPDIR are passed through unchanged.
  • Behavioral Change: terminals spawned from an AppImage build will no longer inherit AppImage-specific env vars or mount paths.
Macroscope summarized 95d7c70.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      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: 7d48fac0-4b2e-4612-9790-eb90fdc05a7b

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Approvability

      Verdict: Approved

      Self-contained bug fix that strips AppImage runtime environment variables from spawned terminals to prevent tools from resolving against AppImage mounts. The change is defensively gated (only activates in AppImage context), well-documented, and includes comprehensive test coverage.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. juliusmarminge approved these changes

    5. juliusmarminge merged this1047dac

    6. juliusmarminge closed this

Sign in to join this conversation.