Skip to content

feat(daemon): process-growth breaker that pauses automatic restores - #27437

Merged
OrcaWin merged 3 commits into
mainfrom
np/d1-growth-breaker
Oct 11, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
np/d1-growth-breaker

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​209 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​436 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​417

ELI5

A restore storm does not have to come from Orca starting too many agents. It can come from agents that are already running, when each one starts helper processes that start more processes. This PR watches how many processes each terminal has under it. When one terminal's processes keep multiplying fast, Orca stops starting new agents automatically and writes down which terminal caused it. It never kills anything.

What Changed

Stacked on #27433. Review only the top commit.

  • Before: the host had no idea how many processes its terminals had spawned. An agent whose hooks forked thousands of children (the pattern in [Bug]: macOS — unbounded agent process growth panics the kernel (watchdogd timeout); RunAtLoad+KeepAlive turns it into a reboot loop #10493) went unnoticed until the machine fell over.
  • After: the terminal daemon samples its descendant process tree, per terminal and in total.
    • When: every 5 s while automatic restores started in the last 10 minutes. Every 30 s otherwise on headless hosts. Only around restores on the desktop, which only observes.
    • How: POSIX reads the existing ps process table in a child process, never on a hot path. Windows uses the native process table, with no PowerShell.
  • Trip condition: any terminal, or the host as a whole, grows by 40 or more processes a second over at least three consecutive rising samples spanning 10 s or more.
    • One long sampling interval is never enough evidence. A rising tree switches the monitor to 5 s samples to confirm it.
    • A high total (1,500 descendants) is reported as elevated load and never trips on its own, because many busy agents can reach it with no storm.
  • When it trips, on headless hosts (which enforce), the breaker:
    • pauses automatic work for the rest of this daemon run. It stays paused even after the storm, per the owner's decision Q3 (stop admitting and alert, never kill). It is kept in memory on purpose: nothing can resume a recorded pause yet, so the breaker writes nothing to disk.
    • reports the host as critical while the storm lasts. Declared automatic restores are deferred. Undeclared ones (all current callers) wait out the storm for their admission window and are refused only if it outlasts that window. The refusal is the distinct terminal_spawn_refused error, never the "daemon gone" message.
    • logs process-growth-breaker-tripped, naming the terminals whose trees grew (by session id suffix), their counts, and their rates.
  • On the desktop (which observes), a trip is only logged.
  • What keeps working: interactive shells, user resumes, attach, list and cancel are never blocked.

Mechanism:

  • src/shared/process-growth-breaker.ts is a pure breaker. Its state is keyed by scope: one scope per terminal tree today, plus the host.
  • An unreadable table is unknown, which never trips and never resets a streak.
  • DaemonAutomaticWorkGuard gathers the fork gate, the crash marker and the growth monitor in one place, so DaemonServer wires one object.

Why

This is the "growth breaker" for #10493.

  • Why pacing is not enough: pacing restores bounds how fast agents start, not what they do afterwards. The [Bug]: macOS — unbounded agent process growth panics the kernel (watchdogd timeout); RunAtLoad+KeepAlive turns it into a reboot loop #10493 panic came from descendants of agents that had already been admitted.
  • Why per terminal: a storm is almost always one agent's hook loop. Naming that terminal makes the alert actionable. It also gives a later per-agent OS ceiling (decision Q4, follow-up) the exact scope to act on. The software breaker is the guarantee everywhere, including SSH, WSL and container hosts where no OS scope is available.
  • Why it never kills: decision Q3. The breaker stops new automatic work; agents the user is running keep running.

Linked Issue

Refs #10493

Visual Proof

N/A: no UI change yet. Today the trip shows up in the daemon log, and the paused state is enforced only for clients that declare intent (the client PR adds the visible state and the Resume control).

Testing

  • Automated tests added/updated
  • process-growth-breaker.test.ts: covers the following.
    • Three rising samples over 10 s trip and name the agent that grew; a quiet sibling is not named.
    • One long interval never trips.
    • Growth stopping resets the streak.
    • A high total is elevated, never a trip.
    • An unreadable table is unknown and neither trips nor resets.
    • Per-root counting tolerates pid cycles.
  • daemon-automatic-work-guard.test.ts: covers the following.
    • A simulated storm under one agent's shell pauses automatic work for the run and logs that agent.
    • It writes no recorded pause.
    • An observe-only host only logs.
  • terminal-spawn-gate.test.ts: covers the following.
    • An undeclared restore waits out a storm and goes ahead once it clears.
    • It is refused (terminal_spawn_refused) only past its deadline.
    • A declared restore is deferred with pressure.
  • pnpm tc, pnpm lint, pnpm run check:code-quality:changed and the daemon and shared suites pass.

Review

Agent skill upstream boundary

  • Not applicable

Notes

  • Mixed versions: no wire change. A preserved old daemon has no breaker until it restarts.
  • SSH: orcad on an SSH host samples that host's own tree. Remote processes are never counted locally.
  • WSL: processes inside the WSL VM are invisible to the Windows host's table, so a WSL storm reads as quiet there. That is not counted as protection; the Linux-side daemon (orcad in the distro) is where it applies.
  • Windows: native process table only. No PowerShell, -EncodedCommand or WMI.
  • Folder workspaces: covered (keyed on terminal process trees).
  • Execution boundary: the breaker never reports a terminal as exited and never signals a process.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered
  • pnpm lint, pnpm typecheck, and focused tests pass locally; CI covers the rest

@OrcaWin
OrcaWin force-pushed the np/d1-growth-breaker branch from 9ad27be to 47ae7cb Compare October 11, 2026 09:35
@OrcaWin
OrcaWin force-pushed the np/d1-growth-breaker branch from 6656248 to 128b7cc Compare October 11, 2026 10:02
@OrcaWin
OrcaWin changed the base branch from np/d1-crash-pause to main October 11, 2026 10:21
@OrcaWin
OrcaWin force-pushed the np/d1-growth-breaker branch from 128b7cc to 4f6683d Compare October 11, 2026 10:21
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e56eb342-64dc-4ba5-a06b-f93b9fb5e914

📥 Commits

Reviewing files that changed from the base of the PR and between 398cb84 and 4f6683d.


📒 Files selected for processing (10)
  • src/main/daemon/daemon-automatic-work-guard.test.ts
  • src/main/daemon/daemon-automatic-work-guard.ts
  • src/main/daemon/daemon-process-growth-monitor.ts
  • src/main/daemon/daemon-server.ts
  • src/main/daemon/terminal-spawn-gate.test.ts
  • src/main/daemon/terminal-spawn-gate.ts
  • src/shared/host-spawn-admission.test.ts
  • src/shared/host-spawn-admission.ts
  • src/shared/process-growth-breaker.test.ts
  • src/shared/process-growth-breaker.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.



📝 Walkthrough

Walkthrough

The change adds shared process-growth evaluation and descendant counting, plus a daemon monitor that samples process rows and reports pressure levels and trips. A daemon guard connects the monitor to the run marker and terminal spawn gate. Spawn admission now waits under critical pressure for undeclared requests until their deadline, while declared requests defer. Tests cover growth evaluation, pressure-dependent admission, and guard behavior in enforcement and observe-only modes.


Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 4f668

The change adds a breaker that pauses automatic restores during process storms. It does not kill processes or block interactive actions. No actionable merge-blocking risk was found in the supplied context.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the change, rationale, behavior, testing, and platform considerations. However, the Linked Issue section contains only "Refs #10493" while the template requires … Replace "Refs #10493" with a valid linked issue reference, such as "Fixes #10493", and ensure the referenced issue is linked in the pull request. Also confirm that the required build check passes or state that CI covers it.
Docstring Coverage Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the main change: adding a daemon process-growth breaker that pauses automatic restores.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Full details: Description check

Explanation

The description is detailed and covers the change, rationale, behavior, testing, and platform considerations. However, the Linked Issue section contains only "Refs #10493" while the template requires an actual issue link or Fixes reference.


  • Fix all pre-merge checks with AI
✨ 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.

@OrcaWin
OrcaWin merged commit c2624ab into main Oct 11, 2026
44 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