Repository navigation
fix(agent-session): stop publishing usage-limit stops for closed chats - #51539
Conversation
A bot's replaced Home Chat is loaded again to move its queue, and each republish read its saved usage-limit cut into the status feed. The sidebar then kept showing "Usage limit" from a closed chat after the bot moved to another agent. The status summary now carries a usage-limit stop only while the chat is open (tab visible or in the background); a reopened chat publishes its state again at once. Fixes #51486 Co-authored-by: Claude <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Low Merge Risk:
|
ELI5
When a bot switches to a different agent, its old chat is closed but Orca still loads it in the background to move its queued mail. Every time it did, Orca re-announced that old chat's "Usage limit" stop, so the bot's sidebar row kept showing a usage limit from an agent the bot no longer uses. Now a closed chat says nothing about usage limits; only open chats do.
What Changed
usageLimitContinuestate, open or not. A bot's replaced Home Chat (e.g. the old Codex chat after a switch to Claude Code) is republished when its queue moves, so the sidebar kept its "Usage limit · " badge.usageLimitContinue. If the chat's tab is reopened, its usage-limit state is published again at once.StructuredAgentSessionHostnow reads the published usage-limit state through a newpublished()helper instructured-agent-session-host-background.ts. It returnsreadState(id, cut)only whenisUsageLimitChatOpen(store, id)holds. That is the same open check the auto-continue logic already uses (usageLimitCutContinuable), so what is shown and what is continued now agree. The saved cut stays in the store; nothing is deleted.Why
The sidebar badge should follow the bot's current chat. Clearing or rewriting the saved cut on close was the alternative, but it would lose the state a reopened chat needs and would add store writes. Gating at publish time reuses the existing open-chat check, keeps saved data unchanged, and adds no new state.
Linked Issue
Fixes #51486
Reported by xz0831
Visual Proof
N/A. No screenshots were captured: the change is to the main-process status summary, and no GUI run was done on the owner's in-use machine. The behavior is shown by the regression test (
structured-agent-session-usage-limit-closed-chat.test.ts). It fails onmain(expect(summary?.usageLimitContinue).toBeUndefined()gets a value for a closed chat) and passes with this change.Testing
Repro: a regression test puts a chat into a usage-limited turn, closes it, republishes it, and reads
readStatusSummary. Onmainthe summary still carriesusageLimitContinue(fails). On this branch it isundefined(passes). A second case reopens the tab and checks that the usage-limit state is published at once.Ran targeted vitest:
structured-agent-session-usage-limit-closed-chat,-account-switch,-agent-mail-after-failure,-usage-limit-queue-recovery(4 files, 29 tests passed).Static gates on touched files: anti-slop oxlint, native code-quality oxlint, ast-grep, changed-code quality gate, oxfmt. All clean.
Platforms: macOS (unit tests). The logic has no platform-specific code.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
Effectively none. The check runs only when a status summary is built for a chat that has a saved usage-limit cut. It is two in-memory map lookups (
isSessionTabVisible/isSessionInBackground), with no I/O, subprocesses, polling, or fan-out to other sessions. Microbenchmark of the published-state read, old vs new: no cut 7-12 ns vs 13-15 ns; open chat with cut ~820 ns vs ~845 ns; closed chat with cut ~810 ns vs ~30 ns (it now skipsreadState). Worst single call: 0.002 ms.Risk
Level: Low
The riskiest part: a chat that is open but that the store does not see as visible or in the background would lose its usage-limit badge. That is the same check that already decides whether Orca auto-continues the cut, so such a chat would not be continued either. No saved data changes, so a plain revert restores the old behavior.
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)