Skip to content

fix: Anthropic 流式 Usage Policy SSE 错误与 mapUpstreamError 对齐 (#503) - #505

Merged
dofastted merged 1 commit into
mainfrom
cursor/stream-anthropic-policy-sse-503-4357
Oct 17, 2026
Merged

dofastted merged 1 commit into
mainfrom
cursor/stream-anthropic-policy-sse-503-4357

Conversation

@dofastted

@dofastted dofastted commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

背景

Fixes #503

非流式路径已通过 mapUpstreamError() 将 Anthropic Usage Policy 文案映射为 policy_blocked / refusal_guard;Anthropic Messages 流式路径在 onEvent 中曾原样 res.write(line),导致 SSE event: error 仍可能保留上游的 invalid_request_error / upstream_invalid_request。

变更

  • 新增 createAnthropicSseErrorRemapper():在写出 Anthropic 原生 SSE 时,对 event: error 的 data: 行调用 mapUpstreamError + rewritePoolErrorForClient,与 mapProtocolClientError 分类一致;流已开始时 HTTP 200 不变。
  • handle-protocol.mjs 流式 anthropic.messages 分支在写入前经 remapper 处理。
  • 将 semanticStatusForStreamError 抽到 stream-error-status.mjs,避免 stream-truncation 依赖整个 go-worker 客户端模块。
  • 回归测试:test/unit/stream-truncation.test.mjs(合成 Usage Policy SSE)。
  • CHANGELOG.md「未发布」一行([Bug] Usage Policy 错误的流式路径与 policy_blocked 映射是否一致 (1.3.169) #503)。

未修改 VERSION;未改动 rememberRefusal / 拒答缓存逻辑。

Test plan

  • node --test test/unit/stream-truncation.test.mjs
  • node --test test/unit/go-worker-client.test.mjs
  • npx biome check on touched files
  • CI unit job
Open in Web Open in Cursor 

Note

Low Risk
Targeted change to Anthropic native SSE error lines on an existing mapping path; low risk with new unit tests and no auth or persistence changes.

Reviewed by Cursor Bugbot for commit 03e0067. Configure here.

Apply mapUpstreamError when forwarding upstream event:error SSE lines
so streaming clients see policy_blocked/refusal_guard like non-streaming.

Extract semanticStatusForStreamError for reuse without pulling the worker
client into stream-truncation. Add regression tests and CHANGELOG entry.

Co-authored-by: ted <kuhlmangarry24@gmail.com>
@dofastted
dofastted marked this pull request as ready for review October 17, 2026 09:20
@dofastted
dofastted merged commit 2a52ba1 into main Oct 17, 2026
8 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.

[Bug] Usage Policy 错误的流式路径与 policy_blocked 映射是否一致 (1.3.169)

2 participants