Skip to content

Preserve exact chat outcomes across stream closure and reattachment - #851

Merged
WaylandYang merged 2 commits into
deeplethe:devfrom
Maya-Kid:fix/chat-stream-terminal-contract
Sep 21, 2026
Merged

WaylandYang merged 2 commits into
deeplethe:devfrom
Maya-Kid:fix/chat-stream-terminal-contract

Conversation

@Maya-Kid

@Maya-Kid Maya-Kid commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Latest dev synchronization (2026-09-21)

Based on dev@474b904dc3e8014d42404a3c067af9906036a953; current head 7a3524c605a1982a4a357658e20acd979f9b54f6.

Conflict resolution retained both upstream chat_terminal_tests and this PR’s stream_tests, each behind cfg(test).

Revalidated the combined integration tree 6cd976351b4d7cc7389730fce530526f4d197992 on isolated Linux PostgreSQL fixtures (all 675 tracked source files hash-matched):

The evidence-only handoff core remains frozen. Earlier validation below belongs to its stated historical heads. Automated browser checks do not replace the maintainer's requested visual review.


A normal Chat SSE connection currently invokes onDone twice; error, idle, or unterminated EOF also reaches the unconditional success callback. A reattachment between the server's terminal broadcast and registry removal receives a snapshot without that terminal.

Preserve the first done/error alongside the internal snapshot, under the existing snapshot/subscription lock. Late subscribers receive the unchanged snapshot JSON followed by the same terminal. Finished entries still return idle.

The shared browser consumer accepts one application terminal, reports unterminated EOF as an interruption, treats idle as reattachment-only, and cancels/releases its reader. It handles LF/CRLF/CR, split UTF-8 and multiline data without dispatching incomplete EOF fragments. No POST retry is added.

Validation:

  • The real Registry + SSE handler regression fails before the patch, then passes for done/error on both sides of terminal emission. Additional tests cover first-terminal freezing and lagged subscribers.
  • Tests import the actual streamChat/reattachChat. Eleven initial cases failed on the old consumer; all 13 now pass, covering terminal multiplicity, abort, malformed/incomplete frames, bytewise Unicode/line endings, and cancellation failure.
  • Full frontend suite: 129 tests pass; production build/typecheck/style guard pass. The Keep late chat callbacks from finishing a follow-up answer #763 stale-handle guards remain unchanged and tested; its delayed-stream-cleanup regression now expects one completion instead of relying on the duplicate callback.
  • Linux Rust formatting, strict workspace clippy and three server stream tests pass. Frontend uses Node 22.23.2 / pnpm 10.2.1. No paid model calls.

Existing event meanings are restored without new wire fields, durable event storage or cancellation of server generation. Registry ownership (#848) and the history-to-idle handoff are separate fixes.

Additional integration validation: isolated tree f7bcd0878bf490d6efb122b71d6f13d379df4709 combines this change with #845 and the other scoped Chat fixes. Linux Rust fmt, strict workspace Clippy, workspace build and 1,013 tests pass (one pre-existing external-HTTPS RSS test ignored); frontend 129 module tests, 27 real-component browser subtests and build pass. Database/PDF test guards were enabled. This combined result is separate from the standalone checks above.

The actual browser/backend integration additionally verifies live reattachment while a local scripted model is gated, the idle/history handoff, and a real fallback assistant INSERT rejection: the browser retains the safe error and generated text after EOF.

Signed-off-by: dada-yan <BinjunYann@gmail.com>
@Maya-Kid
Maya-Kid force-pushed the fix/chat-stream-terminal-contract branch from 147dba7 to 7a3524c Compare September 21, 2026 10:25
@WaylandYang
WaylandYang merged commit 7cf5b0c into deeplethe:dev Sep 21, 2026
4 checks passed
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.

2 participants