fix(cli): align stream error handling after output-mode merge

Follow up on #1740/#1741 by typing terminal SSE errors in the SDK,
classifying them as server.error in the CLI/MCP, marking Projector done
on error frames, attaching session_id to MCP stream failures, and
migrating the e2e chat step to the bounded JSON envelope.
This commit is contained in:
wizardchen
2026-07-03 00:27:48 +08:00
committed by lyingbug
parent 9437e1ac3c
commit 1109e85a57
19 changed files with 260 additions and 35 deletions
+1 -6
View File
@@ -65,12 +65,7 @@ func (a *Accumulator) Append(r *sdk.StreamResponse) {
a.AssistantMessageID = r.AssistantMessageID
}
// Capture references whenever they arrive - they may land on a
// dedicated `references` event before the terminal `complete`. Strip the
// bulky per-chunk Content so the buffered envelope stays small: agents
// consume the index (id / parent_chunk_id / title / score / snippet) and
// fetch full passages on demand via `chunk view`. This runs after SSE
// parsing, so it governs outgoing envelope size — the incoming line-size
// limit is the scanner buffer's job, not this one.
// dedicated `references` event before the terminal `complete`.
if r.KnowledgeReferences != nil {
a.References = r.KnowledgeReferences
}
+6
View File
@@ -64,6 +64,9 @@ func (p *Projector) Chat(r *sdk.StreamResponse) (ProjectedEvent, bool) {
if r.ResponseType == sdk.ResponseTypeComplete {
p.done = true
}
if r.ResponseType == sdk.ResponseTypeError && r.Done {
p.done = true
}
responseType := string(r.ResponseType)
isAnswer := r.ResponseType == sdk.ResponseTypeAnswer || (r.ResponseType == "" && r.Content != "")
@@ -103,6 +106,9 @@ func (p *Projector) Agent(r *sdk.AgentStreamResponse) (ProjectedEvent, bool) {
if r.ResponseType == sdk.AgentResponseTypeComplete {
p.done = true
}
if r.ResponseType == sdk.AgentResponseTypeError && r.Done {
p.done = true
}
isAnswer := r.ResponseType == sdk.AgentResponseTypeAnswer
isReference := r.ResponseType == sdk.AgentResponseTypeReferences
+22
View File
@@ -111,6 +111,28 @@ func TestProjector_VerboseDoesNotImplicitlyAddReferences(t *testing.T) {
}
}
func TestProjector_TerminalErrorMarksDone(t *testing.T) {
p := sse.NewProjector(false, false, "kb")
_, include := p.Chat(&sdk.StreamResponse{
ResponseType: sdk.ResponseTypeAnswer,
Content: "partial",
})
if !include || p.Done() {
t.Fatalf("answer frame: include=%v done=%v", include, p.Done())
}
_, include = p.Chat(&sdk.StreamResponse{
ResponseType: sdk.ResponseTypeError,
Content: "boom",
Done: true,
})
if include {
t.Fatal("default projection should not include terminal error event")
}
if !p.Done() {
t.Fatal("terminal error did not mark projector done")
}
}
func TestTextRenderer_StreamsSelectedEvents(t *testing.T) {
var out bytes.Buffer
r := sse.NewTextRenderer(&out, true)