Repository navigation
Fix headless Linux serve pairing readiness - #9785
Conversation
📝 WalkthroughWalkthroughAdds 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)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (2)
config/docker/headless-pairing/Dockerfile (1)
34-38: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winRuntime pairing fixture never drops root, despite creating and chowning for an
orcauser.
Dockerfilecreates anorcaaccount andrun-appimage-case.shchowns the per-case state directory for it, but nothing ever switches the process to that user (noUSERinstruction, nosu/gosuin 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 aUSER orcainstruction (after thechown, which must happen at container startup, not build time, since$state_diris created per-run) or drop privileges in the entrypoint wrapper instead.config/docker/headless-pairing/run-appimage-case.sh#L9-L12: afterchown -R orca:orca "$state_dir", exec the launcher viasu orca -c/gosu orcarather than continuing to run as root.Source: Linters/SAST tools
src/main/runtime/pairing-endpoint.ts (1)
14-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd rationale comments for non-obvious validation choices.
Several decisions here are non-obvious and undocumented: defaulting to
127.0.0.1when no override is given (line 21), rejecting wildcard hosts (isWildcardHost, lines 98-101), and rejecting explicit port0(line 70-72 inparseHostOverride). 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
📒 Files selected for processing (24)
config/docker/headless-pairing/Dockerfileconfig/docker/headless-pairing/Dockerfile.buildconfig/docker/headless-pairing/run-appimage-case.shconfig/scripts/run-headless-linux-pairing-docker.mjsconfig/scripts/serve-headless-fresh-profile-pairing.mjsdocs/reference/headless-linux-server.mdsrc/cli/runtime/launch.test.tssrc/cli/runtime/launch.tssrc/cli/specs/serve.tssrc/main/index.tssrc/main/runtime/device-registry.tssrc/main/runtime/pairing-endpoint.test.tssrc/main/runtime/pairing-endpoint.tssrc/main/runtime/runtime-rpc.test.tssrc/main/runtime/runtime-rpc.tssrc/main/server/serve-readiness.test.tssrc/main/server/serve-readiness.tssrc/main/server/serve-stdout-boundary.test.tssrc/main/server/serve-stdout-boundary.tssrc/main/startup/appimage-cli-redirect.test.tssrc/main/startup/appimage-cli-redirect.tssrc/main/startup/desktop-startup-ordering.test.tssrc/main/startup/ensure-virtual-display.test.tssrc/main/startup/ensure-virtual-display.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/cli/runtime/launch.ts (1)
90-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the AppImage argument/environment contract.
Lines 90-93 and 123-124 contain non-obvious behavior:
--no-sandboxmust precede--serve, andORCA_APPIMAGE_NO_SANDBOXis 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
📒 Files selected for processing (5)
src/cli/runtime/launch.test.tssrc/cli/runtime/launch.tssrc/main/index.tssrc/main/runtime/runtime-rpc.tssrc/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
| 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) | ||
| }) |
There was a problem hiding this comment.
🎯 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.
| 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*$/) | |
| }) |
Summary
Addresses #9759.
ELI5
The Linux AppImage was sometimes mistaking
orca servefor a normal desktop launch when Chromium's--no-sandboxflag 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:
--no-sandbox serveenter the CLI path, then restore--no-sandboxonly for the Electron server child.SIGTRAP.endpointalias, and explicit pairing availability/reason/guidance;--pairing-addressis explicitly an advertised address, with normalization and validation for hostnames, IPv4/IPv6, ports, HTTP/WebSocket schemes, and reverse-proxy paths;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 insrc/renderer/src/components/skills/skill-freshness-group.tsx:101; changed-file oxlint and touched switch-exhaustiveness checks pass.pnpm typecheckpnpm 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-viteand production-like Linux AppImage packaging passed; the full cross-platform native build was not run.Linux/package verification:
5d7eb40074dfefbf7c70d6693dd1a420e6564fe8ce61714249766359cacedafe.xvfb-run,dbus-run-session -- xvfb-run, and journal-like launches in human and JSON modes.--appimage-extract-and-run --no-sandbox serveentry path.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:
endpointfield as an alias forboundEndpoint;zlib1g-dev, FUSE/extraction behavior, and extract-and-run stdout noise;SIGTRAP;*as an advertised wildcard;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-addresschanges advertisement only and never widens the existing bind behavior.--no-sandboxis 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.Notes
Regression risks and mitigations:
--no-sandboxcould have changed desktop/CLI classification. Unit tests cover desktop-only, help, and serve forms, and the public packaged entry passed in Docker.console.log/info/debugnow go to stderr. The change is gated to--serve; desktop logging is unchanged. Readiness writes directly to stdout.The worktree setup completed successfully before implementation. No public issue comments or edits were made.