Skip to content

Fix headless Linux serve pairing readiness - #9785

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/issue-9759-headless-linux-pairing
Jul 22, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/issue-9759-headless-linux-pairing

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Addresses #9759.

ELI5

The Linux AppImage was sometimes mistaking orca serve for a normal desktop launch when Chromium's --no-sandbox flag came first. It would start desktop-only Electron work, emit noisy Linux service errors, and never reach the code that prints the server address. Separately, a pairing link could look valid while advertising an unusable address, and failures in the pairing registry or encryption-key setup were hidden behind a generic missing-WebSocket result.

This PR fixes the startup route and defines one authoritative serve-ready contract:

  • AppImage launches such as --no-sandbox serve enter the CLI path, then restore --no-sandbox only for the Electron server child.
  • Linux serve mode uses software rendering even with an externally supplied Xvfb display, avoiding the reproduced Chromium GPU-process SIGTRAP.
  • readiness is published exactly once after the listener and pairing identity settle, with one complete stdout write;
  • JSON output is versioned and includes the actual bound endpoint, advertised endpoint, legacy endpoint alias, and explicit pairing availability/reason/guidance;
  • --pairing-address is explicitly an advertised address, with normalization and validation for hostnames, IPv4/IPv6, ports, HTTP/WebSocket schemes, and reverse-proxy paths;
  • pairing registry and E2EE failures keep their precise reason, and credential creation is transactional so failed persistence cannot leave an in-memory ghost token;
  • serve-mode console diagnostics move to stderr so direct JSON stdout remains machine-readable.

The Docker fixture exercises the packaged AppImage path on Ubuntu 24.04, Debian 13, and an Ubuntu 22.04 baseline. Related client-network behavior in #9760 and local PTY behavior in #9047 remain out of scope.

Screenshots

No visual change.

Testing

  • pnpm lint — repository-wide lint reaches an unrelated existing switch-exhaustiveness error in src/renderer/src/components/skills/skill-freshness-group.tsx:101; changed-file oxlint and touched switch-exhaustiveness checks pass.
  • pnpm typecheck
  • pnpm test — focused suites passed (8 files / 114 tests), plus the CLI suite (151 tests); the entire repository suite was not run.
  • pnpm build — pnpm run build:electron-vite and production-like Linux AppImage packaging passed; the full cross-platform native build was not run.
  • Added or updated high-quality tests that would catch regressions, including AppImage routing, exact-once readiness, stdout isolation, endpoint normalization, unavailable reasons, transactional credential persistence, and external-Xvfb GPU configuration.

Linux/package verification:

  • Final AppImage: 195 MB; SHA-256 5d7eb40074dfefbf7c70d6693dd1a420e6564fe8ce61714249766359cacedafe.
  • Ubuntu 24.04 and Debian 13: direct, xvfb-run, dbus-run-session -- xvfb-run, and journal-like launches in human and JSON modes.
  • Ubuntu 22.04 Xvfb JSON baseline.
  • Public --appimage-extract-and-run --no-sandbox serve entry path.
  • Explicit invalid-address and operator-disabled pairing contracts.
  • Authenticated E2EE status request from an independent Debian client container, matching the ready runtime ID.
  • Deliberately mismatched advertised port fails the real client connection probe.
  • Startup checks are bounded; containers are unprivileged and use graceful teardown.

AI Review Report

Ran iterative internal review-until-clean, including elegance and performance interrogation. Three final rounds followed the earlier review passes.

Review findings resolved:

  • restored the legacy JSON endpoint field as an alias for boundEndpoint;
  • prevented serve diagnostics from polluting stdout;
  • documented zlib1g-dev, FUSE/extraction behavior, and extract-and-run stdout noise;
  • corrected Docker stream assertions and teardown behavior;
  • disabled the Linux serve GPU process for externally managed Xvfb after reproducing a zygote SIGTRAP;
  • rejected * as an advertised wildcard;
  • made real registry/E2EE initialization and persistence failures reach their stable readiness reasons;
  • made pending credential creation transactional;
  • constrained readiness reasons to the authoritative type union.

The final review found no remaining in-scope Critical, High, Medium, or meaningful Low issues. Cross-platform review covered macOS, Linux, Windows, WSL, SSH/remote runtimes, AppImage-only routing, platform-gated Chromium behavior, portable path handling, and unchanged desktop stdout behavior. No UI shortcuts, labels, or layout changed.

Performance review found no production polling, retry loops, repeated key generation, duplicate listeners, or hot-path scans. Endpoint parsing and readiness writing occur once at startup; transactional credential creation adds no complexity beyond the existing registry serialization; disabling the unnecessary Linux GPU process reduces headless resource use.

Security Audit

  • Pairing remains authenticated and E2EE; the Docker client completed a real encrypted status request rather than only parsing the URL.
  • The intended pairing capability remains the only secret printed. Device tokens and key material are not logged separately.
  • Invalid schemes, credentials, fragments, zero/invalid ports, and wildcard advertised hosts are rejected before a credential is minted.
  • Registry writes publish the credential only after durable persistence succeeds.
  • --pairing-address changes advertisement only and never widens the existing bind behavior.
  • --no-sandbox is preserved only when the operator explicitly supplied it, is removed from the CLI child environment, and the documentation warns that it disables a Chromium security boundary.
  • No dependencies, shell interpolation paths, IPC authorization rules, or Git/provider behavior changed.

Notes

Regression risks and mitigations:

  • AppImage argument routing: stripping --no-sandbox could have changed desktop/CLI classification. Unit tests cover desktop-only, help, and serve forms, and the public packaged entry passed in Docker.
  • Stdout routing: serve-mode console.log/info/debug now go to stderr. The change is gated to --serve; desktop logging is unchanged. Readiness writes directly to stdout.
  • Linux rendering: all Linux serve launches now disable hardware acceleration. This may reduce offscreen browser rendering throughput, but avoids a proven headless GPU-process crash and does not affect desktop mode or other platforms.
  • Advertised endpoints: complete proxy URLs preserve their external scheme, port, path, and query. Connectivity still depends on DNS/firewall/proxy routing; docs call this out and a real unreachable offer is tested.
  • Credential persistence: creation/rotation now replaces in-memory registry state only after the secure write succeeds, preserving the previous credential if rotation cannot be persisted.

The worktree setup completed successfully before implementation. No public issue comments or edits were made.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds headless Linux pairing infrastructure across runtime code, serve output, AppImage startup, Docker fixtures, and documentation. Pairing endpoints are normalized and validated, pairing failures expose structured reasons, and serve readiness is rendered through a single publisher with human, JSON, and recipe-JSON modes. AppImage no-sandbox handling and headless GPU configuration are updated. Docker-based checks cover startup modes, readiness contracts, authenticated pairing, unavailable pairing, and unreachable advertised endpoints.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.00% which is insufficient. The required threshold is 80.00%. 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 summarizes the main change: headless Linux serve pairing readiness fixes.
Description check ✅ Passed All required sections are present and substantially filled, including summary, screenshots, testing, review, security, and notes.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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: 6

🧹 Nitpick comments (2)
config/docker/headless-pairing/Dockerfile (1)

34-38: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Runtime pairing fixture never drops root, despite creating and chowning for an orca user.

Dockerfile creates an orca account and run-appimage-case.sh chowns the per-case state directory for it, but nothing ever switches the process to that user (no USER instruction, no su/gosu in the entrypoint script). The container that actually executes the built AppImage and exercises real network pairing therefore always runs as root — the one root cause is a missing privilege-drop step.

  • config/docker/headless-pairing/Dockerfile#L34-L38: add a USER orca instruction (after the chown, which must happen at container startup, not build time, since $state_dir is created per-run) or drop privileges in the entrypoint wrapper instead.
  • config/docker/headless-pairing/run-appimage-case.sh#L9-L12: after chown -R orca:orca "$state_dir", exec the launcher via su orca -c / gosu orca rather than continuing to run as root.

Source: Linters/SAST tools

src/main/runtime/pairing-endpoint.ts (1)

14-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add rationale comments for non-obvious validation choices.

Several decisions here are non-obvious and undocumented: defaulting to 127.0.0.1 when no override is given (line 21), rejecting wildcard hosts (isWildcardHost, lines 98-101), and rejecting explicit port 0 (line 70-72 in parseHostOverride). A short "why" comment on each would help future maintainers understand the security/UX intent.

As per coding guidelines, "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."

Also applies to: 98-101

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9d417583-6ca5-411a-aa87-1143b894323d

📥 Commits

Reviewing files that changed from the base of the PR and between 903112a and 19bec4b.

📒 Files selected for processing (24)
  • config/docker/headless-pairing/Dockerfile
  • config/docker/headless-pairing/Dockerfile.build
  • config/docker/headless-pairing/run-appimage-case.sh
  • config/scripts/run-headless-linux-pairing-docker.mjs
  • config/scripts/serve-headless-fresh-profile-pairing.mjs
  • docs/reference/headless-linux-server.md
  • src/cli/runtime/launch.test.ts
  • src/cli/runtime/launch.ts
  • src/cli/specs/serve.ts
  • src/main/index.ts
  • src/main/runtime/device-registry.ts
  • src/main/runtime/pairing-endpoint.test.ts
  • src/main/runtime/pairing-endpoint.ts
  • src/main/runtime/runtime-rpc.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/server/serve-readiness.test.ts
  • src/main/server/serve-readiness.ts
  • src/main/server/serve-stdout-boundary.test.ts
  • src/main/server/serve-stdout-boundary.ts
  • src/main/startup/appimage-cli-redirect.test.ts
  • src/main/startup/appimage-cli-redirect.ts
  • src/main/startup/desktop-startup-ordering.test.ts
  • src/main/startup/ensure-virtual-display.test.ts
  • src/main/startup/ensure-virtual-display.ts

Comment thread docs/reference/headless-linux-server.md Resolved
Comment thread docs/reference/headless-linux-server.md Resolved
Comment thread docs/reference/headless-linux-server.md Resolved
Comment thread docs/reference/headless-linux-server.md Resolved
Comment thread docs/reference/headless-linux-server.md Resolved
Comment thread src/main/runtime/pairing-endpoint.ts Resolved

@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

🧹 Nitpick comments (1)
src/cli/runtime/launch.ts (1)

90-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the AppImage argument/environment contract.

Lines 90-93 and 123-124 contain non-obvious behavior: --no-sandbox must precede --serve, and ORCA_APPIMAGE_NO_SANDBOX is consumed by the wrapper rather than forwarded. Add concise comments explaining these constraints to prevent future regressions.

Also applies to: 123-124

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c43d4b0c-6f1c-4cd7-9c76-d94f2d6e8c1f

📥 Commits

Reviewing files that changed from the base of the PR and between ac94cad and b6beade.

📒 Files selected for processing (5)
  • src/cli/runtime/launch.test.ts
  • src/cli/runtime/launch.ts
  • src/main/index.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/startup/desktop-startup-ordering.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/cli/runtime/launch.test.ts
  • src/main/index.ts
  • src/main/runtime/runtime-rpc.ts

Comment on lines +75 to +82
it('notifies the serve supervisor only after publishing readiness', () => {
const source = readFileSync(join(process.cwd(), 'src/main/index.ts'), 'utf8')
const readyStart = source.indexOf('await serveReadinessPublisher.publish(')
const supervisorReady = source.indexOf('notifyServeSupervisorReady(', readyStart)

expect(readyStart).toBeGreaterThanOrEqual(0)
expect(supervisorReady).toBeGreaterThan(readyStart)
})

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 | 🟡 Minor | ⚡ Quick win

Assert ordering against publish completion, not its opening.

The test only checks that notifyServeSupervisorReady( appears after await serveReadinessPublisher.publish( starts. It would still pass if the notification occurred inside the publish expression, before the awaited publish completed. Assert that the publish call closes before the supervisor notification, or match the complete call sequence.

Suggested test adjustment
    const readyStart = source.indexOf('await serveReadinessPublisher.publish(')
    const supervisorReady = source.indexOf('notifyServeSupervisorReady(', readyStart)
+   const publishBlock = source.slice(readyStart, supervisorReady)

    expect(readyStart).toBeGreaterThanOrEqual(0)
    expect(supervisorReady).toBeGreaterThan(readyStart)
+   expect(publishBlock).toMatch(/\n  \)\s*$/)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('notifies the serve supervisor only after publishing readiness', () => {
const source = readFileSync(join(process.cwd(), 'src/main/index.ts'), 'utf8')
const readyStart = source.indexOf('await serveReadinessPublisher.publish(')
const supervisorReady = source.indexOf('notifyServeSupervisorReady(', readyStart)
expect(readyStart).toBeGreaterThanOrEqual(0)
expect(supervisorReady).toBeGreaterThan(readyStart)
})
it('notifies the serve supervisor only after publishing readiness', () => {
const source = readFileSync(join(process.cwd(), 'src/main/index.ts'), 'utf8')
const readyStart = source.indexOf('await serveReadinessPublisher.publish(')
const supervisorReady = source.indexOf('notifyServeSupervisorReady(', readyStart)
const publishBlock = source.slice(readyStart, supervisorReady)
expect(readyStart).toBeGreaterThanOrEqual(0)
expect(supervisorReady).toBeGreaterThan(readyStart)
expect(publishBlock).toMatch(/\n \)\s*$/)
})

@OrcaWin
OrcaWin merged commit 34c1604 into main Jul 22, 2026
7 checks passed
@OrcaWin
OrcaWin deleted the OrcaWin/issue-9759-headless-linux-pairing branch July 22, 2026 01:23
@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants