Skip to content

fix(agent-session): stop publishing usage-limit stops for closed chats - #51539

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-51486
Nov 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-51486

Conversation

@nwparker

@nwparker nwparker commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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.

Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​81 $\color{#cf222e}{\Huge{\mathbf{−}}}$​109 $\color{#cf222e}{\Huge{\mathbf{−}}}$​28
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​65

What Changed

  • Before: The status summary for any chat with a saved usage-limit cut carried that cut's usageLimitContinue state, 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.
  • After: The summary carries a usage-limit stop only while the chat is open (tab visible, or a live background chat). A closed chat's summary has no usageLimitContinue. If the chat's tab is reopened, its usage-limit state is published again at once.
  • Mechanism: StructuredAgentSessionHost now reads the published usage-limit state through a new published() helper in structured-agent-session-host-background.ts. It returns readState(id, cut) only when isUsageLimitChatOpen(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.
  • Tests: a new regression test for the closed-chat case and the reopen case. A shared usage-limited turn journal fixture replaces three copied versions in existing tests.

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 on main (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. On main the summary still carries usageLimitContinue (fails). On this branch it is undefined (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 skips readState). 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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)

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]>
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The host now publishes usage-limit state only when a usage-limit cut exists and the chat is open. A new test checks status behavior when a chat is closed and its tab is reopened. A shared fixture now creates usage-limited journal turns for several host tests.

Severity of issue fixed: Low

Merge Risk: Minimal · up to 8e761

Closed chats no longer publish a usage-limit badge, which fixes the stale sidebar badge after a Home Chat is replaced. Reopening a chat restores its state. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: usage-limit stops are no longer published for closed chats. It follows the conventional-commit style and fits the raw summary, which adds a published() gate that retur…
Linked Issues check Passed Issue #51486 requires that a bot's sidebar status not show a usage limit from a closed earlier chat, such as a replaced Codex Home Chat. At the reviewed head, published() in `recovery/structured-age…
Out of Scope Changes check Passed All changed files relate to the usage-limit publication fix for #51486. The host change swaps the direct usageLimitContinue read for the new published() helper. The background module adds that hel…
Description check Passed The PR description follows the repository template closely. It has an ELI5, a What Changed section with before and after behavior and the mechanism, a Why section explaining the alternative rejected, …
Full details: Title check

Explanation

The title names the main change: usage-limit stops are no longer published for closed chats. It follows the conventional-commit style and fits the raw summary, which adds a published() gate that returns usage-limit state only when the chat is open. The title is 70 characters, which is within a normal length.

Full details: Linked Issues check

Explanation

Issue #51486 requires that a bot's sidebar status not show a usage limit from a closed earlier chat, such as a replaced Codex Home Chat. At the reviewed head, published() in recovery/structured-agent-session-host-background.ts returns a saved usage-limit state only when isUsageLimitChatOpen(host.deps.store, id) holds. StructuredAgentSessionHost uses this helper when it publishes a status summary. A closed chat therefore publishes no usageLimitContinue. The closed-chat regression test (structured-agent-session-usage-limit-closed-chat.test.ts) checks this case. It also checks that reopening the tab publishes the state again. The saved cut is not cleared, so no stored data changes. The full test suite and build are not reported as run, but the targeted test evidence covers the requirement.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the usage-limit publication fix for #51486. The host change swaps the direct usageLimitContinue read for the new published() helper. The background module adds that helper. The test changes add the closed-chat regression test. They also move three copied usage-limited turn setups into the shared appendUsageLimitedTurn fixture, which supports the tests for this change. The refactored existing tests (account-switch, agent-mail-after-failure, usage-limit-queue-recovery) use the same fixture and do not change their intended behavior. No unrelated change was found.

Full details: Description check

Explanation

The PR description follows the repository template closely. It has an ELI5, a What Changed section with before and after behavior and the mechanism, a Why section explaining the alternative rejected, a Linked Issue (Fixes #51486), a Visual Proof section with N/A and a reason plus a regression test reference, a Testing section listing the targeted tests and a repro, a Performance section with a concrete justification, a Risk section with level Low and a revert path, and the review and checklist sections. The unchecked manual-test box and the unchecked full pnpm lint/typecheck/test/build item are candid about what was not verified, and the author notes that no GUI run was done. These gaps are minor and do not make the description largely incomplete. The AI Disclosure section is left as the template comment, which is acceptable for this check.

  • 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.

Share

Recent 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: 5ddb4579-8658-4c12-bb83-80f987c9ee0a
Commits

Reviewing files that changed from the base of the PR and between 7ceeb8f and 8e7610f.

Files selected for processing: 7

  • src/main/native-chat/agent-session-wire/host/structured-agent-session-host.ts
  • src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-account-switch.test.ts
  • src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-agent-mail-after-failure.test.ts
  • src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-usage-limit-closed-chat.test.ts
  • src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-usage-limit-queue-recovery.test.ts
  • src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-usage-limited-turn.test-fixture.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-host-background.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker merged commit aaf8f28 into main Nov 28, 2026
57 checks passed
@nwparker
nwparker deleted the bugbash/issue-51486 branch November 28, 2026 06:50
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.

[Bug]: Bot sidebar keeps showing "Usage limit" from a closed earlier chat after the bot moves to another agent

1 participant