Skip to content

fix(updater): detect the running app after its executable is replaced - #1706

Merged
ilysenko merged 2 commits into
ilysenko:mainfrom
thejesh23:fix/updater-liveness-deleted-exe
Nov 21, 2026
Merged

ilysenko merged 2 commits into
ilysenko:mainfrom
thejesh23:fix/updater-liveness-deleted-exe

Conversation

@thejesh23

@thejesh23 thejesh23 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

liveness::is_app_running is the guard that keeps the updater from installing or rolling back while ChatGPT Community is open. It checks each /proc/<pid>/exe link with a strict equality against /opt/codex-desktop/ChatGPT (updater/src/liveness.rs:34-39):

read_exe_link(pid)
    .map(|path| path == expected)

When a package transaction replaces /opt/codex-desktop/ChatGPT while the app is running, the running process keeps the old, now-unlinked image, and the kernel reports its link as /opt/codex-desktop/ChatGPT (deleted). That never equals the expected path, so is_app_running returns false for an app that is still open. This happens, for example, after installing a package by hand (apt install ./codex-desktop_*.deb, rpm -U, pacman -U) with the app open.

All callers of the guard then act as if the app were closed:

  • rollback.rs:184: codex-update-manager rollback goes ahead and installs the rollback package over the running app instead of printing "Close it before rollback".
  • app.rs:178 / app.rs:694: a pending update goes straight to the privileged install instead of waiting for the app to exit.
  • app.rs:934: diagnose --json reports "appRunning": false.

The crate already handles this kernel suffix for its own binary: restart.rs:17 uses install::strip_deleted_path_suffix(&link_target).unwrap_or(link_target). This PR applies the same helper in liveness.rs, in a small exe_link_matches function. A link only matches if it is the expected path, or the expected path followed by exactly one (deleted). Other paths, other (deleted) paths and prefix collisions such as ChatGPT-helper (deleted) still do not match.

This is the liveness half of #1315, which was closed during the move to the official Linux package with an invitation to refresh it if still needed. The strict comparison is still on current main (04840e9), so this is a refreshed, standalone version of that part. The read-aloud half of #1315 is not included.

Affected formats/features: the updater only (codex-update-manager), the same on every package format and architecture. No launcher, packaging or ASAR change.

Validation

  • Regression tests added in updater/src/liveness.rs:
    • running_app_is_still_detected_after_its_executable_is_replaced copies /bin/sleep to a temp ChatGPT (through a cp child process, so the test runner never holds a writable descriptor for it, the same reason as fix(updater): prevent ETXTBSY in executable test fixtures #1588), starts it, unlinks it, checks that /proc/<pid>/exe really ends in (deleted), and asserts process_matches still finds the process.
    • replaced_executable_of_another_path_is_not_mistaken_for_the_app covers the exact path, the deleted path, a deleted path in another directory, a ChatGPT-helper (deleted) prefix collision, and a doubled suffix.
  • The tests fail without the fix. On ubuntu-latest with stable Rust 1.100.0 (the CI toolchain), using the same tests and the old path == expected comparison: both new tests fail (assertion failed: still_detected and assertion failed: exe_link_matches(Path::new("/opt/codex-desktop/ChatGPT (deleted)"), expected)), and the other 131 tests pass. The (deleted) assertion before still_detected passes there, so the kernel behavior is confirmed on a real Linux runner.
  • With the fix, on the same runner: cargo test -p codex-update-manager passes all 133 tests, and cargo clippy -p codex-update-manager -- -D warnings (the CI command), the same with --all-targets, and cargo fmt -p codex-update-manager --check are all clean.
  • I ran the old and new comparison side by side on 11 link values (exact path, deleted path, trailing slash, double slash, other directory, prefix collision, doubled suffix, ChatGPT(deleted) without a space, bare (deleted), empty, an unrelated binary). Only /opt/codex-desktop/ChatGPT (deleted) changes, from no match to match.
  • cargo fmt -p codex-update-manager --check is clean. I could not build the updater locally because the host is macOS (notify_rust::Notification::hint is Linux-only), so the Linux results above come from GitHub Actions on my fork.
  • This PR's CI: rust and source-and-node pass. signed-baseline, dock-icon-feature-alone, official-linux-gate and nix-build fail for a reason unrelated to this change. The official package moved to 26.1117.41037, so feature:ui-tweaks:reasoning-effort-labels-english reports Expected one Simplified Chinese locale loader, found 0, and the Nix package pin is out of date. Other open PRs fail the same way, and Fix three Linux feature patches for signed 26.1117 #1705 addresses that drift. This PR only changes updater/src/liveness.rs.
  • Not tested: a live end-to-end run (open the app, replace the package, then run rollback). The test above reproduces the same kernel state with a stand-in binary.

Checklist

  • This pull request is ready for review and is no longer a draft.
  • I followed CONTRIBUTING.md, kept the change focused, edited source files rather than generated output, and removed unrelated changes.
  • If this fixes upstream drift, it targets only the latest signed stable OpenAI Linux package and removes obsolete fallback code and tests. (Not drift. This is an updater bug, not tied to any package version.)
  • I added or updated relevant tests, ran the validation listed above, and confirmed that required CI checks pass. (Tests added and run as listed above. rust and source-and-node pass here. The package-build jobs fail because of the unrelated 26.1117 drift described above.)
  • I reviewed the final diff with my coding agent using maximum reasoning effort, addressed all findings, and reran the relevant tests. (The coding agent that wrote the change reviewed the diff, but not at maximum reasoning effort.)

🤖 Generated with Claude Code

@ilysenko ilysenko left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the focused fix. Reusing install::strip_deleted_path_suffix keeps the liveness guard consistent with restart.rs, the change only makes the guard stricter, and the tests cover both the real kernel (deleted) link and the false-match cases. The failing package/Nix jobs came from the 26.1117 drift that #1708 fixed on main; I updated the branch and the full CI is green on the new head. Approving.

@ilysenko
ilysenko merged commit 2fd3d3d into ilysenko:main Nov 21, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants