Skip to content

[Bug]: Linux AppImage integrated terminal leaks AppImage runtime env into PTY sessions, causing incorrect PHP_BINARY #1699

@ncbraner

Description

@ncbraner

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

Summary

On Linux AppImage builds, T3 Code's integrated terminal can inherit
AppImage runtime state into PTY sessions.

This creates a mismatch where shell command resolution looks correct, but
process metadata inside launched programs is wrong. In particular, php
resolves from /usr/bin/php, while PHP_BINARY inside the PHP process
reports the AppImage path instead of the real PHP binary.

Environment

  • Host OS: Linux
  • App packaging: AppImage
  • App: T3 Code desktop build
  • Shell inside terminal: zsh

Reproduction

Run these inside the T3 integrated terminal:

type php
php -r 'echo PHP_BINARY, PHP_EOL;'
env | grep -E '^(APPIMAGE|APPDIR|OWD|ARGV0|LD_LIBRARY_PATH)='
printf '%s\n' "$PATH"

Expected

  • type php reports the real PHP binary path, for example /usr/bin/php
  • php -r 'echo PHP_BINARY, PHP_EOL;' prints the real PHP binary path
  • AppImage runtime variables such as APPIMAGE, APPDIR, OWD, and
    ARGV0 are not present in the terminal session
  • PATH does not contain AppImage mount paths such as
    /tmp/.mount_T3-...

Actual

In the broken AppImage build:

  • type php reported /usr/bin/php
  • php -r 'echo PHP_BINARY, PHP_EOL;' printed
    /home/{user}/T3-Code.AppImage
  • PATH contained AppImage mount paths such as /tmp/.mount_T3-...

Example observed output from the broken build:

php is /usr/bin/php
/home/{user}/T3-Code.AppImage
...
/home/{user}/.bun/bin:...:/usr/bin:/tmp/.mount_T3-Cod...:/tmp/.mount_T3-Cod.../usr/sbin:...

Impact

This creates a subtle but real mismatch between shell resolution and
runtime process metadata inside the integrated terminal.

Root Cause

Source tracing showed:

  • the desktop app launches the backend process from Electron main
  • the backend inherits the AppImage runtime environment
  • the terminal/PTTY layer clones that environment into PTY sessions
  • AppImage-specific runtime variables and mount-derived path entries were
    not sanitized before spawning the terminal shell

So the terminal was not launching php directly as the AppImage. The
problem was leaked AppImage runtime environment contaminating terminal
child processes.

Relevant Code Paths

  • apps/desktop/src/main.ts
  • apps/server/src/terminal/Layers/Manager.ts
  • apps/server/src/terminal/Layers/NodePTY.ts
  • packages/shared/src/shell.ts

Proposed Fix

Sanitize AppImage runtime state before PTY shell spawn on Linux:

  • remove APPIMAGE
  • remove APPDIR
  • remove OWD
  • remove ARGV0
  • strip AppImage mount entries like /tmp/.mount_* from PATH
  • strip AppImage mount entries like /tmp/.mount_* from
    LD_LIBRARY_PATH

Also apply the same sanitization when hydrating PATH from the login
shell.

Validation After Fix

In the fixed build:

  • type php -> /usr/bin/php
  • PHP_BINARY -> real PHP binary, for example /usr/bin/php8.5
  • no /tmp/.mount_T3-... entries in PATH
  • no APPIMAGE, APPDIR, OWD, or ARGV0 in terminal environment

Notes

  • We already have a fix locally and can push code if needed.

Expected behavior

Expected

  • type php reports the real PHP binary path, for example /usr/bin/php
  • php -r 'echo PHP_BINARY, PHP_EOL;' prints the real PHP binary path
  • AppImage runtime variables such as APPIMAGE, APPDIR, OWD, and
    ARGV0 are not present in the terminal session
  • PATH does not contain AppImage mount paths such as
    /tmp/.mount_T3-...

Actual behavior

Actual

In the broken AppImage build:

  • type php reported /usr/bin/php
  • php -r 'echo PHP_BINARY, PHP_EOL;' printed
    /home/{user}/T3-Code.AppImage
  • PATH contained AppImage mount paths such as /tmp/.mount_T3-...

Impact

Major degradation or frequent failure

Version or commit

latest

Environment

Linux

Logs or stack traces

Screenshots, recordings, or supporting files

No response

Workaround

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken or behaving incorrectly.needs-triageIssue needs maintainer review and initial categorization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions