Skip to content

feat(chat): add mid-run steering and stable history replay - #88

Merged
Luhaozhu merged 2 commits into
mainfrom
feat/chat-steering-history-replay
Aug 13, 2026
Merged

feat(chat): add mid-run steering and stable history replay#88
Luhaozhu merged 2 commits into
mainfrom
feat/chat-steering-history-replay

Conversation

@Luhaozhu

Copy link
Copy Markdown
Contributor

Summary

  • queue follow-up messages while a chat run is active and apply them as steering instructions at safe execution boundaries
  • preserve interrupted tool-call state and split steered continuations into chronological history messages
  • normalize inline </think> reasoning and structured reasoning fields without fragmenting the visible answer
  • keep live tool execution details available while collapsing historical tool runs by default after a refresh
  • document the steering API and history replay behavior, with backend and frontend regression coverage

Why

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

  • relevant backend regression suite: 58 passed
  • npm run test:chat-stream
  • npm run build
  • python scripts/build_ce.py --allow-dirty --import-check --pytest-check --frontend-check
  • CE import/OpenAPI/ORM checks, release regression tests, brand gate, and frontend build all passed

Luhaozhu and others added 2 commits August 13, 2026 04:45
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
Luhaozhu force-pushed the feat/chat-steering-history-replay branch from fba9451 to c66dc98 Compare August 13, 2026 09:00
@Luhaozhu
Luhaozhu merged commit 7ca00d6 into main Aug 13, 2026
5 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.

1 participant