Skip to content

Reuse text buffers in chat edits for checkpoint replay - #336095

Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
mainfrom
agents/vscode-keep-undo-restore-issue-fix
Sep 15, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 1 commit into
mainfrom
agents/vscode-keep-undo-restore-issue-fix

Conversation

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Summary

Addresses the renderer-freeze portion of #296064. Checkpoint reconstruction currently rebuilds a text buffer from the entire file for every recorded text edit operation, repeatedly scanning and copying the same content on the renderer thread.

  • Reuse one buffer across consecutive ordinary-text edit operations, applying each batch in order rather than flattening ranges from different document versions.
  • Stop batching at file lifecycle boundaries and leave notebook replay on its existing path.
  • Preserve the existing inter-batch BOM and default-EOL normalization, and dispose the buffer when replay succeeds or throws.
  • Add deterministic buffer-creation/disposal regressions and coverage for dependent ranges, LF/CRLF, UTF-16, no-op reconstruction, concurrent snapshots, errors, and file recreation.

No public API, persistence-format, configuration, or UI changes. This does not claim to resolve the separately reported incomplete-file-restoration behavior, which was not reproduced.

Validation

  • npm run gulp compile-client — zero errors.
  • Targeted node build/hygiene.ts on both changed files — passed.
  • 98 tests passed across checkpoint timeline, chat editing actions, editing service, and modified notebook entry suites using scripts/test.bat.
  • Confirmed the buffer-reuse and error-cleanup regression tests fail on the original implementation and pass with this change.
  • Three recorded runs of the actual production implementation in isolated Code OSS on Windows x64, without replay monkeypatching. Synthetic workload: 2,000 edit operations over a 20,000-line, 1.62 MB file.
Measurement Before After (3 runs)
Undo completion 10.90–10.92 s 53.8 / 38.8 / 35.8 ms
Zero-delay renderer timer 10.85–10.89 s 26.6 / 21.0 / 19.3 ms

Verified the restored file SHA-256 matches the baseline exactly, and checked snapshot reads, redo, and subsequent checkpoint restore against the expected file contents.

Replay consecutive text edit batches in one buffer instead of rebuilding the entire file for every operation. Preserve notebook and file lifecycle boundaries, inter-batch EOL/BOM normalization, and cleanup on failure.

Add regression coverage for buffer reuse and replay correctness. Addresses the renderer freeze reported in #296064.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings September 14, 2026 02:20
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues perf chat labels Sep 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The optimized replay path preserves existing semantics, disposes resources reliably, and has comprehensive targeted coverage.

Review tier: Balanced
Findings: None

What changed in this PR

Optimizes checkpoint replay by reusing a text buffer across consecutive text-edit operations while preserving replay semantics and cleanup.

Changes:

  • Batches sequential ordinary-file edits through one disposable buffer.
  • Preserves BOM/EOL normalization and lifecycle boundaries.
  • Adds regression coverage for correctness, concurrency, errors, and disposal.
File Description
chatEditingCheckpointTimelineImpl.ts Implements reusable-buffer checkpoint replay.
chatEditingCheckpointTimeline.test.ts Adds replay and lifecycle regression tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as ready for review September 14, 2026 02:54
@dmitrivMS Dmitriy Vasyura (dmitrivMS) changed the title chat: reuse text buffers for checkpoint replay Reuse text buffers in chat edits for checkpoint replay Sep 14, 2026
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added this to the 1.139.0 milestone Sep 14, 2026
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 903d0d0 into main Sep 15, 2026
34 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the agents/vscode-keep-undo-restore-issue-fix branch September 15, 2026 07:43
Abdullah Atrash (abdullahatrash) added a commit to abdullahatrash/flowleap-agent-v2 that referenced this pull request Sep 20, 2026
* port(chat-ui): preserve #file reference when editing text before it (#394)

Upstream d750fe2 (microsoft#333965), applied clean with its tests.
Typing before an existing #file attachment silently deleted the attachment.
Adds touchesReference and findReferenceRangeForNonOverlappingEdit.

* port(chat-ui): highlight generic tool output by content type (#394)

Upstream 63acf08 (microsoft#333923). chatInputOutputMarkdownProgressPart.ts
applied clean; the chatToolOutputContentSubPart.ts hunk was hand-applied because the
fork's adjacent-code-part loop predates upstream's refactor. The agentHost
stateToProgressAdapter.ts hunk and its test are dropped (Agent Host only).
Our patent tools return large JSON payloads into exactly this part.

* port(chat-ui): fix IME handling in the chat find widget (#394)

Upstream b9861ad (microsoft#332950), applied clean with its tests.
Composition input (CJK) broke search in the transcript find widget.

* port(chat-ui): fix transcript Find keybindings (#394)

Upstream cefc831 (microsoft#333135). chatFindActions.ts, chatFindWidget.ts,
chatListWidget.ts and the find tests applied clean; the chatListWidget.test.ts hunk was
hand-applied because that test file is diverged. Enter/Escape/F3 inside the transcript
find widget went to the generic tree find instead of chat Find.

* port(chat-ui): configurable paste-to-attachment threshold and Insert in Prompt (#394)

Upstream e1801a0 (microsoft#331978). chatPasteProviders.ts, chatCopyActions.ts,
constants.ts, chatAccessibilityHelp.ts, the chat.shared.contribution.ts configuration
registration and the paste tests all applied clean. The src/vs/sessions hunks are left
out: the fork has no caller of createPastedTextArtifact there, and sessions files belong
to the deferred wave W.

* port(chat-ui): remove the line requirement for paste attachments (#394)

Upstream 36053db (microsoft#335100), hand-applied: the fork's
chatPasteProviders.ts lacks the GitHub-URL pattern that surrounds the hunk, and its
chatAccessibilityHelp.ts and both test files are behind upstream's base. A short paste
now becomes an attachment on character count alone, so pasting a single-line claim
works like pasting a multi-line one.

* port(chat-ui): reuse text buffers for checkpoint replay (#394)

Upstream 903d0d0 (microsoft#336095), applied clean with its tests.
Checkpoint restore rebuilt a text model per replayed edit.

* port(chat-ui): constrain symbol tools to the active workspace (#394)

Upstream d8cfdc7 (microsoft#333144), applied clean with its tests.
renameTool and usagesTool no longer reach outside the active workspace folder.
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

chat freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues perf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants