Skip to content

fix: normalize non-standard errors from anthropic-format 3rd-party APIs#452

Open
brotherlang8888 wants to merge 1 commit into
NanmiCoder:mainfrom
brotherlang8888:fix/anthropic-passthrough-error-normalization
Open

fix: normalize non-standard errors from anthropic-format 3rd-party APIs#452
brotherlang8888 wants to merge 1 commit into
NanmiCoder:mainfrom
brotherlang8888:fix/anthropic-passthrough-error-normalization

Conversation

@brotherlang8888
Copy link
Copy Markdown

Summary

  • Routes anthropic-format providers through the local proxy (passthrough mode) instead of bypassing it
  • Normalizes non-standard upstream error responses to proper Anthropic format
  • Prevents conversation history corruption and cascade failures

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 AssistantMessage that got injected into conversation history. On subsequent requests, the corrupted history was re-sent to the API → another error → infinite cascade. Only /clear could recover.

Fix

  • handler.ts: Remove the "proxy not needed" rejection for anthropic format. Add handleAnthropicPassthrough that forwards requests/responses through unchanged, but intercepts error responses and normalizes them via normalizeAnthropicError() to:
    {"type":"error","error":{"type":"invalid_request_error","message":"..."}}
  • providerService.ts: Route anthropic-format providers through the proxy (change needsProxy condition from apiFormat != null && apiFormat !== 'anthropic' to apiFormat != null)

Test plan

  • 41 proxy transform + streaming tests pass
  • Test with step-router-v1: trigger image error → text follow-up should work (no cascade)
  • Test with step-router-v1: trigger ToolSearch/deferred tool error → text follow-up should work

Additional requests

  1. Skills not loading after restart: After restarting the app, user-installed skills are no longer loaded. This may be a separate issue worth investigating.

  2. 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

…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>
@github-actions
Copy link
Copy Markdown

PR quality triage

Changed areas: area:server

CLI core policy: No CLI-core policy block detected.

Missing-test policy: Blocked by policy until a maintainer applies allow-missing-tests or matching tests are added.

Coverage baseline policy: No coverage-baseline policy block detected.

CLI core files:

  • none

Coverage policy files:

  • none

Expected checks:

  • change-policy
  • desktop-checks
  • server-checks
  • desktop-native-checks
  • coverage-checks

Test coverage signals:

  • BLOCKING unless allow-missing-tests is applied: Server product files changed without a server test file in the PR.

Risk notes:

  • Provider/search behavior changed: PR gate uses mock tests; live-provider tests stay maintainer-only.

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.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels May 14, 2026
@brotherlang8888
Copy link
Copy Markdown
Author

brotherlang8888 commented May 14, 2026 via email

@zhbdesign
Copy link
Copy Markdown

我也遇到这个问题,会合并吗,异常以后会话就不能再继续了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:server bug Something isn't working needs-maintainer-approval size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants