Skip to content

perf(sleep): park idle agents in the worktree you are working in (#16211) - #16591

Merged
nwparker merged 1 commit into
mainfrom
nwparker/win-16211-hibernate-active-worktree
Aug 26, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/win-16211-hibernate-active-worktree

Conversation

@nwparker

@nwparker nwparker commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

Recommendation: close this in favour of #16214 by @sanshengai. See "Review" at the bottom. Kept open only so the comparison is on the record.

ELI5

Orca can put idle, finished agent panes to sleep to save memory. It was skipping every pane in the worktree you're currently looking at — including background tabs you haven't touched in hours. On a 16 GB Windows machine that's exactly where the memory piles up. Now only the tab actually on screen (and one you left recently) is protected.

What Changed

Removed worktreeId === snapshot.activeWorktreeId from the planner's skip condition, so the existing per-tab foreground guard applies to every worktree.

Why

planAgentHibernationCandidates skipped the whole active worktree:

if (!worktreeId || worktreeId === snapshot.activeWorktreeId || tabs.length === 0) {

The reporter in #16211 keeps four long-lived product worktrees with 1–3 agent tabs each and works in one of them. Sibling-tab idle already worked for the inactive trees; the active one — the one accumulating idle Codex/Grok panes and their MCP descendants — was exempt wholesale.

Removing it is safe because the two remaining guards are the more precise boundary and both already existed: foregroundTerminalTabIds covers the tab on screen, and the foregroundTerminalLastSeenAtByTabId floor in getEligiblePane is anchored to the end of a foreground visit, so a tab left inside the idle window cannot be parked. Everything else in getEligiblePane is untouched.

Linked Issue

Addresses #16211 (the hibernation half). The diagnostics half is #16589.

Visual Proof

N/A — no UI change. Behaviour is a background scheduler decision; covered by unit tests instead.

Testing

  • pnpm test src/renderer/src/lib src/renderer/src/store → 755 files / 7310 passed.

  • pnpm tc clean.

  • I manually tested these changes locally

  • Automated tests added/updated

Review

Two review findings, both material, and together they change my recommendation:

1. A repo-wide pnpm format had leaked into this commit — 32 files touched for a 6-file change, rewriting three canonical skill guides without regenerating their bundled artifacts. Confirmed P1 under adversarial verification. Fixed: the branch is rebuilt on origin/main as a single 6-file commit.

2. My added tests were vacuous. They used worktree wt-bg while the fixture's activeWorktreeId was wt-active, so the worktree was never the active one and the tests passed unchanged against pre-fix code. Worse, I had removed activeWorktreeId from the planner snapshot — which makes the pre-fix condition impossible to express in a test at all.

@sanshengai's #16214 does this correctly and did it first. Same one-line planner change, but it keeps activeWorktreeId on the snapshot and sets it to the worktree under test inside the existing sibling-tab regression — one added line, and it genuinely fails against pre-fix code. That is smaller and strictly stronger than what I wrote.

So: merge #16214, close this. If the now-dead activeWorktreeId field is worth removing, that belongs in a separate follow-up after a non-vacuous test exists — not bundled with the behaviour change that needs it.

Credit: @sanshengai identified and fixed this exact root cause first in #16214, against issue #16211's own proposed slice 3. They are also working the same #16211 umbrella from the orchestration side in #16217 (auto-releasing completed worker terminals), which is complementary and fills a gap none of my PRs address.

@nwparker
nwparker force-pushed the nwparker/win-16211-hibernate-active-worktree branch from 5d4d6d0 to c215861 Compare August 26, 2026 09:40
The planner skipped the entire activeWorktreeId, so the tree a user actually
works in never parked anything — exactly where a 16 GB Windows host
accumulates its idle Codex/Grok panes and starts hard-paging (#16211).

The two guards that remain are the correct granularity and already existed:
foregroundTerminalTabIds covers the tab on screen, and the
foregroundTerminalLastSeenAtByTabId floor in getEligiblePane holds any tab
left inside the idle window.

Test lever taken from @sanshengai's #16214, which found this first: pinning
the existing sibling-tab regression to activeWorktreeId means it fails against
the pre-fix planner. A standalone background-worktree case does not, because
the fixture's active worktree is a different one — that is why the first cut of
this change shipped a vacuous test.

#16214 changed only the planner suite; the same one-line change also breaks
agent-hibernation-coordinator's two revalidation tests, which used
activeWorktreeId as their eligibility lever. Those now flip
setForegroundTerminalTabIds instead, which is the property they were written
to prove.

Co-authored-by: sanshengai <[email protected]>
@nwparker
nwparker marked this pull request as ready for review August 26, 2026 10:11
@nwparker
nwparker force-pushed the nwparker/win-16211-hibernate-active-worktree branch from c215861 to 9de1fbb Compare August 26, 2026 10:11
@nwparker
nwparker merged commit e2cb797 into main Aug 26, 2026
1 check passed
@nwparker
nwparker deleted the nwparker/win-16211-hibernate-active-worktree branch August 26, 2026 10:11
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…blyai#16591)

The planner skipped the entire activeWorktreeId, so the tree a user actually
works in never parked anything — exactly where a 16 GB Windows host
accumulates its idle Codex/Grok panes and starts hard-paging (stablyai#16211).

The two guards that remain are the correct granularity and already existed:
foregroundTerminalTabIds covers the tab on screen, and the
foregroundTerminalLastSeenAtByTabId floor in getEligiblePane holds any tab
left inside the idle window.

Test lever taken from @sanshengai's stablyai#16214, which found this first: pinning
the existing sibling-tab regression to activeWorktreeId means it fails against
the pre-fix planner. A standalone background-worktree case does not, because
the fixture's active worktree is a different one — that is why the first cut of
this change shipped a vacuous test.

stablyai#16214 changed only the planner suite; the same one-line change also breaks
agent-hibernation-coordinator's two revalidation tests, which used
activeWorktreeId as their eligibility lever. Those now flip
setForegroundTerminalTabIds instead, which is the property they were written
to prove.

Co-authored-by: sanshengai <[email protected]>
rahuljangirworks pushed a commit to rahuljangirworks/veer that referenced this pull request Aug 27, 2026
…blyai#16591)

The planner skipped the entire activeWorktreeId, so the tree a user actually
works in never parked anything — exactly where a 16 GB Windows host
accumulates its idle Codex/Grok panes and starts hard-paging (stablyai#16211).

The two guards that remain are the correct granularity and already existed:
foregroundTerminalTabIds covers the tab on screen, and the
foregroundTerminalLastSeenAtByTabId floor in getEligiblePane holds any tab
left inside the idle window.

Test lever taken from @sanshengai's stablyai#16214, which found this first: pinning
the existing sibling-tab regression to activeWorktreeId means it fails against
the pre-fix planner. A standalone background-worktree case does not, because
the fixture's active worktree is a different one — that is why the first cut of
this change shipped a vacuous test.

stablyai#16214 changed only the planner suite; the same one-line change also breaks
agent-hibernation-coordinator's two revalidation tests, which used
activeWorktreeId as their eligibility lever. Those now flip
setForegroundTerminalTabIds instead, which is the property they were written
to prove.

Co-authored-by: sanshengai <[email protected]>
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 28, 2026
…blyai#16591)

The planner skipped the entire activeWorktreeId, so the tree a user actually
works in never parked anything — exactly where a 16 GB Windows host
accumulates its idle Codex/Grok panes and starts hard-paging (stablyai#16211).

The two guards that remain are the correct granularity and already existed:
foregroundTerminalTabIds covers the tab on screen, and the
foregroundTerminalLastSeenAtByTabId floor in getEligiblePane holds any tab
left inside the idle window.

Test lever taken from @sanshengai's stablyai#16214, which found this first: pinning
the existing sibling-tab regression to activeWorktreeId means it fails against
the pre-fix planner. A standalone background-worktree case does not, because
the fixture's active worktree is a different one — that is why the first cut of
this change shipped a vacuous test.

stablyai#16214 changed only the planner suite; the same one-line change also breaks
agent-hibernation-coordinator's two revalidation tests, which used
activeWorktreeId as their eligibility lever. Those now flip
setForegroundTerminalTabIds instead, which is the property they were written
to prove.

Co-authored-by: sanshengai <[email protected]>
(cherry picked from commit e2cb797)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…blyai#16591)

The planner skipped the entire activeWorktreeId, so the tree a user actually
works in never parked anything — exactly where a 16 GB Windows host
accumulates its idle Codex/Grok panes and starts hard-paging (stablyai#16211).

The two guards that remain are the correct granularity and already existed:
foregroundTerminalTabIds covers the tab on screen, and the
foregroundTerminalLastSeenAtByTabId floor in getEligiblePane holds any tab
left inside the idle window.

Test lever taken from @sanshengai's stablyai#16214, which found this first: pinning
the existing sibling-tab regression to activeWorktreeId means it fails against
the pre-fix planner. A standalone background-worktree case does not, because
the fixture's active worktree is a different one — that is why the first cut of
this change shipped a vacuous test.

stablyai#16214 changed only the planner suite; the same one-line change also breaks
agent-hibernation-coordinator's two revalidation tests, which used
activeWorktreeId as their eligibility lever. Those now flip
setForegroundTerminalTabIds instead, which is the property they were written
to prove.

Co-authored-by: sanshengai <[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.

1 participant