Skip to content

fix: stop retrying LLM payment errors#48

Merged
Moskize91 merged 1 commit into
mainfrom
fix/llm-payment-required
May 19, 2026
Merged

fix: stop retrying LLM payment errors#48
Moskize91 merged 1 commit into
mainfrom
fix/llm-payment-required

Conversation

@Moskize91

Copy link
Copy Markdown
Contributor

Summary

  • add a public LLMPaymentRequiredError for HTTP 402 LLM failures
  • stop retrying payment-required API errors even when the SDK marks them retryable
  • print a stable CLI billing message for payment-required failures

Tests

  • pnpm run lint:fix
  • pnpm typecheck
  • pnpm test:run

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 36b62a28-ef3f-4312-a7ff-69013ed3e8dd

📥 Commits

Reviewing files that changed from the base of the PR and between f8fbbf3 and df5f32a.

📒 Files selected for processing (7)
  • src/cli/main.ts
  • src/index.ts
  • src/llm/client.ts
  • src/llm/errors.ts
  • src/llm/index.ts
  • test/cli/main.test.ts
  • test/llm/client.test.ts

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of LLM payment required errors with clear, user-friendly messaging and immediate exit instead of retry attempts.

Walkthrough

This PR introduces end-to-end handling of HTTP 402 "payment required" responses from LLM API providers. A new LLMPaymentRequiredError class is defined with fixed isRetryable=false and statusCode=402 properties. The LLM client detects HTTP 402 responses via a new isPaymentRequiredError predicate, wraps them into the error class, logs the event, and throws immediately without retrying. The error is exported through module indexes for public use. The CLI catches this error and displays a stable, user-facing "LLM payment required" message to stderr. Tests verify both the client wrapping behavior (normalizing retryability across varying provider responses) and the CLI formatting output.

Sequence Diagram

sequenceDiagram
  participant CLI as CLI Main
  participant Convert as Convert Command
  participant LLMClient as LLM Client
  participant Provider as LLM Provider
  CLI->>Convert: execute convert
  Convert->>LLMClient: request LLM
  LLMClient->>Provider: call generateText
  Provider-->>LLMClient: HTTP 402 APICallError
  LLMClient->>LLMClient: isPaymentRequiredError check
  LLMClient->>LLMClient: wrap in LLMPaymentRequiredError
  LLMClient-->>Convert: throw LLMPaymentRequiredError
  Convert-->>CLI: reject with LLMPaymentRequiredError
  CLI->>CLI: formatCLIError handler
  CLI->>CLI: write "LLM payment required." to stderr
  CLI->>CLI: set process.exitCode = 1
Loading

Possibly related PRs

  • oomol-lab/spinedigest#32: Modifies isRetryableError and retry classification in src/llm/client.ts to add special-case handling for error types.
  • oomol-lab/spinedigest#24: Updates src/cli/main.ts error formatting and stderr handling in the main() error path.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title follows the required format 'type(scope): subject' with type 'fix' and a clear subject describing the main change to stop retrying LLM payment errors.
Description check ✅ Passed The PR description is directly related to the changeset, clearly explaining the three main changes: adding LLMPaymentRequiredError, preventing retries for payment errors, and printing a stable CLI message.
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
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/llm-payment-required

Comment @coderabbitai help to get the list of available commands and usage tips.

@Moskize91 Moskize91 merged commit 6b73c44 into main May 19, 2026
3 checks passed
@Moskize91 Moskize91 deleted the fix/llm-payment-required branch May 19, 2026 07:33
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