Skip to content

fix(proxy): emit standard Anthropic error event on upstream stream failure - #3371

Merged
lbjlaq merged 2 commits into
lbjlaq:mainfrom
johngbl:pr/fix-claude-stream-error-format
Sep 2, 2026
Merged

fix(proxy): emit standard Anthropic error event on upstream stream failure#3371
lbjlaq merged 2 commits into
lbjlaq:mainfrom
johngbl:pr/fix-claude-stream-error-format

Conversation

@johngbl

@johngbl johngbl commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Problema

Quando a conexão com o upstream Gemini cai no meio do stream, o proxy emitia um evento de erro malformado:

data: {"error":{"message":"Stream error: ...","type":"stream_error"}}

Faltava o discriminador "type": "error" no topo do objeto. O cliente (opencode / @ai-sdk/anthropic) valida cada payload SSE com um discriminated union no campo type do nível raiz, resultando em:

Type validation failed: invalid_union / "No matching discriminator" no path ["type"]

Correção

src-tauri/src/proxy/mappers/claude/mod.rs — agora emite o evento no formato padrão Anthropic:

event: error
data: {"type":"error","error":{"type":"overloaded_error","message":"..."}}

Usando o mesmo helper state.emit("error", ...) já utilizado em streaming.rs:615-624, garantindo consistência.

Verificação

  • cargo check compila
  • Suíte proxy::mappers::claude: 39 passam; as 4 falhas restantes são pré-existentes em request.rs (max_tokens/budget), não relacionadas a esta mudança (confirmado via git stash)

Ensure claude-opus-4-5 and claude-opus-4-6 (base) expose the same thinking variants as sonnet (low/medium/high/max) via ClaudeThinking. Previously only the -thinking suffix had variants, so syncing the base id produced no variants and dropdown showed without thinking.

Also align Gemini3Pro variant order to low -> medium(disabled) -> high -> max(disabled) for consistent Default -> Low -> Medium -> High ordering.
@lbjlaq
lbjlaq merged commit 7631415 into lbjlaq:main Sep 2, 2026
4 of 7 checks passed
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.

2 participants