You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sleeping agents: skip wake work for refused input, unrelated hosts and unchanged records - #49413
When an agent is asleep, Orca was doing extra work it didn't need to: it could restart a sleeping agent only to then refuse the message it was waking it for, and some background checks re-read every sleeping agent when only one thing (or nothing relevant) had changed. This PR makes each of those checks look only at what actually changed.
What Changed
Refused input never wakes a sleeping agent (STA-18493).terminal.send now refuses a guarded combined send (text + Enter with requireAgentStatus: 'sendable') before it wakes the slept agent, and the keyed desktop-prompt path skips its wake when the handler would refuse the input (guarded combined send, or text over the 16 MiB terminal input limit). Before, both paths cold-started the agent's process and waited for it to idle, then wrote zero bytes. New shared check: terminal-send-pre-wake-refusal.ts. A keyed prompt it refuses runs the handler directly and keeps no receipt (the refusal is deterministic, so a retry, replay-only or not, gets the same refusal). The executor's size measurement is reused by the handler, so a prompt's text is still scanned once.
Host reconnects retry only that host's sleepers (STA-18490). An SSH host connecting, or a runtime environment becoming verified (the renderer now passes its environment ID), retries only the failed wakes and re-checks only the held mail of sleepers on that host (SleptPaneHost). A sleeper whose host can't be determined still counts, so no wake gets stranded. Before, any host edge cleared every failed wake and re-read every tracked mailbox.
One mail wake reads its Run owner twice, not seven times (STA-18491). An empty waiter-reservation set now selects like none and reuses the publication refresh. batch reads the owner once, not twice, and the wake's first read is passed into run instead of being repeated.
A checkpoint write re-indexes only the record it changed (STA-18492). The sleeping-mail index skips its index rewrites for a record object the write left untouched.
Graph replacements skip leaf counting with no waiter (STA-18494).replaceLeaves counts kept leaves only while a slept-agent wait is listening.
Why
Each fix narrows existing work to what changed, inside the same mechanism. No new state machine, no new setting.
sleeping-mail-record-index.performance.test.ts: 1 of 100 / 1,000 records changed
100 / 1,000 index rewrites
1
STA-18494
source: one Map.has per leaf per replacement with zero listeners
N per replacement
0
pnpm check:changed passes. The existing slept-agent wake, mailbox wake, record index and crew-watch suites pass too.
Performance
Every change removes work: fewer SQL reads per wake and per host edge, no index rewrites for unchanged records, and no process start for refused input. The only added work is one in-memory host check per failed or tracked sleeper on a host edge (a map lookup and a repo lookup), which replaces 3+ SQL reads per tracked mailbox.
Risk
Level: Medium
The riskiest part is host-edge scoping: if a sleeper's host were misidentified, its failed wake would not retry on that host's reconnect. Host IDs are built with the shared encoders (so WSL runtime environments match their saved spelling), and a sleeper counts as on a host when its sleep-record partition, its SSH connection ID or its repo's execution host matches, and also when its host is unknown. Window reloads and pane edges still retry everything.
Back out with a plain revert. No saved data changes.
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Cross-platform: no platform-specific code. Remote: SSH and runtime-environment edges are now scoped per host, as described above. Mobile: no change. Folder workspaces: a sleeper whose worktree has no repo counts as on every host.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Walkthrough
Sleeping-mail retries can be scoped to an execution host, and wake processing now selects batches before starting runs. Record-index refresh checks that mappings remain current before skipping unchanged records. Terminal-send refusal checks run before wake paths. Terminal identity leaf counts now depend on whether handle listeners are registered.
Merge Risk: Minimal · up to 3b0f9
This change reduces unnecessary work when waking sleeping agents, and the review found no remaining merge-blocking issue. Refused or oversized terminal sends no longer wake the agent, and host-scoped retries cover the expected cases. Normal checks are sufficient before merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main theme of the change: sleeping-agent wake work is skipped for refused input, unrelated hosts, and unchanged records. The changeset matches all three parts. It also covers the R…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description follows the repository template closely. It has an ELI5, a What Changed section listing five fixes with ticket IDs, a Why section, a Linked Issue section listing STA-18490 through STA-…
Full details: Title check
Explanation
The title names the main theme of the change: sleeping-agent wake work is skipped for refused input, unrelated hosts, and unchanged records. The changeset matches all three parts. It also covers the Run-owner read reduction and leaf-counting change in less detail, which the title does not need to list. The title is 88 characters, so it is slightly long but still clear.
Full details: Description check
Explanation
The description follows the repository template closely. It has an ELI5, a What Changed section listing five fixes with ticket IDs, a Why section, a Linked Issue section listing STA-18490 through STA-18494, a Visual Proof section marked N/A with a reason, a Testing section with a before/after table of the new tests, a Performance section, a Risk section with level Medium and a revert plan, and a completed checklist. The Linked Issue section lists ticket IDs without a 'Fixes #' GitHub issue link. The template says outside contributors need a real linked issue, but the author appears to be a maintainer, so this is a minor gap. The AI Disclosure section is absent, which is acceptable for internal contributors. The Why section is brief and gives only a general reason for the approach, not the alternatives considered.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Use explicit counts for the matching-host retry control.
The initial check accepts any positive attempt count. The matching-host check accepts any increase. For 1,000 sleepers, counts of 1 and 2 satisfy both checks, so partial retry processing can pass.
Settle each phase with fake timers and assert explicit admitted-launch counts for each fleet size. Keep the zero-work assertions for unrelated hosts.
As per coding guidelines, a perf contract “counts operations at the layer that owns the behavior … against hardcoded values.”
Also applies to: 471-471
Source: Coding guidelines
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 4f7d1af3-4bbb-4c2a-a30d-a9c7ac22c8c2
Commits
Reviewing files that changed from the base of the PR and between d3e67bf and 87937ff.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Perf scan (fresh perf reviewer) on head e3ef6ba: no P0/P1 findings. Every touched path does the same or less work: refused prompts skip the wake and the receipt, host edges re-check only that host's sleepers, mail wakes do fewer owner reads, unchanged sleep records skip their index writes, and graph replacements with no waiter skip leaf counting. No new timers, polls or idle wakeups on main, preload or renderer.
Perf scan (fresh perf reviewer) on head 4295efd: no P0/P1 findings. A keyed prompt's text is measured once (the handler reuses the executor's result); refused prompts skip the wake and the receipt; host edges re-check only that host's sleepers; mail wakes do fewer owner reads; unchanged sleep records skip their index writes; graph replacements with no waiter skip leaf counting. No new timers, polls or idle wakeups.
Perf scan (fresh perf reviewer) on head 3b0f9c0: no P0/P1 findings. Every changed hot path does the same or less work than base; a keyed prompt's text is measured once; no new timers, polls or idle wakeups.
Review loop finished on 3b0f9c060f3ecfc72539ab4a7ac18e820de5c065. All five checks pass.
Check
Result
Claude reviewer (fresh)
PASS, P2s only
Codex reviewer (fresh)
PASS, no findings
Blinded regression audit (fresh Codex)
SAFE
Perf scan (fresh perf reviewer)
PASS, see the comment above
Reference check
the approach is standard: validate before resuming; scope reconnect retries per host
Fixed during the loop, each confirmed by a reviewer:
Reconnect host IDs are encoded and compared canonically, so WSL environments match either saved spelling.
An archive-sweep shortcut that could exceed the 128-archive cap was reverted. STA-18489 is cleared, not fixed: the per-archive check is required to keep the cap exact, and costs about 0.5 ms per sweep at 1,628 archives.
A refused keyed prompt now returns its refusal instead of failing on the slept terminal's binding.
A keyed prompt's text is measured once instead of twice.
Index entries for a sleep record that shares a leaf or handle with another record stay linked.
Remaining P2s, accepted:
Local sleepers no longer retry on unrelated host reconnects. That is the point of STA-18490; local failed wakes still retry on graph-ready, pane and reload edges.
Refused keyed prompts keep no receipt. The refusal is deterministic, so any retry gets the same refusal.
QA: tests. The STA-18493 test drives the real RPC dispatcher and fails on main. The perf contracts for STA-18490, 18491 and 18492 each fail on main with the before counts in the PR body. slept-pane-host.test.ts covers both host-ID spellings. CI is green.
Perf scan coverage, confirmed by the same fresh perf reviewer for head 3b0f9c0:
hot-path: all ten detected files were read and traced through their production callers: sleeping-mail routing and wake, keyed prompt send, terminal identity graph. None does more work than base.
publish: the ui:sleepingMailAvailability send in ui-sleeping-mail-api.ts:24 is the same message with one extra string. It fires only when a host first becomes ready and verified, and the main side now publishes only that host's mailboxes.
…d unchanged records (stablyai#49413)
* fix(sleeping-agents): stop wake work that refused input, unrelated hosts and unchanged records cause
* test(sleeping-agents): archive sweep skips re-classifying unchanged sleepers
* fix: type the pre-wake refusal check without a cast
* fix(sleeping-agents): encode reconnecting host IDs; keep the exact archive sweep
* fix(sleeping-agents): match reconnecting hosts across saved id spellings
* fix(sleeping-agents): a refused keyed prompt returns its refusal without binding a slept terminal
* fix(sleeping-agents): measure a keyed prompt once; refused replays get the refusal; keep shared leaf/handle lookups
* refactor: drop a condition the early return already covers
(cherry picked from commit 5af7059)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When an agent is asleep, Orca was doing extra work it didn't need to: it could restart a sleeping agent only to then refuse the message it was waking it for, and some background checks re-read every sleeping agent when only one thing (or nothing relevant) had changed. This PR makes each of those checks look only at what actually changed.
What Changed
terminal.sendnow refuses a guarded combined send (text + Enter withrequireAgentStatus: 'sendable') before it wakes the slept agent, and the keyed desktop-prompt path skips its wake when the handler would refuse the input (guarded combined send, or text over the 16 MiB terminal input limit). Before, both paths cold-started the agent's process and waited for it to idle, then wrote zero bytes. New shared check:terminal-send-pre-wake-refusal.ts. A keyed prompt it refuses runs the handler directly and keeps no receipt (the refusal is deterministic, so a retry, replay-only or not, gets the same refusal). The executor's size measurement is reused by the handler, so a prompt's text is still scanned once.SleptPaneHost). A sleeper whose host can't be determined still counts, so no wake gets stranded. Before, any host edge cleared every failed wake and re-read every tracked mailbox.batchreads the owner once, not twice, and the wake's first read is passed intoruninstead of being repeated.replaceLeavescounts kept leaves only while a slept-agent wait is listening.Why
Each fix narrows existing work to what changed, inside the same mechanism. No new state machine, no new setting.
Linked Issue
STA-18490, STA-18491, STA-18492, STA-18493, STA-18494
Visual Proof
N/A: main-process bookkeeping with no UI change.
Testing
Each new test was run against the parent commit's source (fails) and this head (passes):
slept-agent-wake.test.ts: refused input through the real RPC dispatcherslept-mailbox-wake.performance.test.ts: unrelated SSH + runtime reconnects, 100 / 1,000 local sleeperssleeping-mail-record-index.performance.test.ts: 1 of 100 / 1,000 records changedMap.hasper leaf per replacement with zero listenerspnpm check:changedpasses. The existing slept-agent wake, mailbox wake, record index and crew-watch suites pass too.Performance
Every change removes work: fewer SQL reads per wake and per host edge, no index rewrites for unchanged records, and no process start for refused input. The only added work is one in-memory host check per failed or tracked sleeper on a host edge (a map lookup and a repo lookup), which replaces 3+ SQL reads per tracked mailbox.
Risk
Level: Medium
Review
Agent skill upstream boundary
Notes
Cross-platform: no platform-specific code. Remote: SSH and runtime-environment edges are now scoped per host, as described above. Mobile: no change. Folder workspaces: a sleeper whose worktree has no repo counts as on every host.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)