Skip to content

fix(linux): land the reviewed Linux packaging stack on main - #18100

Merged
nwparker merged 50 commits into
mainfrom
nwparker/linux-orcad-restart-safety
Sep 2, 2026
Merged

nwparker merged 50 commits into
mainfrom
nwparker/linux-orcad-restart-safety

Conversation

@nwparker

@nwparker nwparker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

The nine-PR Linux packaging stack is all reviewed and merged — but each PR merged into the branch below it, and only the first one (#15081) ever reached main. So the remaining work is sitting in a chain of branches with nothing pointing it at main. This PR is that pointer.

Since the stack was cut, main landed refactor(main): split backend services and startup, which broke src/main/updater.ts (2229 lines) into a 94-line facade plus 12 modules under src/main/updater/, and moved the pre-ready startup phase out of src/main/index.ts into src/main/startup/main-process-preflight.ts. The stack edited the monoliths. This PR therefore ports the stack onto that refactor rather than merging against it.

What this lands

PR Change
#15083 Packaged CLI commands no longer fall through to a Chromium start
#15084 A usable display is proven before Chromium initialises (X11 filesystem + abstract-namespace sockets, Wayland incl. WAYLAND_SOCKET, Xvfb ownership)
#15085 Packaged 8-case CLI launch contract, plus an ELF architecture gate
#17319 AppImage runtime must be a static PIE
#17318 deb/rpm update installs move outside Orca
#17320 orcad update restart-safety docs
#17683 Serve options validated before startup
#17918 Updates a distro-managed install cannot apply are no longer offered (#17702)

How the merge was resolved

32 conflict hunks across 12 files.

Structural files — took main's side, then re-applied the stack's behaviour into the new modules:

  • src/main/updater.ts — took main's 94-line facade. All of the stack's updater.ts behaviour was re-applied inside src/main/updater/:
    • remote-support gate → updater-remote-status.ts (deb/rpm/unusable now also yield automatic: false, reason: 'manual-service-update-required')
    • quitAndInstall refusal → updater-install-execution.ts (hard return for deb/rpm before any install, updater:quitAndInstallAborted to the renderer, lifecycle event; unusable additionally sends LINUX_PACKAGE_MARKER_UNUSABLE_MESSAGE)
    • externally-managed download gate → updater-download-install.ts (clearAvailableUpdateContext() and restoreReleaseUpdateSource() before the error status, and no recovery object)
    • autoInstallOnAppQuit → updater-setup.ts, gated to getLinuxPackageType() === 'non-root'
    • retained manual-install card survives a settled check → sendSettledCheckStatus in updater-check-state.ts, used from updater-check-failure.ts, updater-menu-checks.ts, updater-build-selection.ts
    • recovery-action currency checks and shell.showItemInFolder → updater-package-recovery.ts
    • dead deb/rpm install-failure machinery (proveRetainedLinuxPackage, buildLinuxPackageInstallFailureStatus, install-stderr capture) removed, as on the stack — it is unreachable once the gate hard-returns
  • src/main/index.ts — took main's 115-line entrypoint; the stack's four pre-ready changes moved into src/main/startup/main-process-preflight.ts (single maybeRedirectCliLaunch, packaged non-serve display gate, serve Xvfb gate)
  • src/main/startup/main-process-serve.ts — now re-exports the validated getServeOptions from src/main/startup/serve-options.ts (fix(serve): validate in-process serve options before startup #17683) instead of carrying its own unvalidated copy

src/main/startup/appimage-cli-redirect.{ts,test.ts} (delete/modify): accepted the delete. main added #17633 (keep serve in Electron when --disable-features precedes it) to a file this stack deletes. The replacement never redirects serve at all — cli-launch-redirect.ts:121-122 — so the bug cannot occur, and serve-mode-argv-cli-redirect-order.test.ts already exercises --disable-features=Vulkan serve ….

Mechanical files: cli-installer.ts / wsl-cli-installer.ts took main's side (formatting only); cli-command-installation.ts took the stack's side (real change) and was re-formatted; the three source-text assertion tests were re-pointed at main-process-preflight.ts.

Verification

  • pnpm tc clean.
  • pnpm test src/main/cli src/main/startup src/main/updater src/main/linux-package src/cli — 2051 passed, 13 skipped, 0 failed (210 files).
  • pnpm test src/main src/shared — 37038 passed, 10 failed across 9 files, none from this change. 8 of those files pass in isolation (electron/browser-egress, codex, ssh, native-chat, rpc-fuzz and a perf assertion — all load-sensitive, and this machine runs many suites in parallel). The 9th, src/main/runtime/automation-change-publication.test.ts, fails in isolation too — but it fails identically on origin/main (same test, same 30s timeout), so it is pre-existing. No failing file is in this PR's import graph.
  • pnpm run check:code-quality:changed — 0 new findings across 103 changed files. oxlint, oxfmt --check, max-lines / ts-nocheck / runtime-electron / reliability-gate ratchets all clean.
  • Present after the port: isExternallyManagedLinuxInstall, hasAbstractXSocket, isManagedDisplayServerAlive, declaredArchFromPath, removeExtractedAppImagePayload, DESKTOP_FLAGS, hasTrustedPackageManagerFor.

Exercised on real hardware (Ubuntu 24.04 x64 and a Raspberry Pi 5 arm64) throughout the stack: the 8-case launch contract passes 8/8 on the fixed build and fails 4/8 against a pre-stack release (three at SIGTRAP), and all four display-gate directions were verified against pre-fix controls.

Merge-integration changes beyond the stack

Three small changes exist only because of the merge, not in any reviewed PR:

  • src/shared/child-process/child-process-import-boundary.test.ts and windows-console-visibility.test.ts — ratchet pins lowered 160→158 and 68→66. The stack deletes files that were offenders; the tests instruct exactly this.
  • config/scripts/windows-cmd-shim-spawn-boundary.test.mjs — build-linux-local.{mjs,test.mjs} added to the batch-shim allowlist alongside the existing build-mac-local.mjs entry, which has the identical platform === 'win32' ? 'pnpm.cmd' : 'pnpm' shape. That guard landed on main after the stack was cut.
  • serve-mode-argv-cli-redirect-order.test.ts keeps main's preflight-ordering source assertion, rewritten for the single maybeRedirectCliLaunch; the stack had dropped it when it collapsed the two redirects.

User-facing regressions

Carried forward from the individual PRs, unchanged:

Everything else in the stack is net-neutral or a fix.

Pruning removed 3215 of 3216 files from a superseded generation and always
stranded resources/app.asar, leaking ~105 MB per version update. Electron's
asar shim reports a *.asar file as a directory, so the recursive remove tried
to rmdir a real file and failed with ENOTEMPTY; the .catch(() => {}) hid it.
Reproduced end to end on Ubuntu 24.04: 519M -> 623M across one update, and
519M again once the payload is actually reclaimed.

removeExtractedAppImagePayload holds process.noAsar for the removal, counted
so overlapping removals cannot hand the shim back early, and the prune site
now warns with the path instead of swallowing the rejection. All three
removal sites use it -- staging cleanup and displaced roots leaked the same
way.

Also reclaim symlinks left by a packaged deb/rpm install, which the
extracted-cache-only rule turned into a hard conflict on a deb -> AppImage
migration, and name the remedy in the conflict error.
`retries: 1000` caps the attempt count, not elapsed time, so at up to 1s per
attempt an IPC-driven registration could hang ~16 minutes against a wedged
holder with no feedback.

A legitimate holder is bounded by the extraction timeout, so wait that plus
slack and then fail with a message naming the lock file, rather than hanging.
`maxRetryTime` is forwarded verbatim to the `retry` package by proper-lockfile.
The extracted-payload cache key hashed ctime alongside dev/ino/size/mtime.
ctime moves on any inode metadata write -- `chmod +x`, which every AppImage
user is told to run, plus `chown`, an ACL or SELinux relabel, and a backup
restore -- none of which alter a byte of the payload.

Measured on Ubuntu 24.04: `chmod +x` leaves dev, ino, size and mtime
identical and moves ctime alone, so the key changed and the next launch paid
a full ~519 MB re-extraction and a multi-second stall to rebuild a payload it
already had, then pruned the old generation.

Key on content identity instead. An in-place content change moves mtime and
almost always size; a replacement moves the inode. The existing
replace-in-place test still passes.
An X server writes its lock beside its socket and both survive a crash
(verified against Xvfb under SIGKILL), so a socket with no lock was never
left by a crashed server. It is an endpoint published from elsewhere: a
container bind-mounting only /tmp/.X11-unix, WSLg, or a foreign PID
namespace. Declaring those dead made the desktop gate exit(1) on displays
that work, with no workaround, and the serve gate refuse to start.

Liveness now splits by ownership. A foreign DISPLAY trusts a lockless
socket; Orca's own :99 does not, because removeStaleDisplayArtifacts
unlinks the lock before the socket and so manufactures that state itself --
adopting it would resurrect the orphan-socket bug and stop the cleanup from
self-healing. The stale-lock rejection is unchanged.

Also correct four doc statements this behaviour falsified.
Readiness only checked that /tmp/.X11-unix/X99 exists. A stale socket we
could not unlink still exists after our own Xvfb refused to bind, so Orca set
DISPLAY to a dead server and Chromium died in Ozone init.

Measured on Ubuntu 24.04 against the pre-fix build: with a leftover :99
socket and no lock, serve exits 139 (SIGSEGV), the socket inode is unchanged
before and after, and no lock is recreated -- it neither cleaned up nor
respawned. To a user that is a crash, not a misconfiguration.

This is reachable in the documented topology, where orca-xvfb.service has no
User= and runs as root while serve runs as User=orca: /tmp is sticky, so the
orca uid cannot unlink a root-owned socket, rmSync fails, and Xvfb exits with
the display already active.

Readiness now requires the display to actually be live -- our socket plus a
lock naming a running process -- so the same state reports an unusable
display and exits 1 with the existing diagnosis.
Two display setups this gate could not prove were refused outright, and on the
desktop path that is app.exit(1) with no workaround.

An X server may bind only the abstract namespace (`@/tmp/.X11-unix/X0`), which
leaves no filesystem socket to stat. Abstract addresses are kernel-owned and
vanish the moment the owner exits, so an entry in /proc/net/unix is proof of a
live server -- no lock file needed and no stale entry possible. Verified on
Ubuntu 24.04, where 139 such addresses were present.

WAYLAND_SOCKET is an already-connected fd handed over by the compositor, so
there is no path to stat and WAYLAND_DISPLAY may be unset entirely. Its
presence is the display.

Both are consulted only after the filesystem-socket check fails, so no
existing verdict changes.
Recognising a lockless X socket as live is correct for an endpoint published
from elsewhere -- a container bind mount, WSLg -- because an X server writes
its lock beside its socket and both survive a crash. It is wrong for
VIRTUAL_DISPLAY_NUMBER, because Orca's own teardown unlinks the lock before
the socket and so manufactures that exact state.

The managed branch was already strict, but a caller that sets DISPLAY=:99
explicitly takes the foreign path and skipped it, accepting a dead display
left by Orca's own interrupted cleanup. Route the managed number through the
strict probe on both paths.

Found by an adversarial audit of the asymmetry introduced earlier in this
branch; the documented systemd topology is unaffected because its Xvfb writes
a real lock.
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker nwparker changed the title fix(linux): land the reviewed Linux packaging stack on main (needs conflict resolution) fix(linux): land the reviewed Linux packaging stack on main Sep 2, 2026

@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: Team

Run ID: e4c07b8f-2d76-4216-9b55-cd55b93899fc

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc20cb and 9303673.

📒 Files selected for processing (130)
  • .github/workflows/pr.yml
  • config/docker/cli-launch-contract/Dockerfile
  • config/docker/cli-launch-contract/run-cli-case.sh
  • config/docker/headless-pairing/Dockerfile
  • config/docker/headless-serve-shutdown/Dockerfile
  • config/docker/headless-serve-shutdown/run-appimage-desktop-startup-case.sh
  • config/docker/headless-serve-shutdown/run-signal-case.sh
  • config/electron-builder.config.cjs
  • config/reliability-gates.jsonc
  • config/scripts/build-linux-local.mjs
  • config/scripts/build-linux-local.test.mjs
  • config/scripts/electron-builder-config.test.mjs
  • config/scripts/electron-builder-runtime-resources.test.mjs
  • config/scripts/headless-serve-shutdown-workflow.test.mjs
  • config/scripts/linux-package-maintainer-scripts.test.mjs
  • config/scripts/orcad-operations-restart-safety.test.mjs
  • config/scripts/pr-code-change-scope.mjs
  • config/scripts/pr-code-change-scope.test.mjs
  • config/scripts/pr-workflow-parallelism.test.mjs
  • config/scripts/run-headless-serve-shutdown-docker.mjs
  • config/scripts/run-linux-cli-launch-contract-docker.mjs
  • config/scripts/static-appimage-package-contract.cjs
  • config/scripts/static-appimage-package-contract.test.mjs
  • config/scripts/verify-cli-bin.mjs
  • config/scripts/verify-linux-glibc-floor.cjs
  • config/scripts/verify-linux-glibc-floor.test.mjs
  • config/scripts/windows-cmd-shim-spawn-boundary.test.mjs
  • config/tsconfig.cli.json
  • docs/reference/headless-linux-server.md
  • docs/reference/linux-glibc-compatibility.md
  • docs/reference/orcad-operations.md
  • docs/reference/ssh-execution-boundary.md
  • package.json
  • resources/linux/bin/orca-ide
  • resources/linux/packaging/after-remove.sh
  • src/cli/args.test.ts
  • src/cli/args.ts
  • src/cli/cli-command-name-parity.test.ts
  • src/cli/cli-version.test.ts
  • src/cli/cli-version.ts
  • src/cli/command-suggestion.ts
  • src/cli/handlers/core.ts
  • src/cli/index.ts
  • src/cli/runtime/launch.test.ts
  • src/cli/runtime/launch.ts
  • src/cli/runtime/serve-signal-exit-diagnostic.test.ts
  • src/cli/runtime/serve-update-supervisor.ts
  • src/cli/serve-electron-flag-parity.test.ts
  • src/main/cli/cli-command-installation.ts
  • src/main/cli/cli-installer.test.ts
  • src/main/cli/packaged-cli-assets.test.ts
  • src/main/linux-package-downloaded-status.ts
  • src/main/linux-package-install-command.test.ts
  • src/main/linux-package-install-command.ts
  • src/main/linux-package-install-diagnostic.test.ts
  • src/main/linux-package-install-diagnostic.ts
  • src/main/linux-package-update-recovery.test.ts
  • src/main/linux-package-update-recovery.ts
  • src/main/linux-update-package-type.test.ts
  • src/main/linux-update-package-type.ts
  • src/main/startup/appimage-cli-redirect.test.ts
  • src/main/startup/appimage-cli-redirect.ts
  • src/main/startup/cli-command-names.ts
  • src/main/startup/cli-launch-redirect.test.ts
  • src/main/startup/cli-launch-redirect.ts
  • src/main/startup/ensure-virtual-display.test.ts
  • src/main/startup/ensure-virtual-display.ts
  • src/main/startup/main-process-preflight.ts
  • src/main/startup/main-process-runtime-launch.ts
  • src/main/startup/main-process-serve.ts
  • src/main/startup/packaged-cli-entry-redirect.test.ts
  • src/main/startup/packaged-cli-entry-redirect.ts
  • src/main/startup/serve-mode-argv-cli-redirect-order.test.ts
  • src/main/startup/serve-mode-argv.test.ts
  • src/main/startup/serve-mode-argv.ts
  • src/main/startup/serve-options.test.ts
  • src/main/startup/serve-options.ts
  • src/main/startup/serve-signal-handlers.test.ts
  • src/main/startup/serve-signal-handlers.ts
  • src/main/startup/single-instance-lock-exit.electron.test.ts
  • src/main/updater-events.test.ts
  • src/main/updater-events.ts
  • src/main/updater-fallback.ts
  • src/main/updater-linux-package-recovery-actions.test.ts
  • src/main/updater-mac-install.ts
  • src/main/updater-test-harness.ts
  • src/main/updater.fallback.test.ts
  • src/main/updater.headless-serve-install.test.ts
  • src/main/updater.install-failure-cause.test.ts
  • src/main/updater.linux-externally-managed.test.ts
  • src/main/updater.linux-root-package-install.test.ts
  • src/main/updater.mac-install.test.ts
  • src/main/updater.quit-and-install.test.ts
  • src/main/updater.startup-scheduling.test.ts
  • src/main/updater/updater-build-selection.ts
  • src/main/updater/updater-check-failure.ts
  • src/main/updater/updater-check-state.ts
  • src/main/updater/updater-download-install.ts
  • src/main/updater/updater-install-execution.ts
  • src/main/updater/updater-install-support.ts
  • src/main/updater/updater-menu-checks.ts
  • src/main/updater/updater-package-recovery.ts
  • src/main/updater/updater-remote-status.ts
  • src/main/updater/updater-setup.ts
  • src/main/updater/updater-state.ts
  • src/renderer/src/components/LinuxPackageInstallRecoveryCard.test.tsx
  • src/renderer/src/components/LinuxPackageInstallRecoveryCard.tsx
  • src/renderer/src/components/UpdateCard.error-card.test.tsx
  • src/renderer/src/components/UpdateCard.test.ts
  • src/renderer/src/components/UpdateCard.tsx
  • src/renderer/src/components/UpdateErrorCardContent.tsx
  • src/renderer/src/components/maintenance/update-card/UpdateAvailableCardContent.tsx
  • src/renderer/src/components/maintenance/update-card/UpdateCardStateContent.tsx
  • src/renderer/src/components/maintenance/update-card/update-card-error-model.ts
  • src/renderer/src/components/maintenance/update-card/update-card-visibility.ts
  • src/renderer/src/components/settings/GeneralUpdateSettingsSection.test.tsx
  • src/renderer/src/components/settings/GeneralUpdateSettingsSection.tsx
  • src/renderer/src/components/settings/RemoteServerUpdateStatus.tsx
  • src/renderer/src/components/status-bar/UpdateStatusSegment.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/shared/child-process/__fixtures__/child-process-import-allowlist.txt
  • src/shared/child-process/__fixtures__/windows-console-visibility-allowlist.txt
  • src/shared/child-process/child-process-import-boundary.test.ts
  • src/shared/child-process/windows-console-visibility.test.ts
  • src/shared/cli-argument-boundary.test.ts
  • src/shared/cli-argument-boundary.ts
  • src/shared/edit-distance.ts
  • src/shared/serve-option-validation.test.ts
  • src/shared/serve-option-validation.ts
  • src/shared/update-status-types.ts
💤 Files with no reviewable changes (8)
  • src/shared/child-process/fixtures/child-process-import-allowlist.txt
  • src/shared/child-process/fixtures/windows-console-visibility-allowlist.txt
  • src/main/startup/appimage-cli-redirect.ts
  • src/main/startup/packaged-cli-entry-redirect.test.ts
  • config/docker/headless-pairing/Dockerfile
  • src/main/updater/updater-state.ts
  • src/main/startup/packaged-cli-entry-redirect.ts
  • src/main/startup/appimage-cli-redirect.test.ts
🚧 Files skipped from review as they are similar to previous changes (94)
  • src/shared/edit-distance.ts
  • src/renderer/src/components/maintenance/update-card/update-card-error-model.ts
  • src/renderer/src/components/status-bar/UpdateStatusSegment.tsx
  • config/scripts/linux-package-maintainer-scripts.test.mjs
  • src/renderer/src/components/settings/GeneralUpdateSettingsSection.test.tsx
  • src/main/updater-test-harness.ts
  • src/shared/cli-argument-boundary.test.ts
  • src/main/updater-fallback.ts
  • src/main/startup/serve-signal-handlers.test.ts
  • config/scripts/verify-cli-bin.mjs
  • src/cli/cli-version.ts
  • package.json
  • docs/reference/ssh-execution-boundary.md
  • src/cli/runtime/serve-signal-exit-diagnostic.test.ts
  • src/main/linux-package-install-command.ts
  • config/scripts/pr-code-change-scope.test.mjs
  • src/renderer/src/components/settings/RemoteServerUpdateStatus.tsx
  • src/cli/cli-command-name-parity.test.ts
  • src/main/updater.headless-serve-install.test.ts
  • src/cli/index.ts
  • config/reliability-gates.jsonc
  • resources/linux/packaging/after-remove.sh
  • src/cli/args.test.ts
  • src/shared/cli-argument-boundary.ts
  • src/main/updater.fallback.test.ts
  • docs/reference/linux-glibc-compatibility.md
  • config/scripts/build-linux-local.mjs
  • src/renderer/src/i18n/locales/en.json
  • src/main/startup/serve-options.ts
  • config/scripts/pr-code-change-scope.mjs
  • .github/workflows/pr.yml
  • src/main/updater.mac-install.test.ts
  • src/cli/args.ts
  • src/cli/cli-version.test.ts
  • src/main/startup/serve-signal-handlers.ts
  • config/scripts/run-linux-cli-launch-contract-docker.mjs
  • src/main/startup/cli-command-names.ts
  • config/tsconfig.cli.json
  • src/main/startup/serve-mode-argv.test.ts
  • resources/linux/bin/orca-ide
  • config/scripts/orcad-operations-restart-safety.test.mjs
  • src/main/updater.quit-and-install.test.ts
  • src/main/updater.install-failure-cause.test.ts
  • src/main/startup/cli-launch-redirect.ts
  • src/renderer/src/components/maintenance/update-card/UpdateCardStateContent.tsx
  • src/renderer/src/components/maintenance/update-card/UpdateAvailableCardContent.tsx
  • config/scripts/headless-serve-shutdown-workflow.test.mjs
  • src/cli/serve-electron-flag-parity.test.ts
  • config/docker/headless-serve-shutdown/Dockerfile
  • src/renderer/src/components/UpdateCard.tsx
  • src/renderer/src/components/settings/GeneralUpdateSettingsSection.tsx
  • src/main/linux-package-update-recovery.ts
  • src/main/linux-package-install-diagnostic.test.ts
  • config/docker/headless-serve-shutdown/run-signal-case.sh
  • src/main/linux-update-package-type.ts
  • config/scripts/build-linux-local.test.mjs
  • src/renderer/src/components/UpdateErrorCardContent.tsx
  • src/main/linux-update-package-type.test.ts
  • src/renderer/src/components/LinuxPackageInstallRecoveryCard.test.tsx
  • src/main/linux-package-install-command.test.ts
  • src/main/updater.linux-root-package-install.test.ts
  • src/main/updater-events.test.ts
  • src/main/updater-mac-install.ts
  • src/main/updater.startup-scheduling.test.ts
  • config/scripts/pr-workflow-parallelism.test.mjs
  • docs/reference/orcad-operations.md
  • src/main/linux-package-downloaded-status.ts
  • src/renderer/src/components/maintenance/update-card/update-card-visibility.ts
  • config/scripts/static-appimage-package-contract.test.mjs
  • src/shared/serve-option-validation.ts
  • src/renderer/src/components/UpdateCard.test.ts
  • src/cli/command-suggestion.ts
  • src/shared/update-status-types.ts
  • src/main/startup/cli-launch-redirect.test.ts
  • config/scripts/verify-linux-glibc-floor.cjs
  • src/shared/serve-option-validation.test.ts
  • config/docker/headless-serve-shutdown/run-appimage-desktop-startup-case.sh
  • config/docker/cli-launch-contract/run-cli-case.sh
  • src/renderer/src/components/LinuxPackageInstallRecoveryCard.tsx
  • src/main/startup/serve-options.test.ts
  • config/electron-builder.config.cjs
  • config/scripts/run-headless-serve-shutdown-docker.mjs
  • config/scripts/static-appimage-package-contract.cjs
  • config/scripts/electron-builder-runtime-resources.test.mjs
  • config/scripts/verify-linux-glibc-floor.test.mjs
  • src/main/updater-linux-package-recovery-actions.test.ts
  • src/renderer/src/components/UpdateCard.error-card.test.tsx
  • src/main/updater-events.ts
  • src/main/startup/serve-mode-argv.ts
  • src/cli/runtime/launch.test.ts
  • src/main/linux-package-update-recovery.test.ts
  • src/main/startup/ensure-virtual-display.test.ts
  • src/main/updater.linux-externally-managed.test.ts
  • docs/reference/headless-linux-server.md

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

Comment on lines +205 to +206
if (inheritedFd && /^\d+$/.test(inheritedFd)) {
return true

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- repository conventions and learnings ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- target source ---'
cat -n src/main/startup/ensure-virtual-display.ts | sed -n '1,155p;185,220p'
printf '%s\n' '--- direct caller ---'
cat -n src/main/startup/main-process-preflight.ts | sed -n '95,125p'
printf '%s\n' '--- relevant scoped guidance ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/*/*.md; do
  case "$f" in
    *conventions*/*|*learnings*/*|*architecture/*)
      printf '\n--- %s ---\n' "$f"
      cat "$f"
      ;;
  esac
done

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- helper implementation and nearby contracts ---'
cat -n src/main/startup/ensure-virtual-display.ts | sed -n '150,220p'
printf '%s\n' '--- references and tests ---'
rg -n -C 4 'hasUsableWaylandDisplay|hasUsableLinuxDisplay|WAYLAND_SOCKET|fstatSync' src tests package.json
printf '%s\n' '--- applicable conventions ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/src-main-daemon.md
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/repo-wide.md | sed -n '1,180p'
printf '%s\n' '--- relevant learnings ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src-main.md /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/repo-wide.md; do
  printf '\n--- %s ---\n' "$f"
  cat "$f"
done

Repository: stablyai/orca

Length of output: 48105


🌐 Web query:

Node.js fs fstatSync file descriptor Stats isSocket throws invalid file descriptor official documentation

💡 Result:

The fs.fstatSync(fd) method in Node.js does not directly throw an "invalid file descriptor" error inside its isSocket check [1][2]. Rather, if you provide an invalid file descriptor (an integer that does not refer to an open file or resource), fs.fstatSync(fd) itself will throw an error with the code 'EBADF' (Bad File Descriptor) [3][4]. Here is the breakdown of why this occurs: 1. fs.fstatSync(fd) expects a valid, open file descriptor [5]. If the descriptor is invalid, the operation fails at the system level, and Node.js throws an Error: EBADF: bad file descriptor [3][4]. 2. Because fs.fstatSync(fd) throws this exception before returning a result, you never reach the stage of calling any methods on the returned object (such as.isSocket) [3][6]. 3. The isSocket method is a property of the fs.Stats object that is returned only after a successful fstatSync call [7][6]. It simply returns a boolean indicating if the stats object describes a socket [8][6]. To handle cases where a file descriptor might be invalid, you should wrap the call in a try...catch block to catch the EBADF error [3][4]. Example: try { const stats = fs.fstatSync(fd); if (stats.isSocket) { // Handle socket } } catch (err) { if (err.code === 'EBADF') { // Handle invalid file descriptor } else { throw err; } } There is no "invalid file descriptor" error triggered by the isSocket method itself; if the code reaches isSocket, the file descriptor was valid at the time the stats were retrieved [3][6].

Citations:


Validate the inherited Wayland file descriptor.

When WAYLAND_SOCKET contains digits, hasUsableWaylandDisplay returns true without checking the descriptor. A closed or non-socket descriptor can bypass hasUsableLinuxDisplay and allow packaged startup without a usable display. Use fstatSync(Number(inheritedFd)).isSocket() inside try/catch, and return false when fstatSync throws. Add a regression test for a closed descriptor.

🧰 Tools
🪛 ast-grep (0.45.2)

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { spawn, type ChildProcess } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

The prior review flagged the PR as unmergeable against main (12 conflicts across structural files, two of them modify/delete). This run reviewed the conflict resolution: the merge commit lands the already-reviewed nine-PR Linux packaging stack onto main's split updater, plus two mechanical follow-ups.

  • Merge resolution — took main's side on the structural files and re-applied the stack's behavior into the new modules: the deb/rpm/unusable install gate in updater-install-execution.ts, the externally-managed download gate in updater-download-install.ts, autoInstallOnAppQuit gated to non-root in updater-setup.ts, the manual-service-update-required remote status in updater-remote-status.ts, and the retained manual-install card via sendSettledCheckStatus in updater-check-state.ts.
  • Pre-ready startup port — the four pre-ready changes moved into main-process-preflight.ts (single maybeRedirectCliLaunch before the serve-argv rewrite, the packaged non-serve display gate, the serve Xvfb gate), and validated serve options re-exported from serve-options.ts.
  • appimage-cli-redirect.ts delete accepted — cli-launch-redirect.ts:121-122 never redirects serve, so #17633's "keep Chromium switches out of the CLI redirect" concern is subsumed rather than lost; serve-mode-argv-cli-redirect-order.test.ts pins --disable-features=Vulkan serve staying in-process.
  • Ratchet re-pins — child_process import boundary 160→158 and windows-console-visibility 68→66, plus the batch-shim allowlist entries for build-linux-local.mjs.

I verified the four load-bearing behaviors carry over intact (install refusal, download refusal, remote-status refusal, retained card) and that the three deleted redirect files leave no dangling references.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker

nwparker commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Verified and merging. CI green (29 pass), mergeable/clean.

Independently confirmed before merge, since the risk here was a silent drop rather than a visible break:

  • All four ports present at their cited lines: remote support gate (updater-remote-status.ts:35-46), quitAndInstall refusal (updater-install-execution.ts:29-52), externally-managed download gate (updater-download-install.ts:62-78), autoInstallOnAppQuit (updater-setup.ts:147-148).
  • No recovery object on the refusal status — grep returns 0 in that block. Had one leaked in, getActiveDownloadVersion would have fallen back to recovery.version and re-armed the manual-install card on the exact host just blocked.
  • All seven drop-check symbols intact: isExternallyManagedLinuxInstall, hasAbstractXSocket, isManagedDisplayServerAlive, declaredArchFromPath, removeExtractedAppImagePayload, DESKTOP_FLAGS, hasTrustedPackageManagerFor.

The catch that greps alone would have missed: main's refactor had grown its own unvalidated getServeOptions in main-process-serve.ts. Both files existed, typecheck passed, tests passed — and #17683's validation would have been dead code. Confirmed fixed: that file now re-exports from serve-options.ts, which reaches serve-option-validation; the same file on main has zero validation references.

Also landed four semantic changes the original brief did not enumerate — notably sendSettledCheckStatus, without which a settled check erases the retained manual-install card on precisely the distro-managed host that needs it.

The one judgement call worth recording: the dead-code removal was traced rather than assumed — captureLinuxPackageArtifact returns null unless getLinuxRootPackageType() is truthy, so the tracked artifact only ever exists on hosts that now hard-return.

@nwparker
nwparker merged commit f37d2fe into main Sep 2, 2026
57 of 59 checks passed
nwparker added a commit to nwparker/orca that referenced this pull request Sep 2, 2026
stablyai#18100 landed `isExternallyManagedLinuxInstall()`, which the PR body previously
noted would compose cleanly here. It does. Repackagers (AUR, Nix, container
rebuilds) unpack Orca's .deb and inherit its `package-type` marker verbatim, so
a `deb` marker on a host with no dpkg/apt describes the artifact Orca was built
as, never the system that owns the install.

Reporting `deb` there sent the operator to the Orca release page for a package
their host could never apply. The status contract now reports
`externally-managed` and names the package manager that installed Orca as the
upgrade owner instead. No command is emitted for these hosts, because none of
ours is applicable.

The install command itself was already safe -- `buildLinuxPackageInstallCommand`
returns `no-package-manager` on such a host and fell through to the documented
procedure -- so this corrects the reported method and the advice, not a command.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…#18100)

* fix(linux): give the CLI one entrypoint by extracting the AppImage once

* refactor(linux): trim AppImage CLI registration seams

* test(cli): assert registration lock serialization

* fix(linux): fence AppImage terminal shim mounts

* fix(linux): accept extracted AppImage runtimes with APPDIR only

* docs(linux): make headless AppImage extraction runnable

* refactor(linux): import bundled launcher directly

* fix(linux): reclaim superseded AppImage payloads and packaged symlinks

Pruning removed 3215 of 3216 files from a superseded generation and always
stranded resources/app.asar, leaking ~105 MB per version update. Electron's
asar shim reports a *.asar file as a directory, so the recursive remove tried
to rmdir a real file and failed with ENOTEMPTY; the .catch(() => {}) hid it.
Reproduced end to end on Ubuntu 24.04: 519M -> 623M across one update, and
519M again once the payload is actually reclaimed.

removeExtractedAppImagePayload holds process.noAsar for the removal, counted
so overlapping removals cannot hand the shim back early, and the prune site
now warns with the path instead of swallowing the rejection. All three
removal sites use it -- staging cleanup and displaced roots leaked the same
way.

Also reclaim symlinks left by a packaged deb/rpm install, which the
extracted-cache-only rule turned into a hard conflict on a deb -> AppImage
migration, and name the remedy in the conflict error.

* fix(linux): bound the CLI registration lock wait

`retries: 1000` caps the attempt count, not elapsed time, so at up to 1s per
attempt an IPC-driven registration could hang ~16 minutes against a wedged
holder with no feedback.

A legitimate holder is bounded by the extraction timeout, so wait that plus
slack and then fail with a message naming the lock file, rather than hanging.
`maxRetryTime` is forwarded verbatim to the `retry` package by proper-lockfile.

* fix(linux): stop re-extracting the AppImage on inode metadata churn

The extracted-payload cache key hashed ctime alongside dev/ino/size/mtime.
ctime moves on any inode metadata write -- `chmod +x`, which every AppImage
user is told to run, plus `chown`, an ACL or SELinux relabel, and a backup
restore -- none of which alter a byte of the payload.

Measured on Ubuntu 24.04: `chmod +x` leaves dev, ino, size and mtime
identical and moves ctime alone, so the key changed and the next launch paid
a full ~519 MB re-extraction and a multi-second stall to rebuild a payload it
already had, then pruned the old generation.

Key on content identity instead. An in-place content change moves mtime and
almost always size; a replacement moves the inode. The existing
replace-in-place test still passes.

* fix(linux): stop CLI commands from falling through to Chromium startup

* refactor(cli): remove redundant command membership check

* test(cli): cover command-named project selectors

* fix(cli): redirect the open-url command before startup

* test(linux): cover AUR serve wrapper flags

* fix(linux): tighten CLI launch detection

* fix(linux): respect CLI flag value boundaries

* fix(linux): strip injected Chromium switches from CLI args

* fix(linux): report a missing display instead of dying in uv_close

* refactor(linux): read display locks without a preflight race

* fix(linux): preserve unverified external displays

* chore: format reliability gate manifest

* test(packaging): split runtime resource checks

* fix(linux): fail serve when no display is available

* fix(linux): do not treat a lockless X socket as a dead display

An X server writes its lock beside its socket and both survive a crash
(verified against Xvfb under SIGKILL), so a socket with no lock was never
left by a crashed server. It is an endpoint published from elsewhere: a
container bind-mounting only /tmp/.X11-unix, WSLg, or a foreign PID
namespace. Declaring those dead made the desktop gate exit(1) on displays
that work, with no workaround, and the serve gate refuse to start.

Liveness now splits by ownership. A foreign DISPLAY trusts a lockless
socket; Orca's own :99 does not, because removeStaleDisplayArtifacts
unlinks the lock before the socket and so manufactures that state itself --
adopting it would resurrect the orphan-socket bug and stop the cleanup from
self-healing. The stale-lock rejection is unchanged.

Also correct four doc statements this behaviour falsified.

* fix(linux): fail closed when a stale socket blocks the Xvfb rebind

Readiness only checked that /tmp/.X11-unix/X99 exists. A stale socket we
could not unlink still exists after our own Xvfb refused to bind, so Orca set
DISPLAY to a dead server and Chromium died in Ozone init.

Measured on Ubuntu 24.04 against the pre-fix build: with a leftover :99
socket and no lock, serve exits 139 (SIGSEGV), the socket inode is unchanged
before and after, and no lock is recreated -- it neither cleaned up nor
respawned. To a user that is a crash, not a misconfiguration.

This is reachable in the documented topology, where orca-xvfb.service has no
User= and runs as root while serve runs as User=orca: /tmp is sticky, so the
orca uid cannot unlink a root-owned socket, rmSync fails, and Xvfb exits with
the display already active.

Readiness now requires the display to actually be live -- our socket plus a
lock naming a running process -- so the same state reports an unusable
display and exits 1 with the existing diagnosis.

* fix(linux): recognise abstract X sockets and inherited Wayland fds

Two display setups this gate could not prove were refused outright, and on the
desktop path that is app.exit(1) with no workaround.

An X server may bind only the abstract namespace (`@/tmp/.X11-unix/X0`), which
leaves no filesystem socket to stat. Abstract addresses are kernel-owned and
vanish the moment the owner exits, so an entry in /proc/net/unix is proof of a
live server -- no lock file needed and no stale entry possible. Verified on
Ubuntu 24.04, where 139 such addresses were present.

WAYLAND_SOCKET is an already-connected fd handed over by the compositor, so
there is no path to stat and WAYLAND_DISPLAY may be unset entirely. Its
presence is the display.

Both are consulted only after the filesystem-socket check fails, so no
existing verdict changes.

* fix(linux): never treat Orca's own display number as a foreign endpoint

Recognising a lockless X socket as live is correct for an endpoint published
from elsewhere -- a container bind mount, WSLg -- because an X server writes
its lock beside its socket and both survive a crash. It is wrong for
VIRTUAL_DISPLAY_NUMBER, because Orca's own teardown unlinks the lock before
the socket and so manufactures that exact state.

The managed branch was already strict, but a caller that sets DISPLAY=:99
explicitly takes the foreign path and skipped it, accepting a dead display
left by Orca's own interrupted cleanup. Route the managed number through the
strict probe on both paths.

Found by an adversarial audit of the asymmetry introduced earlier in this
branch; the documented systemd topology is unaffected because its Xvfb writes
a real lock.

* test(linux): add a packaged-artifact contract for the CLI launch paths

* test(linux): avoid buffered serve readiness detection

* test(linux): signal AppImage serve owner directly

* test(linux): tolerate readiness timeout boundary

* test(linux): add startup margin to shutdown oracle

* ci(linux): give package contracts timeout headroom

* fix(ci): route all Linux packaging contract changes

* test(linux): poll shutdown readiness without tail leaks

* test(linux): bound shutdown cleanup grace

* test(linux): assert on CLI output, not the harness's own control lines

run-cli-case.sh echoes `RESULT status=N case=<name>`, and the two cases named
*-skills asserted `expectOutput: 'skills'`. That substring was satisfied by
the case name in the harness's own line, so 2 of 8 cases asserted nothing
about the command -- gutting `skills` entirely would still have gone green.

Control lines are now excluded before matching, and both cases assert the
rendered help header, which only real help output produces. Verified on an
Ubuntu 24.04 host: 8/8 still pass against a stack-tip AppImage.

Also register the gate in reliability-gates.jsonc, which stablyai#15085 added a CI
Docker gate without. Red/green is recorded from a stock release AppImage
failing 4 of 8, three of them at status 133 (SIGTRAP).

* fix(linux): require static AppImage runtimes (stablyai#17319)

* test(linux): reject a wrong-architecture native binary at packaging time

Cross-building the arm64 slice on an x64 host silently packed an x86-64
`pty.node` -- the rebuild logged "Forcing native rebuild for linux-arm64" and
shipped the host's binary anyway. Every gate here inspects symbol versions,
which are perfectly valid on the wrong architecture, so nothing noticed.

Observed on a Raspberry Pi 5: the packaged app loaded, then failed with
"Failed to load native module: pty.node", and the launch contract reported
3 of 8 cases crashed rather than naming the cause. Swapping in the aarch64
`pty.node` took the same build to 8/8.

Compare ELF `e_machine` against the slice being packaged and fail with the
offending path. Checked before the glibc pass, because a wrong-architecture
binary's symbol versions are valid but meaningless and would send the reader
down the wrong path.

Release CI builds arm64 on a native runner, so this guards local and future
cross-builds rather than a shipped artifact.

* test(linux): judge per-arch vendored binaries against their own path

The first CI run of the architecture gate failed the x64 package job on
`@parcel/watcher-linux-arm64-glibc/watcher.node`. That binary is arm64 on
purpose: the package ships every architecture and its loader picks the match,
so its presence in an x64 build is correct.

Judge a binary against the architecture its own path names, falling back to
the slice when the path names none. That keeps the case this gate exists for
-- `bin/linux-arm64-*/node-pty.node` holding an x86-64 binary, which is what
shipped to a Raspberry Pi 5 -- while letting multi-arch dependencies through.

Dry-run over the real dependency tree flags nothing for either target arch.

* fix(linux): move deb/rpm update installation outside Orca (stablyai#17318)

* fix(linux): complete deb/rpm package metadata

* fix(linux): preserve CLI link during package upgrades

* docs(linux): document local RPM build prerequisites

* fix(linux): move deb/rpm update installation outside Orca

* fix(updater): preserve Linux recovery across stale events

* fix(updater): fence stale downloaded events by active target

* fix(updater): preserve active Linux package recovery

* test(linux): keep workflow order assertion in scope

* test(updater): assert stale recovery stays silent

* fix(updater): preserve Linux package recovery after checks

* refactor(updater): keep Linux marker message with status

* fix(linux): describe the right manual update path for deb/rpm hosts

A remote host installed from .deb or .rpm now reports
manual-service-update-required, and the guidance told the operator to
"update through the service manager that starts this server" -- which is
correct for unsupported-headless-serve but wrong for a package install,
where nothing about the remedy involves the service manager.

Say both, keyed on how the host was installed.

* docs(linux): document orcad update restart safety

* docs(linux): scope restart census omissions

* docs(linux): use absolute service CLI launcher

* fix(serve): validate in-process serve options before startup (stablyai#17683)

* fix(linux): stop offering updates a distro-managed install cannot apply (stablyai#17918)

Closes stablyai#17702.

The resources/package-type marker is authoritative but never checked against
the host, so any repackager that unpacks Orca's .deb -- AUR, Nix, a container
rebuild -- inherits `deb` verbatim. Install feasibility was then computed
after a ~165 MB download, so those users got check -> download -> a card
promising an install command -> a dead end.

Validate the marker against the host: a deb/rpm marker with no matching
package manager in the trusted directories means a package manager owns this
install. This reuses the exact lists and resolver that
buildLinuxPackageInstallCommand already loops over, so a false positive is
impossible by construction -- any host flagged here would have failed with
no-package-manager after the download anyway. The gate only moves that
verdict earlier. Verified across Debian 12, Ubuntu 24.04, Arch, Fedora 40 and
openSUSE Leap: no false positive on a real deb host, correct on every
repackaging host.

The release is still reported, because the user does want to know 1.4.194
exists and to update through their distro; only the download path is closed.
`externallyManaged` is an additive optional field on the existing `available`
status, so older paired clients decode it unchanged. downloadUpdate() refuses
authoritatively, since main owns this verdict rather than the card, and
unwinds any pinned-build state first -- a Linux pinned jump resolves to
'release', and stranding isPinnedBuildActive would silently kill every
background check for the rest of the process.

Note the fix the issue suggests cannot work: electron-updater builds a
PacmanUpdater whose doDownloadUpdate looks for a .pacman asset Orca does not
publish, then dereferences undefined.

* style(cli): restore prettier wrapping on install error copy

* test(linux): re-pin the child-process ratchets and the batch-shim allowlist after the merge
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