Skip to content

fix(stream): decode complete SSE events and preserve cancellation - #1257

Merged
XuPeng-SH merged 4 commits into
mainfrom
fix/session-stream-recovery
Nov 10, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
fix/session-stream-recovery

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Capability assessment: Unchanged: existing model and agent capabilities are retained; stream decoding, cancellation, and diagnostic accuracy are corrected.

Summary

Decode each SSE event once after its data fields are joined, across provider inference, model checks and Astra clients. Preserve event order and terminal boundaries while local tools are running. Carry the existing incremental framer through Edge read-ahead so split CRLF and UTF-8 boundaries cannot manufacture or lose events.

Keep validated clean-EOF control events usable for cancellation. Process complete provider terminal events at a clean EOF through the same validation as framed events. Correct misleading retry, background-task and destructive-command feedback, and label persisted execution counters that can lag active work.

The affected session recorded malformed SSE JSON but did not retain its upstream bytes. The reproduced decoder defect is a plausible cause, not proof of that session's exact failure.

Related issue

None.

Change type

  • Bug fix
  • Documentation
  • Refactor or performance improvement
  • Test

User and compatibility impact

Legal multiline and no-space SSE data fields are handled consistently. Complete final payloads at a clean EOF still need a validated semantic terminal; truncated or nonterminal provider responses fail. Astra control streams retain their clean-EOF terminal behavior. Messages now describe actual recovery and background-task capabilities.

Architecture and complexity delta

  • Canonical owner changed or extended: the existing core SSE framer and shared event decoder.
  • Existing implementations and callers searched: Chat Completions, Responses inference and model probing, internal turn host and thin-client streams.
  • Superseded code, states, tables, shims, or self-only tests removed: line-by-line JSON decoding, duplicate framing and obsolete tests that pinned non-SSE behavior.
  • If parallel implementations remain, their boundary and retirement condition: provider terminal validation and Astra control EOF semantics remain distinct protocol contracts.

Verification

  • Review fixes: cargo test -p astra-turn-core --lib sse::stream_host::tests -- --test-threads=1 (86 passed), make format-check, and cargo clippy --locked -p astra-turn-core -p astra-cli --lib -- -D warnings passed. Cases cover malformed frames with active tools, terminal ordering across chunks, clean EOF, and a non-fused source.
  • On the previous head 611ebf95a, CI online core-runtime/integration, MOI fresh-Astra compatibility, lint and live harness passed. The new head has triggered CI again.
  • Reproduced the failed online Responses continuation test against an isolated MatrixOne instance, then passed it with the clean-EOF fix. Targeted clean-EOF, malformed/truncated response, model-probe, and judge-classification tests passed.
  • The live Harness judge returned an unknown assessment in CI; the diagnostic now classifies that as verification unavailable rather than a negative quality verdict. The case still fails when no assessment is available.
  • make format-check and cargo clippy --locked -p astra-core -p astra-services -p astra-runtime -p astra-test-harness --tests -- -D warnings passed for this CI fix.
  • The isolated MatrixOne test covered Responses continuation; no database schema, queries, or writes changed.

Earlier verification, on commit 7fddf65 before the CI fix:

  • cargo test -p astra-turn-core --lib sse -- --test-threads=1 (361 passed) and cargo test -p astra-turn-core --test sse_events (3 passed).
  • Targeted core framer, Responses accumulator, thin-client streaming, runtime Chat/Responses, service model-probe and CLI regression tests passed. The same affected selections passed with RUSTFLAGS=-Zsanitizer=thread cargo +nightly test -Zbuild-std --target aarch64-apple-darwin; the runtime Responses test reused the instrumented test binary built from the same source.
  • make format-check; cargo clippy --locked -p astra-core -p astra-thin-client -p astra-turn-core -p astra-runtime -p astra-services -p astra-cli --all-targets -- -D warnings; python3 scripts/ci/validate_repository.py; PR metadata check: passed.
  • The full MOI database gate was not run locally; its tests and contract are unchanged and remain covered by CI.
  • Public entrypoint exercised: classified chat streaming and model-probe HTTP responses, including open connections and EOF terminal events.
  • Unhappy paths exercised: malformed or truncated payloads, terminal ordering, arbitrary byte boundaries, frame limits, failed terminal control, and active tool cancellation.

Final checklist

  • I added or updated tests at the layer that owns the behavior, or explained why no test is needed.
  • I updated public or design documentation for contract changes, or the change needs no documentation update.
  • I checked the diff for credentials, private URLs, customer data, generated files, and other sensitive information.
  • The PR title follows the repository's Conventional Commit format.

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: two reproducible stream read-ahead defects remain. GitHub does not permit the author account to submit a formal request-changes review on its own PR. The Responses CI regression is being fixed separately without changing the MOI gate.

@XuPeng-SH
XuPeng-SH merged commit 3c01292 into main Nov 10, 2026
40 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/session-stream-recovery branch November 10, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant