Skip to content

fix(linux): keep extracted AppImage copies that something still runs from - #28002

Merged
OrcaWin merged 2 commits into
mainfrom
fix/appimage-generation-namespace-lease
Oct 12, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
fix/appimage-generation-namespace-lease

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​421 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​421
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​449 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​437

ELI5

On Linux, the AppImage version of Orca unpacks itself once into ~/.cache/orca/appimage so that the orca command, orca serve and the terminal daemon can run from files that stay put. Old Orca builds tidy that folder by deleting every unpacked copy except their own, even a copy that a newer Orca is still running from. This PR moves new copies to a folder that old builds never tidy. New builds now only delete a copy once they can prove nothing is running from it.

What Changed

  • Before: the cache folder for an AppImage is sha256(AppImage path). Any build that registers the CLI or starts serve deletes every other copy in that folder, apart from the one the installed link points at. If something is running from a deleted copy, it crashes the next time it loads a file.
  • After:
    • New builds put their copies in a folder whose name also includes a layout version. Old builds only clean the folder their own copy is in, so they never look in the new one.
    • Before deleting a copy, a new build checks two things, and keeps the copy if either fails:
      1. No process of this user has its program file in the copy. This reads /proc/<pid>/exe.
      2. No lease names a live process. When the desktop app, serve or the terminal daemon runs from a copy, it writes a small lease file to <cache>/leases. The lease records the process's pid, its start time (Linux start ticks) and the boot id. A different start time means the pid was reused. A different boot id means the machine rebooted. Either one makes the lease stale, and the pruner deletes it.
    • If /proc or a lease holder cannot be read, the copy is kept.
    • New builds still clear idle copies that old builds left in the old folder for the same AppImage path, so an update does not leave about 500 MB behind. Those copies go through the same checks.
    • An installed link that points into the old folder for the same AppImage path now counts as this AppImage's own, not another AppImage's. So removing or re-registering the CLI after an update works as before.
  • Documented in docs/reference/appimage-extraction-cache.md, including what remains exposed. If you roll back to a pre-change build, it can still delete copies in the old folder, which only pre-change builds create. It cannot reach the new one.
  • The packaging CI check headless-serve-shutdown, which runs extract-and-run serve in a container, now asserts that the real AppImage registers its CLI copy outside the old folder.

Why

  • Making the new pruner smarter cannot stop old pruners that are already installed. An old build can be run again months later, from the same path. Only moving the folder takes new copies out of their reach.
  • For "is anything running from it", /proc is the ground truth for this user's processes. It also covers short CLI runs and anything started by older builds. The lease adds a record that does not depend on /proc visibility, with the start time recorded, as the design asked for.
  • An existing lock already serializes extraction and pruning, so no new lock is needed.
  • Alternatives considered:
    • Pin files written inside each copy: they protect nothing that started before the pins existed, and they are deleted along with the copy.
    • Time-based grace: it cannot prove that nobody uses the copy.

macOS, Windows, and Linux .deb/.rpm are unchanged. Every new path checks that it is on Linux and that the program runs from <cache>/<key>/<key>/orca-ide, and returns early otherwise.

Linked Issue

Part of #17322: it protects copies that are in use from being pruned. Extraction markers are still time-based, so #17322 stays open for that.

Visual Proof

N/A. Nothing visible changes. This only affects cache housekeeping on Linux AppImage.

Testing

  • Unit tests, written first and failing on main:
    • the namespace split;
    • a pre-change pruner that keeps its own copy never reaching the new folder;
    • the old folder for the same path counting as this AppImage's own;
    • idle legacy copies being reclaimed while resident and installed copies are kept;
    • a resident copy, including a deleted (deleted) executable, being kept;
    • lease liveness: an exited holder, a reused pid, a reboot, an unreadable holder, and an unreadable lease file;
    • on Linux CI, a real lease held by the test process keeping a copy, and a recycled-pid lease letting it go.
  • Packaging lane: the extract-and-run container asserts where the CLI copy is installed.
  • pnpm tc, oxlint, pnpm lint, pnpm run check:code-quality:changed.
  • Not covered by CI: a real desktop update or rollback against an older AppImage on a FUSE host. No CI lane exists for that journey.

Notes

  • SSH: not affected. Remote hosts run orcad from their own runtime slot, not from the AppImage cache.
  • Folder workspaces: not affected.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for screenshots (no UI)
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered
  • pnpm lint, pnpm typecheck pass locally; CI covers the rest

…from

New builds extract into a namespace that pre-lease builds never prune.
Pruners now delete a generation only when no same-user process runs from
it and no lease names a live process (pid, start ticks, boot id).

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

AppImage extraction now uses a versioned cache namespace and can resolve the prior namespace for cleanup. The code adds Linux process-residency scanning and generation leases. Pruning checks both before removing generations in current or legacy namespaces. Startup paths create leases, and tests cover namespace resolution, lease behavior, residency detection, and pruning.


Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 9f18d

On Linux AppImage installs, cache cleanup can delete an extracted copy that a running command-line process still uses if that process's details cannot be read. That process may then crash. Resolve this, or explicitly accept the tradeoff, before merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preventing deletion of extracted AppImage copies that are still in use.
Description check Passed The description is comprehensive and covers the user impact, implementation, rationale, linked issue, visual proof, testing, compatibility notes, and checklist. The omitted AI Disclosure, Review, and …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1cb9726c-930e-4594-b564-b88bfdc7c078
📥 Commits

Reviewing files that changed from the base of the PR and between 1963ac5 and 9f18d96.

📒 Files selected for processing (2)
  • src/main/cli/appimage-generation-residency.test.ts
  • src/main/cli/appimage-generation-residency.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

// Exited mid-scan: not a resident. Denied: a non-dumpable process, which /proc reports as
// root-owned and which root without CAP_SYS_PTRACE cannot read; Orca's own processes are
// dumpable and also hold leases. Anything else could hide a resident.
if (!['ENOENT', 'ESRCH', 'EACCES', 'EPERM'].some((code) => hasErrorCode(error, code))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Keep same-user permission failures unverifiable. When readExe(pid) returns EACCES or EPERM after ownerUid(pid) === uid, the scan cannot establish where that process runs. Ignoring the failure can produce exited, which permits pruning to delete the generation if lease inspection also reports exited.

  • src/main/cli/appimage-generation-residency.ts#L53-L53: record permission failures for same-user processes as unreadable; retain the existing owner check for processes reported as another user.
  • src/main/cli/appimage-generation-residency.test.ts#L53-L59: expect unverifiable for the same-user permission-error fixtures.
📍 Affects 2 files
  • src/main/cli/appimage-generation-residency.ts#L53-L53 (this comment)
  • src/main/cli/appimage-generation-residency.test.ts#L53-L59

@OrcaWin
OrcaWin merged commit 3d27142 into main Oct 12, 2026
48 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.

1 participant