Repository navigation
fix: Anthropic 流式 Usage Policy SSE 错误与 mapUpstreamError 对齐 (#503) - #505
Merged
Merged
Conversation
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
marked this pull request as ready for review
October 17, 2026 09:20
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.
背景
Fixes #503
非流式路径已通过
mapUpstreamError()将 Anthropic Usage Policy 文案映射为policy_blocked/refusal_guard;Anthropic Messages 流式路径在onEvent中曾原样res.write(line),导致 SSEevent: 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.mjsnode --test test/unit/go-worker-client.test.mjsnpx biome checkon touched filesNote
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.