Skip to content

fix(linux): refuse realtime audio scheduling under an inherited zero RLIMIT_RTTIME - #36183

Merged
nwparker merged 6 commits into
mainfrom
crash/s61-linux-rttime-zero
Nov 3, 2026
Merged

nwparker merged 6 commits into
mainfrom
crash/s61-linux-rttime-zero

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​269 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​267
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​162 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​146

Description

What users saw (Linux, mostly Omarchy): the Orca window goes blank or reloads. The crash report says Renderer process gone { reason: 'killed', exitCode: 9 }, meaning the kernel sent SIGKILL. The affected sessions inherit a hard RLIMIT_RTTIME of 0/0 from a launcher that runs without rtkit.

Root cause (one confirmed path): Chromium moves its realtime-audio threads to SCHED_RR (priority 8) whenever RLIMIT_RTPRIO allows it. The affected threads are the renderer's AudioOutputDevice thread (<audio>, <video>, WebAudio) and the audio-service thread. Chromium has no switch to turn this off. With a hard RLIMIT_RTTIME of 0, the kernel's RT watchdog finds rttime(0) >= hard(0) on the first tick and SIGKILLs the process. So anything that plays sound kills the renderer within milliseconds: a custom agent-finished notification sound, media in a browser pane, video, or dictation.

What this PR changes:

  • Supersedes fix(crash): name an inherited zero realtime limit when Linux kills Orca's GPU or renderer #35984: its two commits are included here, so fix(crash): name an inherited zero realtime limit when Linux kills Orca's GPU or renderer #35984 can be closed once this merges. That PR names the inherited zero RLIMIT_RTTIME in Linux SIGKILL reports and adds the linux_rttime_limit breadcrumb.
  • src/main/linux-rttime-limit.ts: adds a shared /proc/self/limits reader and allowsRealtimePriority(), which is true when the soft or hard RLIMIT_RTPRIO is non-zero.
  • New src/main/startup/linux-realtime-scheduling-guard.ts (refuseRealtimeSchedulingUnderZeroRtTime):
    • Runs only on Linux, only when RTTIME is 0 and RTPRIO is above 0.
    • Walks main's current process tree through /proc/<pid>/task/*/children. This covers the zygotes, GPU and utility processes; later renderers fork from the zygotes.
    • Runs prlimit --pid <pid> --rtprio=0:0 on each process, async through runProcess.
    • Afterwards sched_setscheduler returns EPERM and Chromium falls back to a nice value.
    • Records {soft, hard, rtPrio: lowered | lowered-partial-tree | not-needed | prlimit-failed} in the breadcrumb. lowered-partial-tree means prlimit succeeded but a live thread's children list could not be read (e.g. a kernel without CONFIG_PROC_CHILDREN), so the breadcrumb does not claim zygotes it never saw were lowered.
    • Keeps the startup outcome so later Linux process-gone reports carry it, since the startup breadcrumb rotates out of the 30-entry ring before a late SIGKILL.
    • Never rejects.
  • main-process-ready-runtime.ts: awaits the guard at the start of initializeReadyRuntimeServices, before any window exists.
  • Guard unit tests: lowered, lowered when a short-lived child exited before its prlimit ran, lowered-partial-tree when children could not be enumerated, prlimit exits non-zero, prlimit missing, RTPRIO already 0, RTTIME not zero, off Linux. Process-tree walk tests cover breadth-first traversal, exited processes, and an unreadable children list.

Scope (please read): this fixes only the RLIMIT_RTPRIO > 0 path. On the Omarchy box we can test, RTPRIO is 0/0, and real Orca never went realtime or armed a CPU timer there. Kills on RTPRIO=0 machines (heavy renderer CPU, one renderer killed 2.6 s after load) still have an unidentified trigger, so keep that crash bucket open. The new rtPrio breadcrumb field will show which reporters have RTPRIO above 0. The full fix for affected users is still Omarchy #16824 or installing rtkit.

Fix evidence

Rig: omarchy (kernel 7.2.5-3-omarchy, no rtkit).

  • Real Orca v1.4.244 from the release AppImage, extracted.
  • Xvfb with ORCA_BACKGROUND_LAUNCH=1 and an isolated HOME and user-data.
  • Run as uid 1000 in the host namespaces through docker (nsenter -t 1 -m + setpriv), with the real sandbox on.
  • An LD_PRELOAD shim logs sched_setscheduler, timer_create and setrlimit.
  • Workload per run: <audio> + WebAudio x3, then one recorded <video>.

1. Mechanism observed in real Orca (host limits, RTPRIO 0): on every playback the browser calls sched_setscheduler(tid, SCHED_RR=2) on the renderer AudioOutputDevice thread and on the audio-service thread:

RT_SHIM ... thread=ThreadPoolSingl sched_setscheduler a=2 b=<tid> rc=-1   (EPERM, RTPRIO 0)

2. Kernel check (rr_probe.c in docker):

--ulimit rtprio=95 --ulimit rttime=0:0   -> sched_setscheduler(SCHED_RR,8) rc=0 ok ; Killed exit=137
rttime unlimited / 200000                -> survived 3 s
host rtprio 0 + prlimit --rttime=0:0     -> rc=-1 Operation not permitted ; survived

3. Same v1.4.244 binary, before and after (RTPRIO 95/95, RTTIME 0:0). The "after" binary differs only in out/main/index.js: a faithful JS port of this guard, injected at the same point and awaited, with the asar round-trip checked with cmp.

== SF-base (stock)  rtprio=95 rttime=0:0
main limits: priority=95/95 timeout=0/0
audio#1..3: undefined   video: undefined
SCHED_RR attempts: 4 rc=0
kills: 4
[window] Renderer process gone; close confirmation will be bypassed { reason: 'killed', exitCode: 9 }   (x4)

== SG-mit-ready (guard)  rtprio=95 rttime=0:0
[s61-guard] ready-time RLIMIT_RTPRIO pids 3793999,3794017,3794018,3794078,3794074,3794020: lowered
main limits: priority=0/0 timeout=0/0
audio#1..3: "audio-element:playing webaudio:running"
video: "video:played 1"
SCHED_RR attempts: 6 rc=-1
kills: 0

Controls, all 0 kills:

Run Build RTPRIO RTTIME SCHED_RR attempts Kills
SC-base-unl stock 95 unlimited 6, rc=0 0
SD-base-rtprio0 stock 0 0:0 6, rc=-1 0
SE-mit-unl / SH-mit-ready-unl guard 95 unlimited 6, rc=0 0

In the last row the guard does nothing (no guard line, RR still succeeds). It changes nothing when RTTIME is not 0.

Earlier runs:

  • Sync preflight variant, --no-sandbox (A-base/B-mit): 4 kills became 0.
  • Sandboxed (SA-base/SB-mit): 4 kills became 0. prlimit worked across the sandboxed zygote's user namespace (4 pids lowered).

Local checks:

  • pnpm check:changed --maxWorkers=2 after rebasing on origin/main: 21 of 22 checks passed (format, lint, typecheck, ratchets including sync-spawn, import boundaries).
  • The failing check is unit tests, and it fails for a local reason. In this worktree every vitest file fails to load with [TSCONFIG_ERROR] Failed to load tsconfig '@electron-toolkit/tsconfig/tsconfig.node.json', a pnpm global-store link problem. That includes files this PR does not touch (for example the orchestration/federation/* suites), and the investigation worktree on main fails the same way.
  • An earlier run passed the 5/5 new guard tests and the daemon rttime tests.
  • CI on this PR is the source of truth for unit tests.

ELI5

Linux has a rule: "if a thread asks to be a VIP (realtime), it gets a stopwatch, and when the stopwatch runs out it is thrown out." Some Omarchy setups set that stopwatch to zero seconds. Chromium always asks for VIP status for its sound threads. So the moment Orca plays any sound, the stopwatch is already at zero and the kernel kills the window.

This PR checks for that situation at startup. If it finds it, Orca gives up its right to ask for VIP status. Sound threads then run as normal high-priority threads, with no stopwatch, so nothing gets killed.

Trade-offs

  • Only in the affected setup (Linux, RLIMIT_RTTIME 0 and RLIMIT_RTPRIO above 0): Orca's audio threads run at a nice value instead of SCHED_RR, so audio could glitch under heavy CPU load. Today those threads are killed outright.
  • Children inherit RTPRIO 0: processes Orca starts later (terminals, and the daemon if this Orca spawns it) get RTPRIO 0. A pro-audio tool started in an Orca terminal cannot get realtime scheduling there. Under the inherited zero RTTIME it would be SIGKILLed anyway.
  • Needs prlimit: it relies on util-linux prlimit being on PATH. If it is missing, the guard does nothing and records rtPrio=prlimit-failed.
  • Startup cost: a few ms of prlimit spawns before the first window, only on affected machines. Everywhere else the cost is one /proc/self/limits read.
  • Small race: a renderer forked during the short async prlimit window could keep RTPRIO above 0. This is unlikely because the guard runs before any window.
  • Not a full fix: it does not help machines with RTPRIO 0, whose kills come from a trigger not yet identified. The bucket stays open.

Adversarial review

2 loops, each with a fresh reviewer subagent. Final verdict: clean.

  • Loop 1, not clean, 1 P1: the reviewer found the code correct:

    • The guard is awaited before any window.
    • The /proc children walk reaches the zygotes.
    • Same-uid prlimit lowering needs no privilege.
    • sched_setscheduler checks the target thread's RTPRIO.
    • There is no sync spawn and no impact on macOS, Windows, remote or folder workspaces.

    The P1 was that the evidence did not cover the reported bucket: the testable box has RTPRIO 0, and the audio SCHED_RR kill had not been reproduced in real Orca with RTPRIO above 0.

    Fixed: the kill was reproduced in real Orca v1.4.244 with RTPRIO 95 and RTTIME 0:0 (SF-base: 4 kills with exit 9). The guarded binary showed 0 kills (SG-mit-ready), and the controls are in the table above. The guard docs and this PR were also rescoped to the RTPRIO > 0 path (commit docs(linux): scope the realtime guard…), and the bucket stays open for RTPRIO 0 reporters.

  • Loop 2, clean, no P0 or P1: the reviewer checked:

    • The mechanism against Chromium's platform_thread_linux.cc (kRealtimeAudio uses SCHED_RR, 8, then falls back to a nice value).
    • The A/B logs.
    • The ordering before the first window, the coverage of the tree walk, the use of runProcess, and that it does nothing off Linux.

    Notes below the P1 bar: the fork race during the async window; without CONFIG_PROC_CHILDREN only main would be lowered (Arch enables it); a setuid sandbox helper could make the breadcrumb say prlimit-failed even when the zygote was lowered.

@OrcaWin

OrcaWin commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator Author

Crash scan 63 (v1.4.245, 9 Omarchy SIGKILL reports from 6 users, GPU process usually killed first): the "unidentified trigger on RTPRIO=0 machines" is most likely kernel RCU priority boosting (Omarchy kernels: CONFIG_PREEMPT_RCU=y, CONFIG_RCU_BOOST=y, boost delay 500 ms).

  • A thread preempted inside an RCU read section that blocks a grace period gets boosted via rt_mutex_setprio into the RT class (prio 98). No sched_setscheduler call is involved, so RTPRIO=0 does not prevent it.
  • With an inherited hard RLIMIT_RTTIME of 0/0, the next tick in the boosted window hits check_thread_timers → SIGKILL (SI_KERNEL, sent from posix_cpu_timers_work).
  • Harness on omarchy (bpftrace): an unprivileged RTPRIO=0 process was killed with exit 137 after 7 s and 11 s under rttime=0:0, and exited 0 after 44 s twice with rttime unlimited. Trace: PIBOOST ... by rcub prio=98 → KILL ... posix_cpu_timers_work.
  • Real Orca 1.4.245: Chromium IO threads are preempted inside RCU readers about 17k times per 30 s (unix_stream_sendmsg -> sock_def_readable on Mojo sends). The GPU IO thread carries the most IPC, which fits the GPU-first kills. We also saw Orca threads RCU-boosted to prio 98 (during teardown). We did not reproduce an end-to-end Orca kill on this box.
  • Ruled out: CPU timers, SCHED_RR/FIFO/DEADLINE calls, Mesa, the GPU watchdog, display-critical threads, memory, and self tree-kill.

This PR is still correct, but it only covers part of the problem. The only Orca-side fix for the whole class would be a Linux startup self-relaunch as a systemd-run --user --collect service when hard RTTIME is 0. A transient service gets the user manager's unlimited RTTIME; verified that a --scope still has 0/0. That changes startup in a product-visible way, so it needs an owner decision. The user-side fix stays the same: omarchy-update (omacom/omarchy#16824) or install rtkit, then log in again.

@nwparker
nwparker force-pushed the crash/s61-linux-rttime-zero branch from 6494f34 to 2a0388d Compare November 3, 2026 05:17
m4air and others added 6 commits November 2, 2026 21:25
…orts

Omarchy launches apps from a shell that holds a hard RLIMIT_RTTIME of 0
(no rtkit, so the portal's zero realtime budget is applied by PipeWire
module-rt). Orca inherits it in every process, and the kernel CPU-timer
watchdog SIGKILLs GPU and renderer processes with no dump while GBs of
memory are free. A hard limit cannot be raised without privilege, so
record it as a startup breadcrumb and in process-gone crash details.

Move the daemon's /proc/self/limits parser into one shared reader so the
terminal warning and crash attribution flag the same zero soft or hard
limit.
…_RTTIME

Chromium makes audio threads SCHED_RR whenever RLIMIT_RTPRIO allows. Under a
zero hard RLIMIT_RTTIME (Omarchy launcher without rtkit) the kernel's RT
watchdog SIGKILLs that renderer or audio process on its first tick, so any
sound (custom notification sound, browser media, video) killed the renderer
with exit 9. When RTTIME is 0 and RTPRIO is nonzero, zero RLIMIT_RTPRIO with
prlimit for main and its existing zygotes before the first window; Chromium
then falls back to a nice value. The linux_rttime_limit breadcrumb records the
outcome.
… was shown to fix

Evidence (Electron 43.8.1 linux-arm64, the version Orca ships, in Docker
with --ulimit rtprio=95:95; page plays a WebAudio oscillator; guard step is
the same /proc tree walk + `prlimit --pid <pid> --rtprio=0:0` as this module):

  rttime unlimited:      AudioOutputDevi / AudioWorkerThre go SCHED_RR prio 8,
                         renderer survives 6 s
  rttime 0:0, no guard:  "audio started" -> render-process-gone killed 9 (~80 ms)
  rttime 0:0, guard:     "guard lowered rtprio on 5 pids", no RR threads,
                         audio keeps running, renderer survives 6 s

Limits: this is a minimal Electron app, not a packaged Orca build. The only
reachable Omarchy box has RTPRIO 0/0 and RTTIME unlimited, and an
unprivileged user cannot raise RTPRIO there. Under RTPRIO 0/0 the guard
records rtPrio=not-needed and changes nothing, so reported zero-RTTIME
SIGKILLs on such machines (for example the one 2.6 s after load with no
audio breadcrumb) have a different trigger. Treat this as a partial
mitigation plus diagnostics; the crash bucket stays open.
…ess tree can't be fully walked

listProcessTree silently skipped unreadable /proc/<pid>/task/<tid>/children files,
so on kernels without CONFIG_PROC_CHILDREN the guard lowered only the main process
yet recorded rtPrio 'lowered'. Track whether any live thread's children list was
unreadable and report 'lowered-partial-tree' in that case. Tests now use a fake
/proc root so tree walking is deterministic on any host.
The linux_rttime_limit breadcrumb rotates out of the 30-entry ring long
before a late SIGKILL, so stash the guard's outcome and attach it as
rlimitRtPrioStartup next to the rlimitRtTime fields. A short-lived child
that exits between the /proc walk and its prlimit call no longer turns
the outcome into prlimit-failed. Adds direct tests for the rttime/rtprio
readers and the new crash-detail fields.
@nwparker
nwparker force-pushed the crash/s61-linux-rttime-zero branch from 2a0388d to 6e05777 Compare November 3, 2026 05:26
@nwparker
nwparker marked this pull request as ready for review November 3, 2026 05:46
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

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 11 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: 475da8f0-9bb2-43c3-8d2f-043a925c5e47
Commits

Reviewing files that changed from the base of the PR and between bff4e36 and 6e05777.

Files selected for processing: 8
  • src/main/crash-reporting/process-gone-diagnostics.test.ts
  • src/main/crash-reporting/process-gone-diagnostics.ts
  • src/main/daemon/daemon-rttime-limit.ts
  • src/main/linux-rttime-limit.test.ts
  • src/main/linux-rttime-limit.ts
  • src/main/startup/linux-realtime-scheduling-guard.test.ts
  • src/main/startup/linux-realtime-scheduling-guard.ts
  • src/main/startup/main-process-ready-runtime.ts
  • 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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

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.

2 participants