fix(runtime): 上游错误体统一走 trace.UpstreamError,正文不进 error
M41 的「LLM / embedding / 视觉 上游错误体」一族(M38 #5 #6 #7 #8 #9 #14): 非 2xx 时把响应体截断后拼进 error,而 error 会被 chat run / loop step / retrieve_fallback 打日志,等于把她的提问、记忆正文、要念的台词写进日志。 - model:openai/anthropic 两处 upstreamError 收口到 upstream.go 的 providerUpstreamError;anthropic 流内 error 事件的 evt.Error.Message (原本无上限)整段丢弃,只保留令牌形状的 type - embedding:readErrorBody 删除,改走 helper(input 就是她的记忆正文) - vision:错误路径不再沿用取图的 50 MiB 上限,改为 4 KiB 有界读且不拼原文 - voice:classifyDashscopeStatus 只解 code/request_id,正文只留在内存里做 分类判据;错误体读取同样改为 4 KiB 有界 - 测试:五个上游各一条「日志/error 里搜不到哨兵正文」用例,且能变异打红
This commit is contained in:
1 parent
46a6da13e0
commit
66dda084cd
16 files changed
+570
-183
No files matched your search
@@ -61,8 +61,8 @@ type streamBlock struct {
|
||||
// tool_call_delta 事件转发(片段由 tool_call_start/tool_call_end 包起来),
|
||||
// 并按块累积,以便块结束时重新拼装成结构化的 Args map。
|
||||
// 流必须以 message_stop 事件终止,
|
||||
// 否则返回 ErrStream。
|
||||
func scanAnthropicSSE(r io.Reader, onEvent func(StreamEvent)) (Response, error) {
|
||||
// 否则返回 ErrStream。upstream 只用于给流内 error 事件标注「打到哪」。
|
||||
func scanAnthropicSSE(upstream string, r io.Reader, onEvent func(StreamEvent)) (Response, error) {
|
||||
scanner := bufio.NewScanner(r)
|
||||
scanner.Buffer(make([]byte, 0, sseBufInit), maxSSELineBytes)
|
||||
agg := Response{}
|
||||
@@ -84,7 +84,7 @@ func scanAnthropicSSE(r io.Reader, onEvent func(StreamEvent)) (Response, error)
|
||||
if err := json.Unmarshal([]byte(data), &evt); err != nil {
|
||||
return Response{}, fmt.Errorf("model: %w: decode stream chunk: %v", ErrUpstream, err)
|
||||
}
|
||||
if err := applyAnthropicEvent(&agg, blocks, &order, &text, evt, onEvent); err != nil {
|
||||
if err := applyAnthropicEvent(&agg, blocks, &order, &text, evt, onEvent, upstream); err != nil {
|
||||
return Response{}, err
|
||||
}
|
||||
if evt.Type == "message_stop" {
|
||||
@@ -101,7 +101,8 @@ func scanAnthropicSSE(r io.Reader, onEvent func(StreamEvent)) (Response, error)
|
||||
return agg, nil
|
||||
}
|
||||
|
||||
// applyAnthropicEvent 把单个流事件折叠进正在运行的聚合状态。
|
||||
// applyAnthropicEvent 把单个流事件折叠进正在运行的聚合状态。upstream 只用于给
|
||||
// error 事件标注「打到哪」,不参与任何成功路径。
|
||||
func applyAnthropicEvent(
|
||||
agg *Response,
|
||||
blocks map[int]*streamBlock,
|
||||
@@ -109,6 +110,7 @@ func applyAnthropicEvent(
|
||||
text *strings.Builder,
|
||||
evt anthropicStreamEvent,
|
||||
onEvent func(StreamEvent),
|
||||
upstream string,
|
||||
) error {
|
||||
switch evt.Type {
|
||||
case "message_start":
|
||||
@@ -213,7 +215,7 @@ func applyAnthropicEvent(
|
||||
}
|
||||
case "error":
|
||||
if evt.Error != nil {
|
||||
return fmt.Errorf("model: %w: anthropic stream error: %s: %s", ErrUpstream, evt.Error.Type, evt.Error.Message)
|
||||
return streamEventError(upstream, evt.Error)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user