fix(client): harden chat and agent SSE reliability#1740
Open
coconut-yc wants to merge 1 commit into
Open
Conversation
11 tasks
6ff0f7b to
1898dd9
Compare
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.
Description
Fixes the streaming and response-fidelity defects reported in #1738 against
the
mainbaseae9038732ad2. This PR is intentionally limited to the SDKreaders and the existing CLI/MCP accumulators; it does not change the CLI output
contract.
Client.doRequestStreamexcludes the ordinary 30-second default fromKnowledgeQAStream,ContinueStream, andAgentQAStreamWithRequest. Stream lifetime is governed by context cancellation. The publicWithTimeoutcontract is preserved: when callers explicitly configure it, the same upper bound still applies to streaming calls.bufio.Scannerper-line cap from 64 KiB to 4 MiB, covering reference events of hundreds of KiB while retaining a bounded allocation.response_type=error, done=trueframe is delivered to the callback and then returned as an SDK error, even when the server leaves the connection open withoutcompleteor EOF.AgentAccumulatornow terminates only onresponse_type=completevia the newAgentResponseTypeCompleteconstant. Intermediate thinking/reflection/answerdone:truemarkers no longer discard later tool events or the final answer.SearchResult.KnowledgeBaseID,ParentChunkID, andSubChunkIDpreserveknowledge_base_id,parent_chunk_id, andsub_chunk_idfrom reference events.The follow-up agent-output PR, #1741, is stacked on this fix and separately changes the CLI/MCP output contract. It adds bounded defaults,
--reference,--verbose, human-readable text, and an explicit raw NDJSON mode.Scope Boundary
The fix commit contains only:
client/client.go,client/agent.go,client/session.go,client/knowledgebase.go,client/streaming_test.gocli/internal/sse/agent_accumulator.goand its testcli/cmd/session/ask_test.goandcli/internal/mcp/tools_test.gocli/CHANGELOG.md[Unreleased]It does not contain projected events, buffered envelopes,
--reference,--verbose, or other output-contract changes.Type of Change
cli/CHANGELOG.md)Related Issue
Fixes #1738
Testing
New regression coverage verifies:
KnowledgeQAStreamandContinueStreameach accept a 256 KiB reference event;WithTimeoutremains enforced;knowledge_base_id,parent_chunk_id, andsub_chunk_idsurvive JSON decoding;AgentAccumulatorignores intermediatedone:trueand finalizes onresponse_type=complete.Validated locally:
Checklist
git diff --checkpassesWithTimeoutbehavior remains compatibleScreenshots / Recordings
N/A — SDK / CLI internals only.