Skip to content

Add Claude CLI fallback for data load failures#517

Open
johnyoonh wants to merge 2 commits intosteipete:mainfrom
johnyoonh:fix/claude-cli-fallback
Open

Add Claude CLI fallback for data load failures#517
johnyoonh wants to merge 2 commits intosteipete:mainfrom
johnyoonh:fix/claude-cli-fallback

Conversation

@johnyoonh
Copy link

@johnyoonh johnyoonh commented Mar 13, 2026

Summary

Improves Claude provider reliability by automatically falling back to web/oauth authentication when CLI fails with data load errors.

Changes

  • Detect 'could not load usage data' errors from Claude CLI
  • Automatically fallback to web/oauth authentication methods
  • Improves reliability when CLI has transient issues
  • Preserves existing fallback behavior for other error types

Testing

  • Verified fallback triggers on 'Claude CLI could not load usage data' error
  • Confirmed other error types still show appropriate messages
  • Tested web/oauth fallback successfully retrieves usage data

Note

This is a general reliability improvement. Not tied to a specific issue, but helps when users encounter 'Could not parse Claude usage: Claude CLI could not load usage data. Open the CLI and retry /usage.' error.

Copilot AI review requested due to automatic review settings March 13, 2026 03:31
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 464a9538f9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +341 to +344
if errorDesc.contains("could not load usage data")
|| errorDesc.contains("failed to load usage data")
{
return true

Choose a reason for hiding this comment

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

P1 Badge Restrict CLI data-load fallback to contexts with a next strategy

Returning true unconditionally for these message matches causes the pipeline to drop the original CLI error even when no usable fallback exists. In explicit Claude CLI mode, resolveStrategies returns only ClaudeCLIFetchStrategy (ClaudeProviderDescriptor.swift lines 54-57 and 78-81), so this path makes ProviderFetchPipeline continue and then end with ProviderFetchError.noAvailableStrategy instead of surfacing the actionable CLI failure; the same can happen in auto mode when web fallback is unavailable. This is a regression from the previous guard that limited fallback to app+auto with web availability.

Useful? React with 👍 / 👎.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves Claude provider resilience by extending the CLI fetch strategy’s fallback behavior to detect “usage data load” failures and attempt alternate auth-based strategies instead of surfacing the CLI error immediately.

Changes:

  • Add substring-based detection for “could not/failed to load usage data” CLI failures.
  • Trigger fallback when those errors are observed (intended to reach web/oauth flows).
  • Preserve the prior “fallback only in app+auto when web is available” behavior for other error types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +337 to 351
func shouldFallback(on error: Error, context: ProviderFetchContext) -> Bool {
// Always fallback for CLI data load failures - these are transient issues
// that web/oauth methods can often resolve
let errorDesc = error.localizedDescription.lowercased()
if errorDesc.contains("could not load usage data")
|| errorDesc.contains("failed to load usage data")
{
return true
}

// For other errors, only fallback in auto mode when web is available
guard context.runtime == .app, context.sourceMode == .auto else { return false }
// Only fall through when web is actually available; otherwise preserve actionable CLI errors.
return ClaudeWebFetchStrategy.isAvailableForFallback(
context: context,
browserDetection: self.browserDetection)
Comment on lines +339 to +346
// that web/oauth methods can often resolve
let errorDesc = error.localizedDescription.lowercased()
if errorDesc.contains("could not load usage data")
|| errorDesc.contains("failed to load usage data")
{
return true
}

Comment on lines 338 to 348
// Always fallback for CLI data load failures - these are transient issues
// that web/oauth methods can often resolve
let errorDesc = error.localizedDescription.lowercased()
if errorDesc.contains("could not load usage data")
|| errorDesc.contains("failed to load usage data")
{
return true
}

// For other errors, only fallback in auto mode when web is available
guard context.runtime == .app, context.sourceMode == .auto else { return false }
@johnyoonh johnyoonh changed the title Add Claude CLI fallback to web/oauth on data load failures Add Claude CLI fallback for data load failures Mar 13, 2026
@johnyoonh johnyoonh force-pushed the fix/claude-cli-fallback branch from 464a953 to ae01775 Compare March 13, 2026 03:46
@johnyoonh johnyoonh requested a review from Copilot March 13, 2026 03:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves Claude provider reliability by attempting to detect a specific Claude CLI “usage data load” failure and deciding when to fall back to alternate fetch strategies.

Changes:

  • Adds error-message substring detection for “could not/failed to load usage data” in ClaudeCLIFetchStrategy.shouldFallback.
  • Keeps existing app+auto fallback gating based on web availability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +338 to 352
// For CLI data load failures, fallback only when alternate strategies are available
let errorDesc = error.localizedDescription.lowercased()
if errorDesc.contains("could not load usage data")
|| errorDesc.contains("failed to load usage data")
{
// Only fallback in app+auto mode where web/oauth strategies exist
// In explicit CLI mode, preserve the actionable error message
guard context.runtime == .app, context.sourceMode == .auto else { return false }
return ClaudeWebFetchStrategy.isAvailableForFallback(
context: context,
browserDetection: self.browserDetection)
}

// For other errors, only fallback in auto mode when web is available
guard context.runtime == .app, context.sourceMode == .auto else { return false }
Comment on lines +339 to +348
let errorDesc = error.localizedDescription.lowercased()
if errorDesc.contains("could not load usage data")
|| errorDesc.contains("failed to load usage data")
{
// Only fallback in app+auto mode where web/oauth strategies exist
// In explicit CLI mode, preserve the actionable error message
guard context.runtime == .app, context.sourceMode == .auto else { return false }
return ClaudeWebFetchStrategy.isAvailableForFallback(
context: context,
browserDetection: self.browserDetection)
Comment on lines +343 to +348
// Only fallback in app+auto mode where web/oauth strategies exist
// In explicit CLI mode, preserve the actionable error message
guard context.runtime == .app, context.sourceMode == .auto else { return false }
return ClaudeWebFetchStrategy.isAvailableForFallback(
context: context,
browserDetection: self.browserDetection)
Comment on lines +338 to +342
// For CLI data load failures, fallback only when alternate strategies are available
let errorDesc = error.localizedDescription.lowercased()
if errorDesc.contains("could not load usage data")
|| errorDesc.contains("failed to load usage data")
{
johnyoonh and others added 2 commits March 13, 2026 02:44
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
- Detect 'could not load usage data' errors from Claude CLI
- Automatically fallback to web/oauth when alternate strategies available
- Only fallback in app+auto mode (preserves CLI errors in explicit CLI mode)
- Improves reliability when CLI has transient issues

General reliability improvement - helps when users encounter 'Could not parse Claude usage: Claude CLI could not load usage data' error.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@johnyoonh johnyoonh force-pushed the fix/claude-cli-fallback branch from ae01775 to e1f592c Compare March 13, 2026 07:46
func shouldFallback(on error: Error, context: ProviderFetchContext) -> Bool {
// For CLI data load failures, fallback only when alternate strategies are available
let errorDesc = error.localizedDescription.lowercased()
if errorDesc.contains("could not load usage data")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we walk through how this branch changes the fallback behavior from before? I’m reading both this special case and the default path as still falling back only in app + auto when web is available, so I may be missing what user-visible case now behaves differently.

@ratulsarna ratulsarna added the question Further information is requested label Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants