Skip to content

fix(agent-status): cap the live agent-status map to stop Windows renderer OOM (#9872) - #9936

Merged
nwparker merged 1 commit into
mainfrom
OrcaWin/bug-windows-renderer-oom-crash-exit-36861-after
Jul 22, 2026
Merged

nwparker merged 1 commit into
mainfrom
OrcaWin/bug-windows-renderer-oom-crash-exit-36861-after

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #9872.

The live agentStatusByPaneKey map had no size cap. Missed pane teardown events could leave heavy rows behind indefinitely, and every status ping spread-copied the entire map, eventually pushing the Windows renderer past V8's heap limit.

This change:

  • caps live agent-status rows at 500 by evicting panes that are provably gone, then stale or unprovable rows when needed;
  • never evicts rows for leaves present in a rooted live layout;
  • purges evicted pane keys from the related sleeping-session and launch-config maps;
  • bumps status and sort epochs when eviction changes the visible map;
  • adds regression coverage for dead-pane churn, live/rootless/headless panes, stale rows, hard-cap behavior, related-map cleanup, and eviction-only epoch updates.

Screenshots

No visual change.

Testing

  • pnpm lint — changed-file oxlint and the max-lines ratchet pass; the repository-wide command reaches an unrelated pre-existing switch-exhaustiveness error in src/renderer/src/components/skills/skill-freshness-group.tsx:101.
  • pnpm run typecheck:web
  • pnpm test — focused renderer-store and agent-status suites were run instead.
  • pnpm build — no build-surface change.
  • Added or updated high-quality tests that would catch regressions.

Focused results:

  • agent-status-live-map-leak.test.ts: 9/9
  • Agent-status and use-tab-agent suites: 192/192 across 15 files
  • Full renderer store suite: 1,901/1,901 across 121 files
  • Changed-file oxlint: clean
  • Max-lines ratchet: clean

AI Review Report

The review traced liveness classification, status-map ownership, teardown cleanup, stale-state handling, hard-cap fallback, epoch invalidation, and recovery-map persistence. It flagged two issues that were fixed: evicted pane keys now also clear sleepingAgentSessionsByPaneKey and agentLaunchConfigByPaneKey, and the epoch test now uses a same-state ping to an existing row so eviction is the only sort-relevant change.

Cross-platform and remote-workspace behavior were explicitly checked. The change is renderer-only in-memory state management with no keyboard shortcuts, labels, filesystem paths, shell behavior, Git commands, or Electron platform branches; it behaves identically on macOS, Linux, Windows, local, WSL, and SSH-backed workspaces.

Security Audit

No new external input handling, command execution, path handling, authentication, secrets, dependencies, or IPC surface is introduced. The cap operates on already-normalized in-memory agent-status entries. Eviction never removes a pane proven live by the rooted layout, and related recovery metadata is removed only for the exact pane keys evicted from the live map.

Notes

The 500-row limit is intentionally soft only when more than 500 panes are proven live by rooted layouts. Fresh rootless/headless rows are preserved when dead or stale rows can absorb overflow; the fallback sheds oldest unprovable rows only when required to contain memory growth.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The agent-status slice now exports a maximum live-status count, classifies pane entries using terminal layout state, and evicts dead or stale rows before applying a hard cap. Status writes remove related pane-key state and update epoch counters when eviction occurs. A regression suite covers dead-pane churn, live and special pane preservation, unprovable rows, stale ordering, under-cap behavior, and epoch increments.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR adds the bounded live-map eviction fix and regression tests that address the reported renderer heap leak and crash conditions.
Out of Scope Changes check ✅ Passed The changes stay focused on the agent-status slice and its regression tests, with no obvious unrelated scope added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise, specific, and accurately summarizes the main change: capping the agent-status map to prevent Windows OOM.
Description check ✅ Passed The description includes all required template sections and covers testing, review, security, and notes with relevant detail.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

🧹 Nitpick comments (1)
src/renderer/src/store/slices/agent-status-live-map-leak.test.ts (1)

240-252: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

This test doesn't actually isolate the eviction-triggered epoch bump.

setAgentAt(store, 'tab-live:dead-extra', ...) inserts a brand-new paneKey, so sortRelevantChange (!existing) is already true independent of eviction — agentStatusEpoch would bump here even without the new evictedOrphans disjunct. The assertion doesn't distinguish "new entry bumped it" from "eviction bumped it."

To isolate it, seed the map above cap via store.setState directly, then send a same-state/fresh ping to an existing paneKey (no other sort-relevant change) and assert the bump only happens because of eviction.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c1c27592-74a0-4acf-8bb3-86e7bdb61ca2

📥 Commits

Reviewing files that changed from the base of the PR and between 334027c and 88d0c57.

📒 Files selected for processing (2)
  • src/renderer/src/store/slices/agent-status-live-map-leak.test.ts
  • src/renderer/src/store/slices/agent-status.ts

…erer OOM (#9872)

The live `agentStatusByPaneKey` map had no size cap. `setAgentStatus` rewrites it
with a full spread copy on every status ping and keeps rows until a pane/tab
teardown event removes them; a missed teardown (agent killed without a Stop hook,
pane/tab closed while its status lingered) orphans a row forever. On long
multi-agent sessions orphaned heavy rows accumulate without bound, and because
each ping spread-copies the whole map, once it is ~1.9 GB one ping transiently
doubles it past the 3586 MB old-space limit -> renderer crash (exit -36861).

Cap the live map at MAX_LIVE_AGENT_STATUSES=500, shedding only rows whose pane is
provably gone (a mounted tab's rooted layout no longer lists the leaf) or long
idle, and never an open pane's row (any state, incl. needs-input waiting/blocked).
Rootless/empty-snapshot, not-yet-hydrated, and no-renderer-tab (orchestration
worker) rows are unprovable: kept while a fresh agent could own them, shed only
past the stale window or by a hard-cap fallback that guarantees the bound.
Eviction bumps the status/sort epochs so the retention sync snapshots disappeared
done rows. Cost is one Object.keys length check on the reducer's already-O(n)
spread under the cap; the layout walk + sweeps run only on the rare over-cap ping.
@nwparker
nwparker force-pushed the OrcaWin/bug-windows-renderer-oom-crash-exit-36861-after branch from 88d0c57 to 8651875 Compare July 22, 2026 20:54
@nwparker
nwparker merged commit 8f40419 into main Jul 22, 2026
1 check passed
@ironerumi

Copy link
Copy Markdown

it's on Mac but similar OOM issue

  • Report ID: 0408e819-a801-46db-89ca-89890fad7b54
  • IPS: Orca Helper (Renderer)-2026-08-10-143320.ips
  • IPS incident ID: 9D965418-DC3E-4BB5-8E87-43B1B2A7832C

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…erer OOM (stablyai#9872) (stablyai#9936)

The live `agentStatusByPaneKey` map had no size cap. `setAgentStatus` rewrites it
with a full spread copy on every status ping and keeps rows until a pane/tab
teardown event removes them; a missed teardown (agent killed without a Stop hook,
pane/tab closed while its status lingered) orphans a row forever. On long
multi-agent sessions orphaned heavy rows accumulate without bound, and because
each ping spread-copies the whole map, once it is ~1.9 GB one ping transiently
doubles it past the 3586 MB old-space limit -> renderer crash (exit -36861).

Cap the live map at MAX_LIVE_AGENT_STATUSES=500, shedding only rows whose pane is
provably gone (a mounted tab's rooted layout no longer lists the leaf) or long
idle, and never an open pane's row (any state, incl. needs-input waiting/blocked).
Rootless/empty-snapshot, not-yet-hydrated, and no-renderer-tab (orchestration
worker) rows are unprovable: kept while a fresh agent could own them, shed only
past the stale window or by a hard-cap fallback that guarantees the bound.
Eviction bumps the status/sort epochs so the retention sync snapshots disappeared
done rows. Cost is one Object.keys length check on the reducer's already-O(n)
spread under the cap; the layout walk + sweeps run only on the rare over-cap ping.

Co-authored-by: OrcaWin <[email protected]>
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]: Windows renderer OOM crash (exit -36861) after upgrading to 1.4.149 — heap climbs to limit within ~7 min under multi-agent + 5+ terminal tabs

3 participants