Skip to content

fix: claude panic - #2804

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/claude-usage-panic
Feb 2, 2026
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/claude-usage-panic

Conversation

@seefs001

@seefs001 seefs001 commented Feb 2, 2026 •

Copy link
Copy Markdown
Collaborator

fix #2757

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced stability when processing Claude API responses, with improved handling of edge cases in streamed conversations and partial data scenarios.

@coderabbitai

coderabbitai Bot commented Feb 2, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR adds defensive nil guards throughout the Claude response handler to prevent nil pointer dereferences. Nil checks are introduced for Message, Usage, and Delta fields across StreamResponseClaude2OpenAI, FormatClaudeResponseInfo, HandleStreamResponseData, and HandleClaudeResponseData functions.

Changes

Cohort / File(s) Summary
Claude Response Nil Safety
relay/channel/claude/relay-claude.go
Added nil checks for claudeResponse.Message, claudeResponse.Usage, and claudeInfo fields before dereferencing. Guarded usage extraction in message_start, content_block_delta, and message_delta paths. Initialized Usage struct when needed and wrapped all nested field accesses to prevent nil-pointer panics during streamed response handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion

Poem

🐰 A rabbit hops through streaming fields,
Where nil pointers once brought panics real,
With guards and checks on every path,
No more dereferencing's wrath!
Safe handling blooms—the message flows,
Through Usage, Delta—now it knows! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: claude panic' directly addresses the main objective: fixing a panic in Claude response handling. It is concise and clearly indicates the primary change.
Linked Issues check ✅ Passed The PR adds defensive nil guards throughout relay-claude.go to prevent nil pointer dereferences in FormatClaudeResponseInfo and related functions, directly addressing issue #2757's panic during stream response handling.
Out of Scope Changes check ✅ Passed All changes in relay-claude.go focus exclusively on adding nil checks and defensive guards to prevent the reported panic, with no unrelated modifications detected.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@Calcium-Ion
Calcium-Ion merged commit 1788fb2 into QuantumNous:main Feb 2, 2026
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
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] Panic: nil pointer dereference in FormatClaudeResponseInfo during stream response handling

2 participants