Skip to content

Improve Claude usage refresh fallback behavior - #5995

Merged
Jinwoo-H merged 4 commits into
mainfrom
Jinwoo-H/claude-agent-session-issue
Jun 21, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
Jinwoo-H/claude-agent-session-issue

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add an internal Claude usage refresh plan and OAuth/CLI source execution path.
  • Classify Claude OAuth and credential failures, then use structured metadata for fallback/defer/UI copy instead of raw string parsing alone.
  • Add safe automatic CLI fallback, OAuth retry after CLI repair, managed live-session defer handling, Keychain-unavailable metadata, and stale snapshot metadata preservation.
  • Split status-bar usage error copy into a focused module to keep the tooltip file under the line limit.

Review

  • Ran an independent Orca subagent review focused on hidden PTY fallback safety, managed live-session defer behavior, metadata/stale policy, renderer copy, and implementation-plan mismatches.
  • Addressed the actionable findings by preventing managed live-session no-token cases from falling through to CLI fallback and by adding structured Keychain-unavailable classification/copy.
  • The remaining hidden PTY note is intentional for app auto mode, while retaining the existing non-Windows/WSL/live-session guardrails.

Verification

  • pnpm exec vitest run --config config/vitest.config.ts src/main/rate-limits/claude-fetcher.test.ts src/main/rate-limits/claude-usage-error-classification.test.ts src/main/rate-limits/claude-usage-refresh-plan.test.ts src/main/rate-limits/service.test.ts src/renderer/src/components/status-bar/tooltip.test.ts
  • pnpm run typecheck
  • pnpm exec oxlint src/main/rate-limits/claude-fetcher.ts src/main/rate-limits/claude-fetcher.test.ts src/main/rate-limits/claude-usage-error-classification.ts src/main/rate-limits/claude-usage-error-classification.test.ts src/main/rate-limits/claude-usage-refresh-plan.ts src/main/rate-limits/claude-usage-refresh-plan.test.ts src/main/rate-limits/service.ts src/main/rate-limits/service.test.ts src/renderer/src/components/status-bar/tooltip.tsx src/renderer/src/components/status-bar/usage-error-copy.ts src/renderer/src/components/status-bar/tooltip.test.ts src/shared/rate-limit-types.ts
  • pnpm exec oxfmt --check src/main/rate-limits/claude-fetcher.ts src/main/rate-limits/claude-fetcher.test.ts src/main/rate-limits/claude-usage-error-classification.ts src/main/rate-limits/claude-usage-error-classification.test.ts src/main/rate-limits/claude-usage-refresh-plan.ts src/main/rate-limits/claude-usage-refresh-plan.test.ts src/main/rate-limits/service.ts src/main/rate-limits/service.test.ts src/renderer/src/components/status-bar/tooltip.tsx src/renderer/src/components/status-bar/usage-error-copy.ts src/renderer/src/components/status-bar/tooltip.test.ts src/shared/rate-limit-types.ts

Note: local shell reports the repo's standard Node engine warning because it is using Node v26 while the repo expects Node 24; commands above passed.


Open in Stage

@ghost

ghost commented Jun 21, 2026 •

Copy link
Copy Markdown

@Jinwoo-H Jinwoo-H changed the title Match CodexBar Claude usage fallback behavior Improve Claude usage refresh fallback behavior Jun 21, 2026
@coderabbitai

coderabbitai Bot commented Jun 21, 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

Run ID: d5b4265d-f424-47f5-83a1-e486ab9fceb0

📥 Commits

Reviewing files that changed from the base of the PR and between 8d6b34e and 1048558.

📒 Files selected for processing (1)
  • src/main/updater.test.ts

📝 Walkthrough

Walkthrough

This PR restructures Claude usage limit tracking in Orca to introduce classification-driven OAuth/CLI fallback behavior with comprehensive metadata tracking. It adds shared UsageRateLimitMetadata types capturing source, attempted sources, failure kinds, and provenance. New classification modules categorize OAuth HTTP errors and credential-absence scenarios into recoverable, fallback-only, and terminal states, with a refresh plan resolver that builds ordered source steps (OAuth first, then optional CLI on non-Windows). Keychain-unavailability is now distinguished from ordinary missing credentials throughout the credential-reading pipeline. The fetchClaudeRateLimits function is substantially rewritten with attempt orchestration helpers to drive OAuth-first then optional delegated-refresh repair (CLI attempt + credential re-read + OAuth retry) or CLI/PTY fallback, recording attempted sources and failure kinds in metadata. RateLimitService gates PTY fallback by platform (disabled on Windows, enabled otherwise) and updates stale-policy metadata merging to track lastSuccessfulSource across both success and error-retention paths. On the renderer side, a new usage-error-copy.ts module provides provider-aware, failureKind-driven error messages and status labels, and tooltip.tsx is refactored to use it. A specification document outlines the complete implementation plan and non-goals.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description covers the Summary section and includes Review, Verification, and Notes sections. However, it is missing Screenshots (no indication of visual changes or explicit statement), and the Testing checklist is not completed with checkmarks or explanations for each item. Add a 'Screenshots' section stating 'No visual change' and complete the Testing checklist by checking off each item or explaining verification was performed via command-line tests.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Improve Claude usage refresh fallback behavior' accurately summarizes the main change—implementing better fallback mechanisms for Claude usage refresh with OAuth/CLI paths and structured error classification.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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 and usage tips.

@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

🧹 Nitpick comments (3)
docs/claude-usage-tracking-codexbar-parity.md (1)

26-39: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Replace the machine-specific CodexBar paths.

These /Users/... references are brittle and leak a local username. Use repo-relative paths or stable permalinks so the spec works for everyone.

♻️ Example rewrite
- Reference: `/Users/jinwoohong/stably/codexbar/Sources/CodexBarCore/Providers/Claude/ClaudeSourcePlanner.swift:173`
+ Reference: `Sources/CodexBarCore/Providers/Claude/ClaudeSourcePlanner.swift:173`
src/main/rate-limits/claude-usage-refresh-plan.ts (1)

36-39: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add a short “why” note for the deferred web fallback decision.

webDeferred: true encodes a non-obvious parity constraint; please annotate the reason inline so this doesn’t get “simplified” later.

Suggested tweak
   return {
     steps,
+    // Why: first parity pass intentionally keeps web fallback disabled.
     webDeferred: true
   }
As per coding guidelines, code driven by non-obvious constraints should include a short comment explaining why it behaves that way.

Source: Coding guidelines

src/main/rate-limits/claude-fetcher.test.ts (1)

637-655: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add the complementary keychain-unavailable test with CLI fallback enabled.

This suite currently validates only the disabled-fallback path. Adding an allowPtyFallback: true case would pin the intended recovery behavior and prevent regressions in the credential-classification branching.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1346147b-3788-4e3c-be06-3dda14b17625

📥 Commits

Reviewing files that changed from the base of the PR and between f6b8282 and 24e88c9.

📒 Files selected for processing (13)
  • docs/claude-usage-tracking-codexbar-parity.md
  • src/main/rate-limits/claude-fetcher.test.ts
  • src/main/rate-limits/claude-fetcher.ts
  • src/main/rate-limits/claude-usage-error-classification.test.ts
  • src/main/rate-limits/claude-usage-error-classification.ts
  • src/main/rate-limits/claude-usage-refresh-plan.test.ts
  • src/main/rate-limits/claude-usage-refresh-plan.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/service.ts
  • src/renderer/src/components/status-bar/tooltip.test.ts
  • src/renderer/src/components/status-bar/tooltip.tsx
  • src/renderer/src/components/status-bar/usage-error-copy.ts
  • src/shared/rate-limit-types.ts

Comment thread src/main/rate-limits/claude-fetcher.ts Resolved
@Jinwoo-H
Jinwoo-H merged commit 530f98d into main Jun 21, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/claude-agent-session-issue branch June 21, 2026 20:10
audichuang pushed a commit to audichuang/orca that referenced this pull request Jun 22, 2026
* Match CodexBar Claude usage fallback behavior

Co-authored-by: Orca <[email protected]>

* Remove external tracker references from Claude usage changes

Co-authored-by: Orca <[email protected]>

* Allow CLI fallback when Claude Keychain is unavailable

Co-authored-by: Orca <[email protected]>

* Stabilize updater prerelease promotion test

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
(cherry picked from commit 530f98d)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Match CodexBar Claude usage fallback behavior

Co-authored-by: Orca <[email protected]>

* Remove external tracker references from Claude usage changes

Co-authored-by: Orca <[email protected]>

* Allow CLI fallback when Claude Keychain is unavailable

Co-authored-by: Orca <[email protected]>

* Stabilize updater prerelease promotion test

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
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.

1 participant