Skip to content

proc: take a child's exit by asking too, not by SIGCHLD alone (from h04x3d's Mac fixes) - #1497

Merged
jlcjak merged 3 commits into
mainfrom
macos-sleep-guard
Nov 24, 2026
Merged

jlcjak merged 3 commits into
mainfrom
macos-sleep-guard

Conversation

@jlcjak

@jlcjak jlcjak commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

A macOS user (h04x3d) reported strange timeouts after the Mac had been asleep:

Their fork (h04x3d/Backplane, fix/macos-sleep) fixed two faults. This PR is now brought up to date with main (merge, not rebase) and takes everything in it that main doesn't already have.

Already on main, so taken from main

What this adds (h04x3d's child-exit fix, as a backstop)

  • proc::wait: asks try_wait every 5 ms, backing off to 250 ms, raced with tokio's cancel-safe wait(); whichever comes first wins.
  • proc::output: output() with the exit taken by proc::wait. Every git and sh call in files/git.rs goes through it.
  • proc::kill_and_reap / kill_wait: a killed child is reaped in the background, never dropped to tokio's orphan queue. Used by the account checks (RPC close, CLI calls, the Claude usage read, the sign-in flow).

Why it shouldn't break anything

  • Linux and Windows: wait() still answers first (pidfd / wait handle). The poll only adds a few timer wakes, capped at 4 a second, while a child runs. try_wait waits on that child's pid only, so it can't take another child's status.
  • Exit codes, output and timeouts are unchanged:
    • output() reads both pipes at once and then waits, as tokio's does.
    • It sets stdin to null as tokio's output() does, so a child that reads stdin can't hold it (tested). git calls already set null.
    • kill_on_drop still kills a git child whose read times out.
  • Waits stay bounded. Account-check waits keep their 2–3 s limits. A child not seen to exit by then is reaped in the background for up to a minute instead of being dropped.
  • macOS: this is h04x3d's own code from their fork, ported onto main's newer account code.

Testing

  • Hub tests for proc::, files::git, settings::accounts and guard:: all pass (188). They include h04x3d's test, extended for output()'s null stdin and kill_wait's limit.
  • Not run on a Mac. Mac users will tell us if anything is off.

Co-authored by h04x3d.

🤖 Generated with Claude Code

jlcjak and others added 3 commits November 20, 2026 22:05
A Mac user saw the hub restart overnight ("stopped answering", "start stalled for 1054 s")
and builds marked bad after the laptop slept. The hub stored each part's last good check by
the wall clock while its checks run on tokio's timers, which stop while the machine sleeps.
At a Power Nap DarkWake (about 2 s, every 15 minutes) every part looked hours old, the wake
was too short for the next check, and six wakes in a row ended a well hub. The guard
measured a start's stall by the phase file's wall-clock age, so a sleep counted as a stall.

- hub guard.rs: the last good checks are kept on the monotonic clock, as the timers are.
- guard run.rs: a start's stall is measured on Instant from the last change of the phase file.
- guard plan.rs SleepClock: the wall clock running >10 s past the monotonic one is a sleep;
  it resets the miss count, and a failed check within 30 s of a wake is logged, not counted.

Found and first fixed by h04x3d (fix/macos-sleep on their fork); taken as is, without that
branch's child-reaping part, which main covers since e16ae77 (#1456).

Tested: guard crate tests (45, incl. plan::a_sleep_is_told_from_a_hang_by_the_two_clocks),
hub guard:: tests (25). Not run on a Mac.

Co-authored-by: h04x3d <33473989+h04x3d@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	native/guard/src/plan.rs
#	native/guard/src/run.rs
#	native/host/src/guard.rs
…04x3d)

h04x3d's Mac hub missed SIGCHLD: git calls never returned (design-history
captures over 120 s, #1110), account checks got stuck (#1108), and the
Claude usage read left a zombie every five minutes. The root cause (a
signal mask inherited from the desktop app) was fixed in e16ae77, and
their sleep fix landed in main as 47c492c. This takes the rest of their
branch as a backstop, so a missed signal can no longer hang the hub.

- proc::wait: try_wait every 5 ms, backing off to 250 ms, raced with
  tokio's wait() (cancel-safe); whichever comes first wins.
- proc::output: output() with the exit taken by proc::wait. It sets stdin
  to null as tokio's output() does, so a child that reads stdin cannot
  hold it. Every git and sh call in files/git.rs goes through it.
- proc::kill_and_reap / kill_wait: a killed child is reaped in the
  background, never dropped to tokio's orphan queue. The account checks'
  closes, CLI calls, usage read and sign-in flow use them.

On Linux (pidfd) and Windows the poll only adds a few cheap timer wakes
while a child runs; wait() still answers first.

Tested: hub tests for proc::, files::git, settings::accounts and guard::
(188 pass), including the new
a_childs_exit_is_taken_without_sigchld_and_a_killed_child_is_reaped (stdin
null, a running child's exit, a killed child reaped, kill_wait within
its limit). Not run on a Mac.

Co-Authored-By: h04x3d <33473989+h04x3d@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jlcjak jlcjak changed the title guard: a sleeping Mac is no longer taken for a hung hub (from h04x3d's fork) proc: take a child's exit by asking too, not by SIGCHLD alone (from h04x3d's Mac fixes) Nov 24, 2026
@jlcjak
jlcjak marked this pull request as ready for review November 24, 2026 00:19
@jlcjak
jlcjak merged commit 425d5be into main Nov 24, 2026
8 checks passed
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.

1 participant