feat(chat): add mid-run steering and stable history replay - #88
Merged
Conversation
Structured-reasoning models can deliver the tail of a thinking sentence after the first answer token has streamed. The live view already folds that late delta back into the previous thinking block, but persistence flushed it in place, writing think blocks that cut the visible answer mid-sentence and made refreshed history look reordered around tool calls. Persistence (both streaming paths): - _flush_thinking mirrors the live merge rule: once the answer has started and a previous think block exists, buffered reasoning is inserted back into that block, and recorded content_offset values after the insertion point are shifted to stay aligned with the persisted content - content_replace clears stale offsets (they reference the replaced draft's coordinates), so replay falls back to merged rendering instead of wrong cuts - offsets are also backfilled after tool_result, covering entries appended without a preceding tool_call event Frontend replay: - rebuild history segments from recorded offsets so text and tool cards interleave exactly as streamed; messages without offsets keep the merged fallback - segmentTextSlice heals already-persisted rows: a late thinking tail merges into the previous thinking block and the punctured sentence rejoins seamlessly - hard rule liftTrailingSegmentsAboveFinalText shared by history rebuild and stream wind-down: tool cards and thinking blocks never render below the final answer, so the layout no longer jumps after a refresh - artifact pseudo-cards (no offsets by nature) sort to the end instead of knocking the whole message back to stacked rendering Regression cases added to test-chat-stream-segments for offset interleave, the punctured-sentence heal, single-character fragment merge, and trailing artifact cards.
Luhaozhu
force-pushed
the
feat/chat-steering-history-replay
branch
from
August 13, 2026 09:00
fba9451 to
c66dc98
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.
Summary
</think>reasoning and structured reasoning fields without fragmenting the visible answerWhy
Previously, follow-up messages had to wait for the active response to finish, and replaying a saved conversation could reorder reasoning and tool calls or split the final response into multiple blocks. Tool details also reopened after every refresh. This change keeps live and persisted conversations consistent across supported model reasoning protocols.
Validation
npm run test:chat-streamnpm run buildpython scripts/build_ce.py --allow-dirty --import-check --pytest-check --frontend-check