Skip to content

fix(hibernation): park completed background tabs in the active worktree - #16214

Closed
sanshengai wants to merge 1 commit into
stablyai:mainfrom
sanshengai:perf/hibernate-inactive-active-worktree
Closed

sanshengai wants to merge 1 commit into
stablyai:mainfrom
sanshengai:perf/hibernate-inactive-active-worktree

Conversation

@sanshengai

Copy link
Copy Markdown

ELI5

Orca already knows which terminal tab is actually visible. It was nevertheless exempting every completed agent in the active worktree from auto-hibernation, so background tabs in the worktree a user was viewing could stay alive forever.

What changed

The hibernation planner now applies the existing per-tab foreground guard to every worktree, including the active one. The visible terminal tab remains protected; completed, resumable sibling tabs can hibernate after the configured idle window.

Why

On small Windows hosts, users often keep several long-lived agent tabs in one active product worktree. Skipping the whole worktree leaves every completed Codex/Claude process and its MCP descendants resident. Per-tab visibility is already the more precise safety boundary.

Linked issue

Addresses #16211 (proposed slice 3).

Tests

  • Added the active-worktree case to the existing sibling-tab regression: the foreground tab stays awake while an idle sibling is selected.
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/lib/agent-hibernation-planner.test.ts — 31 passed.
  • pnpm run typecheck:web — passed.
  • Targeted oxlint and git diff --check — passed.

The repository's pnpm test wrapper could not rebuild windows-native-registry for local Node 24.19.0; the same test was run directly with the repository Vitest config.

Scope

  • No setting defaults changed; experimental hibernation must still be enabled.
  • Foreground tabs, recent input, drafts, mobile-controlled panes, interrupted sessions, subagents, unsettled orchestration, and non-resumable agents keep their existing guards.
  • No RPC or remote-wire changes.

AI Disclosure

This change and its regression coverage were developed with Codex assistance and reviewed against the existing hibernation safety gates.

Checklist

  • Small and focused
  • Automated regression coverage
  • Cross-platform and remote behavior considered
  • No UI change
  • No upstream skill source copied

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 601d976d-d1d4-46cb-b452-970134bf85f2

📥 Commits

Reviewing files that changed from the base of the PR and between 4ee41fe and 7cdf7f3.

📒 Files selected for processing (2)
  • src/renderer/src/lib/agent-hibernation-planner.test.ts
  • src/renderer/src/lib/agent-hibernation-planner.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The agent hibernation planner no longer excludes the active worktree from candidate evaluation. Foreground-tab and other eligibility checks remain in place. Tests now focus the first case on disabled and foreground conditions, and the sibling-tab case marks wt-bg as the active worktree.

Merge Risk: ⚪ Minimal · up to 7cdf7

The change narrows hibernation protection to the visible tab while allowing completed idle sibling tabs to hibernate; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the change, motivation, scope, linked issue, testing, and AI use, but omits the required Visual Proof section for this behavior change. Add the Visual Proof section and provide before/after evidence, or write N/A with a brief reason if the behavior change has no visual or interaction impact.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: hibernating completed background tabs in the active worktree.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
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.

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.

nwparker added a commit that referenced this pull request Aug 26, 2026
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 <sanshengai@users.noreply.github.com>
nwparker added a commit that referenced this pull request Aug 26, 2026
)

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 <sanshengai@users.noreply.github.com>
@nwparker

Copy link
Copy Markdown
Contributor

Thank you for this — you found this root cause first, and your test approach was better than mine.

What happened: I independently hit the same one-line planner fix in #16591. My version shipped a vacuous test — it used a background worktree while the fixture's activeWorktreeId was a different one, so it passed unchanged against the pre-fix planner and proved nothing. Yours pins the existing sibling-tab regression to activeWorktreeId instead, which genuinely fails pre-fix. That is the correct lever and it is one line instead of twenty.

Why this PR could not merge as-is: it is ~142 commits behind main, and the same one-line planner change also breaks two tests in agent-hibernation-coordinator.test.ts — revalidates fresh state before shutdown and the delayed-runtime-list case both used activeWorktreeId as their eligibility lever. I verified this by trial-merging your branch onto current main: the planner suite passes, but the coordinator suite goes red (1 failed / 73 passed).

What landed: #16591, which takes your test lever and adds the coordinator-test fix, with you credited as Co-authored-by. Final diff is 3 files, +14/−5 — smaller than either original. Non-vacuity was verified by reverting the planner line and confirming the test fails.

Closing this in favour of that, but the credit is yours. Also worth saying: your #16217 (auto-releasing completed worker terminals) covers a part of #16211 that none of my PRs touch — my own triage confirmed completed workers stay retained and I did not fix it.

@nwparker nwparker closed this Aug 26, 2026
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 <sanshengai@users.noreply.github.com>
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 <sanshengai@users.noreply.github.com>
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 <sanshengai@users.noreply.github.com>
(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 <sanshengai@users.noreply.github.com>
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.

2 participants