Repository navigation
fix(agent-status): cap the live agent-status map to stop Windows renderer OOM (#9872) - #9936
Conversation
📝 WalkthroughWalkthroughThe 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)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
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 winThis test doesn't actually isolate the eviction-triggered epoch bump.
setAgentAt(store, 'tab-live:dead-extra', ...)inserts a brand-new paneKey, sosortRelevantChange(!existing) is alreadytrueindependent of eviction —agentStatusEpochwould bump here even without the newevictedOrphansdisjunct. The assertion doesn't distinguish "new entry bumped it" from "eviction bumped it."To isolate it, seed the map above cap via
store.setStatedirectly, 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
📒 Files selected for processing (2)
src/renderer/src/store/slices/agent-status-live-map-leak.test.tssrc/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.
88d0c57 to
8651875
Compare
|
it's on Mac but similar OOM issue
|
…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]>
Summary
Fixes #9872.
The live
agentStatusByPaneKeymap 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:
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 insrc/renderer/src/components/skills/skill-freshness-group.tsx:101.pnpm run typecheck:webpnpm test— focused renderer-store and agent-status suites were run instead.pnpm build— no build-surface change.Focused results:
agent-status-live-map-leak.test.ts: 9/9use-tab-agentsuites: 192/192 across 15 filesAI 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
sleepingAgentSessionsByPaneKeyandagentLaunchConfigByPaneKey, 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.