Skip to content

fix(chat): resume usage-limited chats after a relaunch - #47245

Merged
brennanb2025 merged 31 commits into
mainfrom
brennanb2025/takeover-jinjing-fix-item
Nov 25, 2026
Merged

brennanb2025 merged 31 commits into
mainfrom
brennanb2025/takeover-jinjing-fix-item

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When a chat stops because its account has run out of usage, changing to an account with room normally lets it continue. If the stopped chat's agent had been cleaned up and started again first, Orca forgot which account had hit the limit and made the chat wait for the old account's reset. Now it recognizes that the chat was restarted, checks the account it would use now, and continues when that account has room.

Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​423 $\color{#cf222e}{\Huge{\mathbf{−}}}$​63 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​360
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​435 $\color{#cf222e}{\Huge{\mathbf{−}}}$​212 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​223

What Changed

  • Preserves enough in-memory attribution for a usage-limited cut when a chat has relaunched after the failed turn.
  • Uses a fresh, non-live-session usage reading from the relaunched account to release the stopped chat early.
  • Holds a relaunched chat on any reading that shows the account spent, until room is read after the failed turn.
  • Shows no continue time for a relaunched chat with no known reset until room is read.
  • Retains the existing safeguards for stale readings, usage limits on the replacement account, capped retry chains, and queued chat mail.

Why

The session record intentionally keeps only the latest launch. Once cleanup stopped and restarted a chat, its recorded launch no longer matched the failed turn, so the existing account-switch path could not identify the account that had hit its limit. The recovery path now treats that missing historical attribution as a relaunch and waits for evidence that the current account has room.

Linked Issue

N/A. Reported internally.

Visual Proof

N/A. This changes recovery state only; it adds no control or visual treatment.

Testing

  • 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

Added focused recovery tests for a relaunched usage-limited chat, including queued mail release, stale-reading rejection, a replacement account that is also limited, spending read before a known reset, and room read after earlier unknown spending. A desktop run on Linux restarted a real chat and continued it after the relaunch; a real exhausted account can't be produced on demand, so the held-then-continued path is covered by the tests.

Performance

At most one non-forced refresh is requested per account every ten minutes while a relaunched cut is held, shared across chats. No polling runs for chats without a usage-limit cut.

Risk

Level: Low

The main risk is continuing on an account that is also limited. Fresh account-scoped readings, stale-reading rejection, and the existing retry cap contain that case. The change is derived state only, so a plain revert removes it without affecting saved data.

AI Disclosure

N/A

Review

Self-reviewed for recovery ordering, stale readings, and account attribution after a restart.

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

The existing account-home abstractions preserve platform-aware comparisons. The recovery runs only on the host that owns the chat; remote and mobile clients receive the existing session status updates.

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)

@brennanb2025
brennanb2025 marked this pull request as ready for review November 23, 2026 06:36
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

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.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Account-hold recovery now tracks provider attribution and relaunch timestamps. It applies switch-reset metadata from matching moved cuts and gates readiness on scheduling and room state. Continuation checks apply switch-reset metadata and validate attribution bindings. Tests cover known-reset timing, exhausted-account behavior, and resetless recovery that requires fresh usage readings and may wait for room to arrive.

Merge Risk: Minimal · previous review ee9b1

This change improves resumption of usage-limited chats after a relaunch. No concrete merge-blocking risk was identified, and the added tests cover the main recovery paths.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(chat): resume usage-limited chats after a relaunch" matches the main change. The PR treats a missing historical account attribution after a chat relaunch as a relaunch, checks the accou…
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.
Description check Passed The description is mostly complete. It has a clear ELI5, a What Changed list, a Why section, a Testing section with checked items and a manual Linux run, a Performance line with a concrete reason, a R…
Full details: Title check

Explanation

The title "fix(chat): resume usage-limited chats after a relaunch" matches the main change. The PR treats a missing historical account attribution after a chat relaunch as a relaunch, checks the account the chat would use now, and resumes the chat when that account has room. The title is specific and follows a conventional commit format. The objectives also state the same purpose.

Full details: Description check

Explanation

The description is mostly complete. It has a clear ELI5, a What Changed list, a Why section, a Testing section with checked items and a manual Linux run, a Performance line with a concrete reason, a Risk section with level and revert path, and a Review section. Gaps: the Linked Issue section says N/A and cites an internal report, but the template says outside contributors must link an actual issue; the author does not state whether they are an outside contributor, so this cannot be fully confirmed. The Visual Proof N/A reason is given. The AI Disclosure is N/A with no model details. The 'pnpm lint, typecheck, test, build' checklist item is unchecked, and the Testing section says the desktop run was on Linux only, with no macOS or Windows coverage noted. The Notes section does not explicitly confirm that cross-platform and SSH impact was checked beyond a general statement.

  • 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: 0fc9eb21-68bc-42a9-a230-f366cf538a41
Commits

Reviewing files that changed from the base of the PR and between 432d1dc and ee9b107.

Files selected for processing: 5

  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-account-hold.test.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-account-hold.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-continue.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-relaunch.test.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-relaunch.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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

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: bdde0130-2d22-41cd-af11-fc0621e9d9e8
Commits

Reviewing files that changed from the base of the PR and between 37a3b4f and 34cfb2d.

Files selected for processing: 6

  • 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/recovery/structured-agent-session-usage-limit-account-hold.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-account-schedule.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-account-types.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-continue.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-relaunch.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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review loop complete for 34cfb2d. Focused recovery tests, node typecheck, lint, desktop QA, review, and CI are all complete with no open findings.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final-head Electron QA passed on 34cfb2dae05acdc2a8b09a06df8bae281329f182.

The isolated M4Air app loaded from this worktree; the renderer showed the empty chat surface without visible errors. The focused recovery suite passed 7/7. The recovery state itself was not fabricated in the UI and remains covered by that automated end-to-end test.

Electron QA screenshot

Final-head Electron QA

A relaunched cut with a known reset now holds on spending read before that
reset, and a resetless relaunched cut no longer publishes its stand-in reset
as a continue time while it waits for room.
A relaunched cut with a known reset now continues on room read since the
relaunch, even after an earlier spent reading with no reset time.
Live-session readings can't release a relaunched cut, so they no longer latch
one either; a spent one with no reset time held a known-reset chat forever
when no other reading could arrive.
Live-session spending with a known reset now holds moved and relaunched cuts
to that reset; without one it no longer sets the unknown-reset latch that only
non-live room can clear.
A cached room reading older than the overdue window replaced the reset and
made the cut unschedulable, so no fresh reading was ever requested.
@brennanb2025

brennanb2025 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Review loop complete for a4a87cf.

Problem. A chat stopped at a usage limit lost track of which account hit the limit once its agent was cleaned up and restarted. It then waited for the old account's reset even when the account it would use now had room.

What changes for users. A restarted chat continues once a fresh reading shows its current account has room. Until then, the usage-limit card shows no continue time. Any reading that shows the account spent keeps the chat held. No new text or controls.

Fixed in this round (each with a test that fails without the fix):

  • With auto-continue off, cancelled or failed, a restarted chat with no known reset was shown as "can continue now" while the account was still spent.
  • A spent reading taken before a known reset didn't hold a restarted chat. A later reading with room then failed to release one held by earlier spending that had no reset time.
  • A live usage report showing spending with no reset time could hold a switched or restarted chat with no way to release it. Live reports with a known reset now hold the chat until that reset.
  • After a sleep of more than a day, a cached room reading for a switched account could make the chat unschedulable, so no fresh reading was requested.

Deferred (P2).

  • A spent reading whose spent session window has no reset time also discards the reset of a spent weekly window in the same reading. Only matters with account polling off; same on main.
  • Two narrow cases can still stop a switched chat from continuing after a sleep of more than a day: a switch recorded before the sleep, and room read in the last seconds before the sleep. Both are the same on main.
  • A code comment says room counts "since a relaunch"; the code counts room "since the turn ended", which the rules allow.

Verified on a4a87cf.

  • CI green.
  • Changed-file checks pass on a remote Linux host.
  • Focused recovery suites pass, 35 tests.
  • A fresh review pass and a blinded regression audit of the change merged onto current main (SAFE) both found no blockers.
  • Compared with the reference implementations: they continue only at a provider-reported reset, or immediately when a routed account pool has a ready account. Orca's release on a fresh room reading follows the second model, and both share the same one-day overdue cap.

Desktop QA ran on af84eda on Linux, with a real Claude chat:

  • One reply, then a graceful quit and relaunch on the same data.
  • History intact; a second reply that carried the earlier context.
  • No error banner, no auto-continue text, and no usage reads while idle.
  • The later commits change only hold logic that the tests above cover. A real exhausted account can't be produced on demand.
Desktop QA screenshot (af84eda, after relaunch and second reply)

Desktop QA after relaunch

Desktop QA on a4a87cf on Linux, with a real Codex chat:

  • One reply, then a graceful quit and relaunch on the same data.
  • History intact; the relaunched chat continued the same conversation with the earlier context.
  • No error banner, no auto-continue text, and no usage reads while idle.
  • The focused recovery suites passed there too (35/35).
Desktop QA screenshot (Codex, a4a87cf, after relaunch and second reply)

Desktop QA with Codex after relaunch

@brennanb2025
brennanb2025 merged commit c07fce2 into main Nov 25, 2026
57 checks passed
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