chat: preserve transcript order when refreshing history - #339458
Open
Osvaldo Ortega (osortega) wants to merge 2 commits into
Open
Osvaldo Ortega (osortega) wants to merge 2 commits into
Osvaldo Ortega (osortega) wants to merge 2 commits into
Conversation
Reconcile refreshed history by request identity and replace changed turns in their existing model and view positions instead of appending them after local messages. Preserve drafts, local responses, and streaming deferral while supporting older history insertion. Dispose superseded response listeners and publish removals after updating the request list so last-request state and session cost remain current. Add real service/model/view regressions for ordering, identity, streaming, and history removals. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
ID-less history prepends can reassign generated identities to the wrong turns.
Review effort: Balanced
Findings: 1
What changed in this PR
Preserves chat transcript ordering during passive history refreshes while retaining local turns and drafts.
Changes:
- Reconciles history by request ID and inserts turns at stable positions.
- Updates model/view replacement and disposal handling.
- Adds regression coverage for ordering, streaming, removals, and metadata updates.
| File | Description |
|---|---|
chatServiceImpl.ts |
Reconciles refreshed history turns. |
chatModel.ts |
Supports indexed request replacement. |
chatViewModel.ts |
Maintains view order and listener lifetimes. |
chatInputPart.ts |
Refreshes cost state and response listeners. |
chatService.test.ts |
Adds history-refresh regressions. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Screenshot ChangesBase: Changed (2)2 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details. |
Replace positional fallback with unique request-content matching in both the previous and incoming history. Preserve provider IDs, avoid assigning ambiguous duplicates another turn's local identity, and keep identical history refreshes as no-ops. Cover ID-less history prepends, removals, and one-to-many and many-to-one ambiguous matches with real model/view regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Osvaldo Ortega (osortega)
marked this pull request as ready for review
October 3, 2026 07:45
Osvaldo Ortega (osortega)
enabled auto-merge (squash)
October 3, 2026 07:45
This branch has not been deployed
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
Refreshing an older response could move it below a newer locally sent message. The history merger removed and rebuilt the changed suffix, kept local requests in place, and appended the rebuilt turns at the end. Even an elapsed-time or usage update could change the visible conversation order.
This is independent of the authentication-recovery changes in #339454. It does not change the protocol client, authentication, or host-side persistence.
Validation
[README, hi]becomes[hi, README]despite correctly ordered incoming history.Manual verification
Open a restored remote chat, send and complete a new message, then trigger a history refresh (for example, return after switching apps). Confirm earlier turns remain above the newer message, response text stays visible, and the unsent draft is preserved. Also load older history and verify it is inserted before the existing turns without duplication.
A turn also missing from another client's history is not proof of a display-order bug; this PR does not claim to repair missing host-side history.