fix: normalize non-standard errors from anthropic-format 3rd-party APIs#452
Open
brotherlang8888 wants to merge 1 commit into
Open
Conversation
…APIs
Third-party Anthropic-compatible APIs (e.g. step-router-v1) often return
errors in non-standard shapes like:
{"error":{"message":"...","type":"input_invalid"}}
Previously, anthropic-format providers bypassed the proxy entirely. When
these APIs returned errors, cc-haha injected a malformed AssistantMessage
into conversation history, causing a cascade failure on every subsequent
request (only /clear could recover).
This change:
1. Routes anthropic-format providers through the proxy (passthrough mode)
2. Normalizes non-standard error responses to proper Anthropic format:
{type:"error", error:{type:"...", message:"..."}}
3. Passes through successful responses unchanged
Fixes the cascade failure issue reported with step-router-v1 where any
error (image reading, deferred tools, unrecognized tool calls) would
permanently corrupt the conversation until /clear.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
PR quality triageChanged areas: area:server CLI core policy: No CLI-core policy block detected. Missing-test policy: Blocked by policy until a maintainer applies Coverage baseline policy: No coverage-baseline policy block detected. CLI core files:
Coverage policy files:
Expected checks:
Test coverage signals:
Risk notes:
Hard merge gates still come from GitHub Actions, not AI review. Dosu handoff: Dosu can be used as the AI reviewer for risk explanation, missing-test prompts, and maintainer Q&A. If it does not comment automatically from the PR template, ask: @dosubot review this PR for changed-area risk, missing tests, docs impact, desktop startup risk, and CLI core impact. |
Author
|
这是来自QQ邮箱的假期自动回复邮件。收到了你的邮件,请确认你的发送时间
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
When using third-party Anthropic-compatible APIs like step-router-v1, any API error (image reading, deferred tools, unrecognized tool calls) returns non-standard error shapes:
{"error":{"message":"The input you provided is invalid","type":"input_invalid"}}Since anthropic-format providers bypassed the proxy, these raw errors went straight to cc-haha's error handler. The handler produced a malformed
AssistantMessagethat got injected into conversation history. On subsequent requests, the corrupted history was re-sent to the API → another error → infinite cascade. Only/clearcould recover.Fix
handleAnthropicPassthroughthat forwards requests/responses through unchanged, but intercepts error responses and normalizes them vianormalizeAnthropicError()to:{"type":"error","error":{"type":"invalid_request_error","message":"..."}}needsProxycondition fromapiFormat != null && apiFormat !== 'anthropic'toapiFormat != null)Test plan
Additional requests
Skills not loading after restart: After restarting the app, user-installed skills are no longer loaded. This may be a separate issue worth investigating.
OpenAI format support: Would it be possible to add an OpenAI-format proxy mode that converts Anthropic messages ↔ OpenAI Chat Completions format? This would help providers that only support OpenAI-compatible APIs.
🤖 Generated with Claude Code