fix(client): harden chat and agent SSE reliability
This commit is contained in:
@@ -10,6 +10,18 @@ of the WeKnora server / frontend release cadence.
|
||||
CLI history before v0.3 is recorded in the project root
|
||||
[CHANGELOG.md](../CHANGELOG.md) under the release that introduced the CLI.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
- Streaming SDK calls are no longer cut off by the client's default 30-second
|
||||
timeout (explicit `WithTimeout` values remain honored), and SSE data lines
|
||||
up to 4 MiB are accepted.
|
||||
- Terminal `response_type=error, done=true` frames now end SDK stream calls
|
||||
even when the server leaves the HTTP connection open.
|
||||
- Agent accumulation now waits for `response_type=complete` instead of treating
|
||||
per-event `done:true` markers as completion of the whole run.
|
||||
- Reference `parent_chunk_id` / `sub_chunk_id` fields now survive SDK unmarshal.
|
||||
|
||||
## [0.9.0] - 2026-06-10
|
||||
|
||||
### v0.9 — auth/profile model harmonization + flag cleanup
|
||||
|
||||
@@ -47,7 +47,7 @@ func answerEvent(content string) *sdk.AgentStreamResponse {
|
||||
return &sdk.AgentStreamResponse{ResponseType: sdk.AgentResponseTypeAnswer, Content: content}
|
||||
}
|
||||
func doneEvent() *sdk.AgentStreamResponse {
|
||||
return &sdk.AgentStreamResponse{ResponseType: sdk.AgentResponseTypeAnswer, Done: true}
|
||||
return &sdk.AgentStreamResponse{ResponseType: sdk.AgentResponseTypeComplete, Done: true}
|
||||
}
|
||||
func toolCallEvent(id, name string) *sdk.AgentStreamResponse {
|
||||
return &sdk.AgentStreamResponse{
|
||||
|
||||
@@ -477,7 +477,7 @@ func TestMCP_SessionAskToolReturnsToolCalls(t *testing.T) {
|
||||
{ResponseType: sdk.AgentResponseTypeThinking, Content: "agent thinks"},
|
||||
{ResponseType: sdk.AgentResponseTypeToolCall, ID: "tc1", Content: "knowledge_search"},
|
||||
{ResponseType: sdk.AgentResponseTypeAnswer, Content: "agent answer"},
|
||||
{Done: true},
|
||||
{ResponseType: sdk.AgentResponseTypeComplete, Done: true},
|
||||
},
|
||||
}
|
||||
c, _ := newTestServer(t, svc)
|
||||
@@ -523,7 +523,7 @@ func TestTool_SessionAsk(t *testing.T) {
|
||||
agentEvents: []*sdk.AgentStreamResponse{
|
||||
{ResponseType: sdk.AgentResponseTypeAnswer, Content: "result"},
|
||||
{ResponseType: sdk.AgentResponseTypeToolCall, ID: "c1", Content: "knowledge_search"},
|
||||
{Done: true},
|
||||
{ResponseType: sdk.AgentResponseTypeComplete, Done: true},
|
||||
},
|
||||
}
|
||||
c, _ := newTestServer(t, svc)
|
||||
|
||||
@@ -22,8 +22,9 @@ type AgentToolEvent struct {
|
||||
// AgentAccumulator buffers an AgentQAStream callback sequence. Distinct
|
||||
// from Accumulator (KnowledgeQAStream) because the agent event model is
|
||||
// wider - events include thinking / reflection / tool_call / tool_result
|
||||
// / answer / references / error, with a flat `Done bool` on each frame
|
||||
// rather than the ResponseType=complete sentinel KnowledgeQAStream emits.
|
||||
// / answer / references / error / complete. Done is scoped to an individual
|
||||
// event stream (thinking, reflection, answer, etc.); only response_type=complete
|
||||
// terminates the whole agent stream.
|
||||
//
|
||||
// Zero value is ready to use. Not safe for concurrent Append calls - the
|
||||
// SDK callback contract is sequential on a single goroutine.
|
||||
@@ -80,7 +81,10 @@ func (a *AgentAccumulator) Append(r *sdk.AgentStreamResponse) {
|
||||
if r.KnowledgeReferences != nil {
|
||||
a.References = r.KnowledgeReferences
|
||||
}
|
||||
if r.Done {
|
||||
// Thinking / reflection / answer streams each emit their own Done=true
|
||||
// marker before later events arrive. Only the explicit complete frame is
|
||||
// terminal for the whole agent run.
|
||||
if r.ResponseType == sdk.AgentResponseTypeComplete {
|
||||
a.done = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package sse_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/cli/internal/sse"
|
||||
sdk "github.com/Tencent/WeKnora/client"
|
||||
)
|
||||
|
||||
func TestAgentAccumulator_FinalizesOnlyOnComplete(t *testing.T) {
|
||||
a := &sse.AgentAccumulator{}
|
||||
preTerminal := []*sdk.AgentStreamResponse{
|
||||
{ResponseType: sdk.AgentResponseTypeThinking, Content: "think", Done: true},
|
||||
{ResponseType: sdk.AgentResponseTypeToolCall, ID: "call_1", Content: "search"},
|
||||
{ResponseType: sdk.AgentResponseTypeReflection, Content: "reflect", Done: true},
|
||||
{ResponseType: sdk.AgentResponseTypeAnswer, Content: "final answer", Done: true},
|
||||
}
|
||||
for _, event := range preTerminal {
|
||||
a.Append(event)
|
||||
if a.Done() {
|
||||
t.Fatalf("%s Done=true terminated the whole stream", event.ResponseType)
|
||||
}
|
||||
}
|
||||
|
||||
a.Append(&sdk.AgentStreamResponse{ResponseType: sdk.AgentResponseTypeComplete, Done: true})
|
||||
if !a.Done() {
|
||||
t.Fatal("complete event did not terminate the stream")
|
||||
}
|
||||
if got := a.Answer(); got != "final answer" {
|
||||
t.Errorf("answer=%q, want final answer", got)
|
||||
}
|
||||
if got := a.Thinking(); got != "thinkreflect" {
|
||||
t.Errorf("thinking=%q, want thinkreflect", got)
|
||||
}
|
||||
if len(a.ToolEvents) != 1 {
|
||||
t.Errorf("tool_events=%d, want 1", len(a.ToolEvents))
|
||||
}
|
||||
|
||||
a.Append(&sdk.AgentStreamResponse{ResponseType: sdk.AgentResponseTypeAnswer, Content: "late"})
|
||||
if got := a.Answer(); got != "final answer" {
|
||||
t.Errorf("post-complete event was appended: %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user