Skip to content

fix(notifications): detect Linux desktop lock and Wayland idle - #46985

Open
Mel-SRK wants to merge 4 commits into
stablyai:mainfrom
Mel-SRK:Mel-SRK/fix-linux-desktop-away
Open

Mel-SRK wants to merge 4 commits into
stablyai:mainfrom
Mel-SRK:Mel-SRK/fix-linux-desktop-away

Conversation

@Mel-SRK

@Mel-SRK Mel-SRK commented Nov 22, 2026

Copy link
Copy Markdown

ELI5

Phones set to receive alerts only when the desktop is away can now receive them when Orca's Linux desktop is locked or has had no input for three minutes on supported Wayland compositors.

What Changed

  • Read the graphical logind session's LockedHint and report lock transitions promptly. Resolve the session by PID and use XDG_SESSION_ID for desktop launches outside the graphical session scope. A wrapper in a private process group reaps the logind monitor when its parent pipe closes.
  • Use the existing bundled Wayland helper to subscribe to input-only idle and resume events at 180,000 ms on single-seat compositors advertising ext_idle_notifier_v1 v2. Electron supplies initial and fallback presence.
  • Use the same Linux activity state for local alerts and desktop presence reports to compatible relays.

Why

On the reported niri setup, logind shows a locked session while Electron reports active and zero idle time. The away-only filter then suppresses alerts. Logind supplies lock state and the Wayland v2 input-idle protocol measures keyboard and pointer inactivity independently of display idle inhibitors.

Linked Issue

Fixes #41341

Visual Proof

N/A

The change is to background alert eligibility. The issue includes the before-state Electron readings. The private niri probe produced these after-state relay decisions with Electron held at active/0. Before-state report

Desktop input state Away-only relay result
Active Suppress
Idle Allow
Input resumes Suppress
Idle again Allow

Testing

  • Independent review passed all 25 checks in pnpm check:changed --base=a817c50bd824 for the final logind wrapper change. On the preceding revision, the combined patch passed the 28-check gate and all five focused desktop-away tests. The implementation also ran the five focused tests on the final revision.

  • Independently ran the implementation's private D-Bus fixture with the production watcher and real gdbus under Bash and Ubuntu dash. Both runs verified the wrapper and monitor occupy a process group separate from the owner and checked session selection, lock transitions, parent-only SIGKILL, normal stop, cancellation during spawn, and cleanup after monitor exit.

  • In the preceding independent review, built the unchanged native helper with release warning and hardening flags. Seven Wayland protocol tests and the X11 clipboard fallback test on a private Xvfb display passed. The protocol tests cover the v2 input-only request, the 180,000 ms threshold, resume, parent EOF, and v1 or absent-protocol fallback.

  • Reran the implementation's isolated niri/Xvfb probe through Orca's relay delivery predicate in the preceding independent review. The probe verifies the production 180,000 ms argument and uses a shortened 1,200 ms timer in the private compositor. The implementation previously verified an x64 helper against the Ubuntu 20.04 glibc floor.

  • Full Linux packaging and arm64 execution remain unverified locally. The production build requires Docker and the local daemon is unavailable. Actual push gateway/APNs delivery to a paired iPhone still needs a separate end-to-end test.

  • I manually tested these changes locally

  • Automated tests added or updated

  • Added tests exercise lock transitions and the input-idle and relay-delivery invariants introduced by this change

Performance

Linux starts an event-driven logind monitor with a shell wrapper and, on supported Wayland desktops, one idle helper. The lock watcher makes bounded startup and property re-read calls. The existing relay sampling interval remains five seconds, with immediate reports on activity transitions.

Risk

Level: Medium. Linux session discovery or compositor compatibility can affect when away-only alerts are eligible. Unavailable sources fall back to Electron. The existing relay capability gate determines which remote runtimes receive presence reports. A revert restores the prior detection behavior without a data migration.

AI Disclosure

OpenAI Codex (GPT-6) assisted with implementation, independent review, and verification.

Review

An independent reviewer reproduced the monitor lifecycle issue on the earlier revision and verified the fix on this PR's head.

Agent skill upstream boundary

  • Not applicable

Notes

X11 clipboard regression coverage ran on a private display. The non-Linux state test exercises the macOS fallback. Windows was reviewed in code. Relay verification exercised the existing presence RPC and the away-only delivery predicate.

Checklist

  • This PR is focused on Linux desktop presence for away-only mobile alerts
  • Explained the user-facing change and rationale
  • Documented risk and rollback
  • Included behavioral evidence
  • Reviewed correctness, security, performance, and cross-platform/remote behavior
  • Local changed-files gate passed. Full builds and platform checks are for CI.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The native Wayland helper adds idle notifications and tests for idle, resume, and parent-pipe closure. Linux session-lock and Wayland-idle watchers now feed desktop-away state. Away-state changes trigger desktop presence updates. Startup supplies the helper path for Linux Wayland sessions, and the clipboard publisher uses the shared helper-path function.

Severity of issue fixed: Medium

Merge Risk: Moderate · up to f9051

On Linux AppImage installs, inherited loader paths can stop the new logind lock detection from working. The lock state is then not reported and away-only mobile alerts keep behaving as before. Passing the AppImage-cleaned environment to both logind subprocesses should be done before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main capabilities added: Linux desktop lock detection and Wayland idle detection. These match the changed files, which add logind LockedHint monitoring and a Wayland ext_idle_n…
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #41341), Visual Proof (N/A with reason and a before-state link), Testing, Performance, Risk wi…
Linked Issues check Passed Directly linked issue #41341 requires Linux presence detection that reports away when the session is locked, using logind LockedHint, because Electron reports active/0 on niri. The change set impl…
Out of Scope Changes check Passed The changes support the Linux desktop-away objective of #41341. wayland-clipboard.c adds wl_display_dispatch, a reusable get_registry helper, and a version parameter for bind. These changes ar…
Full details: Title check

Explanation

The title names the two main capabilities added: Linux desktop lock detection and Wayland idle detection. These match the changed files, which add logind LockedHint monitoring and a Wayland ext_idle_notifier_v1 idle watcher. The title follows the conventional commit style and is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #41341), Visual Proof (N/A with reason and a before-state link), Testing, Performance, Risk with level and rollback, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist. The Testing section is long and reports many verification runs that a reviewer cannot easily follow. The Performance section is written as a description rather than the required one-line sentence. The Risk section describes rollback as a plain revert. The Visual Proof section relies on a relay-decision table that is not a UI screenshot. These points are minor. The description is mostly complete.

Full details: Linked Issues check

Explanation

Directly linked issue #41341 requires Linux presence detection that reports away when the session is locked, using logind LockedHint, because Electron reports active/0 on niri. The change set implements this requirement. src/main/notifications/linux-session-lock.ts (added) resolves the graphical session by PID, falls back to XDG_SESSION_ID, and monitors LockedHint through gdbus monitor. src/main/notifications/desktop-away-state.ts reports away when the session is locked. subscribeDesktopAwayChanges and subscribeAwayChanges in desktop-presence-reporter.ts push lock transitions to the presence reporter immediately. The tests in desktop-away-state.test.ts cover lock and unlock transitions, unavailable session data, a missing LockedHint, and the non-Linux fallback. The issue's optional idle-hint suggestion is covered by the Wayland ext_idle_notifier_v1 input-idle watcher (linux-wayland-idle.ts, --watch-idle in wayland-clipboard.c), with 180,000 ms threshold tests in protocol_test.py. The issue's UI-wording and debugging suggestions are non-core and not required. Assessment relies on the supplied PR summary and the linked issue text. Source-level behavior was not independently re-read in this review.

Full details: Out of Scope Changes check

Explanation

The changes support the Linux desktop-away objective of #41341. wayland-clipboard.c adds wl_display_dispatch, a reusable get_registry helper, and a version parameter for bind. These changes are needed for the --watch-idle mode. electron-wayland-helper-path.ts centralizes helper path resolution. clipboard-text-publisher.ts uses that shared path, which is a refactor that keeps the existing legacy AppImage staging logic. native/wayland-clipboard/README.md documents the idle watcher and its test coverage. protocol_test.py tests the idle watcher. main-process-observers.ts passes the helper path only for Linux Wayland sessions. The clipboard publisher and README edits affect the shared helper packaging. The summary does not show a clipboard behavior change beyond path resolution. No unrelated change was identified.

  • 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

@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: fccf060f-62d4-426d-b2da-a14e37e47f21
Commits

Reviewing files that changed from the base of the PR and between f2f0cce and f90513e.

Files selected for processing: 11

  • native/wayland-clipboard/README.md
  • native/wayland-clipboard/protocol_test.py
  • native/wayland-clipboard/wayland-clipboard.c
  • src/main/host/electron-wayland-helper-path.ts
  • src/main/notifications/desktop-away-state.test.ts
  • src/main/notifications/desktop-away-state.ts
  • src/main/notifications/desktop-presence-reporter.ts
  • src/main/notifications/linux-session-lock.ts
  • src/main/notifications/linux-wayland-idle.ts
  • src/main/startup/main-process-observers.ts
  • src/main/window/clipboard/clipboard-text-publisher.ts

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

child = spawnProcess({
program: '/bin/sh',
args: ['-c', LOGIND_MONITOR_SCRIPT, 'orca-logind-monitor', LOGIN],
env: { ...process.env, LC_ALL: 'C' },

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.

Major · Data Integrity & Integration · Quick win

Pass the AppImage-cleaned environment to both logind subprocesses.

The logind monitor and the callLogind queries run host tools with the full app environment. Inside an AppImage, that environment can include APPDIR and LD_LIBRARY_PATH entries under the mount. Host gdbus and /bin/sh may then load bundled libraries. In that case the lock state is not reported, and Orca falls back to Electron's active state. The away-only alert problem in #41341 remains.

The Wayland idle watcher and other host-tool launches already use envWithoutAppImageRuntime. Use the same helper for both logind subprocesses.

Suggested fix

 const result = await runProcess({
   program: 'gdbus',
   args: [
     'call',
     ...
   ],
   maxOutputBytes: 4_096,
   timeoutMs: 1_500,
+  env: envWithoutAppImageRuntime(process.env),
   signal
 })
 child = spawnProcess({
   program: '/bin/sh',
   args: ['-c', LOGIND_MONITOR_SCRIPT, 'orca-logind-monitor', LOGIN],
-  env: { ...process.env, LC_ALL: 'C' },
+  env: envWithoutAppImageRuntime({ ...process.env, LC_ALL: 'C' }),
   detached: true,
   stdio: ['pipe', 'pipe', 'ignore']
 })

Add this import with the other module imports:

import { envWithoutAppImageRuntime } from '../pty/shell-startup/appimage-terminal-env'

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @Mel-SRK, the root cause (Electron's powerMonitor idle/lock reports active on niri/Wayland, so away-only pushes are always suppressed) is right. The fix is too large for us to land as a bug fix, though. It changes the native Wayland helper in C and adds a long-lived gdbus/logind subprocess wrapper, so it needs a design decision from the notifications owner. Holding it for now.

@Mel-SRK

Mel-SRK commented Nov 24, 2026

Copy link
Copy Markdown
Author

Thanks for the review. @Jinwoo-H, would you be open to splitting this into two changes?

  • For this PR, fix screen-lock detection by subscribing to logind’s LockedHint directly in Electron main and reusing the current desktop presence reporting. Is a small JS D-Bus dependency acceptable? The prototype needed no shell or gdbus monitor process and updated an in-process relay in 1.4–3.1 ms. A five-second polling prototype still missed alerts fired immediately after locking. A headless relay can still decide eligibility before the updated presence arrives. Would you be comfortable handling that ordering guarantee separately?
  • For unlocked idle, propose a separate PR linked to [Bug]: Linux/Wayland (niri): "only when desktop is away" suppresses all mobile pushes; powerMonitor reports active/0 while logind says LockedHint=yes #41341 using Wayland v2’s input-only idle events. It would cover three minutes without keyboard or mouse input and resume on input. Would you prefer reusing the existing Wayland helper or keeping this in a dedicated helper?

Once we agree on the lock path, I’ll narrow this PR and update it against current main.

This branch has not been deployed

No deployments
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.

[Bug]: Linux/Wayland (niri): "only when desktop is away" suppresses all mobile pushes; powerMonitor reports active/0 while logind says LockedHint=yes

2 participants