Skip to content

fix(push): honor "only when desktop is away" on headless orca serve - #31956

Merged
nwparker merged 5 commits into
mainfrom
nwparker/serve-desktop-away
Oct 22, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/serve-desktop-away

Conversation

@nwparker

@nwparker nwparker commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​136 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​287 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​276

ELI5

Your phone has a setting: "only notify me when I'm away from my desktop." On a headless server (orca serve, or the server Orca installs over SSH or in WSL), the server had no way to tell whether you were at your desktop. So the setting did nothing, and the phone buzzed for every agent turn, even while you were watching that turn live on the desktop. Now each desktop tells the servers it's connected to whether someone is using it, and the server uses that to decide.

What Changed

  • Before: on a headless server, every push notification carried "desktop away: unknown". The push filter only holds a push back when the desktop is known to be present, so with the filter on, every push still went out.
  • After: a connected desktop that is in use holds back the server's away-only pushes. When nobody is at any desktop (idle past the existing 3-minute threshold, locked, asleep, disconnected, or no desktop at all), pushes go out as before.

How it works:

  • New host RPC. notifications.reportDesktopPresence { away } is advertised as notifications.desktop-presence.v1.
    • The host accepts it only from a paired desktop's own socket: runtime scope, a real connection id, and a socket that hasn't closed yet.
    • Reports are tracked per connection. A report lapses after 90 seconds, and it is forgotten when the socket closes, through the existing subscription-cleanup registry.
    • Stale entries are pruned, so nothing builds up.
  • How the host decides. "Present" requires a fresh report from an attached desktop saying someone is there. Otherwise the host uses its own idle check (Electron hosts only). A headless host with no such report counts as away.
    • "Unknown" never counts as present. The existing "unknown must not silence a phone" rule is unchanged.
  • What the desktop sends. Every 5 seconds the desktop reads the OS idle state, the same powerMonitor check the desktop host already uses. It reports to every ready shared-control socket whose host advertises the capability. A report is sent when the state changes, when the socket reconnects, and as a 30-second keepalive.
  • Sleep and lock. On suspend or lock-screen the desktop reports away straight away, and keeps reporting away until resume or unlock-screen. Closing the lid doesn't leave pushes held back until the 90-second expiry. That expiry is only there for crashes.

Why

The server can't watch the user's keyboard, but the desktop already can (readDesktopAwayState), so the desktop is the right place to measure presence. This uses the transport and capability gating that already exist (shared-control socket, status.capabilities), so SSH, WSL and plain orca serve all behave the same.

Alternatives considered:

  • Treat any attached desktop socket or RPC traffic as presence. Desktops poll in the background, so a desktop left open overnight would silence the phone.
  • Treat undefined as away. This would keep buzzing during active use, which is the bug itself.

Scope of a presence report, and why it covers all of a host's events: the desktop renderer itself shows OS notifications for agents on every mirrored remote host, including background worktrees and hosts other than the active one. It does this through the session.tabs.subscribeAll mirror, the hook-completion lane and the parked-terminal watcher. So when the desktop is in use, the same event already shows on the desktop. Two limits on this:

  • Presence is per device. It does not check whether that desktop has its own notifications turned on, or whether it has muted that host. A desktop with notifications off still counts as present.
  • On an Electron host, a fresh report from an attached remote desktop also counts as present, for the same reason.

Mixed versions:

  • Old desktop, new host: the old desktop never reports, so the host treats it as away (same delivery as today).
  • New desktop, old host: the old host doesn't advertise the capability, so the desktop sends nothing.
  • Old phones: unaffected, because the filter runs on the host.

Fixes #31570

Thanks to @letjsk for the precise report and bundle analysis.

Visual Proof

N/A: no UI change. The change is in when a host sends a push.

Testing

  • push-policy-pipeline.integration.test.ts drives the real controller, the RPC handler and the subscription registry against the push pipeline. It covers:

    • no desktop means away;
    • a phone, or a socket that already closed, can't claim presence;
    • present holds back pushes and away lets them through;
    • a report lapses after the TTL, and a new report after that works;
    • closing the socket forgets the report.

    It fails on main, where neither the method nor the controller API exists and headless presence is undefined.

  • desktop-presence-reporter.test.ts checks:

    • reports on change, on a new socket and as a keepalive;
    • unknown is sent as away;
    • a failed send is retried;
    • suspend latches away until resume.
  • Ran the 50 test files that import changed modules, the full static job, and pnpm tc.

  • Not verified live on a real SSH/WSL host with a paired phone. A push gateway round-trip needs a real APNs/FCM device.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Codex review clean on the head commit. Independent Opus review: no P0–P2. Its P2s from the first round (the sleep gap, presence scope) and its P3s (late reports, pruning, early return, the suspend latch) are addressed.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: only an authenticated runtime-scope device can report, and only for its own socket.
  • Platforms: powerMonitor is available on all three. Lock events are macOS/Windows; on Linux, the idle check's locked state covers it.
  • Remote: SSH, WSL and serve all use the same shared-control transport.
  • Mobile: no change to the phone.
  • Performance: one cheap idle read every 5 seconds, and at most one small RPC per host every 30 seconds.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 02e00319-8559-4b81-a54b-be1f3b369a59
📥 Commits

Reviewing files that changed from the base of the PR and between ec9464a and e59e55b.

📒 Files selected for processing: 3
  • src/main/ipc/runtime-environments/runtime-environment-shared-control-answers.ts
  • src/main/notifications/desktop-presence-reporter.test.ts
  • src/main/notifications/desktop-presence-reporter.ts
📝 Walkthrough

The changes add desktop presence reporting between the main process and capable runtime environments. Runtime clients can report desktop away state through a workspace-permission RPC. The runtime tracks reports by connection, removes stale reports, and uses active desktop presence when setting the desktop-away value for mobile notifications. Tests cover reporter behavior and push-filter handling.

Priority: ⚪ Pending latest changes

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to ec946

A rapid change in desktop presence could cause an away-only phone notification to be missed. The risk is narrow, but presence reports should be ordered before relying on this behavior.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: honoring the desktop-away push filter on headless Orca servers.
Description check Passed The description follows the repository template and provides the user impact, implementation details, rationale, linked issue, testing coverage, compatibility notes, and checklist status.
Linked Issues check Passed Issue [#31570] requires the onlyWhenDesktopAway filter to work on headless hosts when a paired desktop is active. The PR adds notifications.reportDesktopPresence, capability gating, per-connection…
Out of Scope Changes check Passed The changes stay within issue [#31570]. Shared-control socket tracking, capability registration, RPC validation, startup and quit lifecycle wiring, push-controller integration, and automated tests dir…
Full details: Linked Issues check

Explanation

Issue [#31570] requires the onlyWhenDesktopAway filter to work on headless hosts when a paired desktop is active. The PR adds notifications.reportDesktopPresence, capability gating, per-connection reports, 90-second expiry, socket cleanup, and desktop idle, lock, and sleep reporting. The push controller treats a fresh away: false report as present and treats no report, stale reports, or away: true as away. The integration and reporter tests cover the filter, authorization, expiry, cleanup, retries, and power-state behavior. The suggested per-host toggle is not a required coding objective.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue [#31570]. Shared-control socket tracking, capability registration, RPC validation, startup and quit lifecycle wiring, push-controller integration, and automated tests directly support desktop-presence reporting and filtering. No unrelated product behavior or mobile-client changes are identified.

✨ 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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cfecf86d-eb00-48c6-82f0-4e592a2a244b
📥 Commits

Reviewing files that changed from the base of the PR and between c8d0f99 and ec9464a.

⛔ Files ignored due to path filters: 1
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing: 17
  • src/main/ipc/runtime-environments/runtime-environment-request-connections.ts
  • src/main/ipc/runtime-environments/runtime-environment-shared-control-answers.ts
  • src/main/notifications/desktop-presence-reporter.test.ts
  • src/main/notifications/desktop-presence-reporter.ts
  • src/main/runtime/desktop-client-presence-tracker.ts
  • src/main/runtime/push/push-policy-pipeline.integration.test.ts
  • src/main/runtime/rpc/methods/notifications.ts
  • src/main/runtime/runtime-desktop-surface.ts
  • src/main/runtime/runtime-mobile-notification-controller.ts
  • src/main/runtime/runtime-service-command-surface.ts
  • src/main/startup/main-process-observers-hang-breadcrumb.test.ts
  • src/main/startup/main-process-observers.ts
  • src/main/startup/main-process-quit.ts
  • src/main/startup/main-process-state.ts
  • src/shared/desktop-client-presence.ts
  • src/shared/mobile-runtime-capabilities.ts
  • src/shared/rpc-contract/notifications-params.ts

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

Comment on lines +64 to +71
const entry = { socket: target.socket, away, at }
sent.set(target.environmentId, entry)
// Why: a refused report waits for the keepalive; only an unsent one retries on the next tick.
void target
.request('notifications.reportDesktopPresence', { away }, REPORT_TIMEOUT_MS)
.catch(() => {
if (sent.get(target.environmentId) === entry) {
sent.delete(target.environmentId)

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

Serialize presence reports per environment.

target.request('notifications.reportDesktopPresence', { away }, REPORT_TIMEOUT_MS) runs without ordering against earlier requests. Overlapping reports can therefore arrive out of order, so an older present report can overwrite a newer away state on the host. An away-only push during that stale present state is rejected and not retained for later delivery.

Order reports by environment and socket generation, or use an equivalent mechanism that prevents stale requests from overwriting newer presence.

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.

orca serve 1.4.237: onlyWhenDesktopAway filter is a no-op headless, so the phone buzzes while the desktop is in use

1 participant