fix(core): shrink file diff session records - #3872
Merged
Merged
Conversation
Trim oversized file edit result displays before writing them to session JSONL while preserving live tool results and diff stats. Also make resume, ACP replay, and export paths treat saved previews as incomplete so they do not reconstruct fake full diffs. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces on-disk session JSONL bloat by trimming oversized FileDiff tool result displays at record-write time (core), while ensuring downstream replay/export/UI paths treat the stored data as an explicit preview rather than a complete diff.
Changes:
- Add optional “saved-session preview” metadata fields to the core
FileDiffresult display shape. - Sanitize large
FileDiffpayloads inChatRecordingService.recordToolResult()so JSONL history stores bounded previews instead of full contents/diffs. - Update CLI replay/export/UI rendering and stats collection to detect
truncatedForSessionand avoid reconstructing/exporting fake “full diffs”, with new tests covering the behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/tools/tools.ts | Extends FileDiff with optional truncation metadata fields. |
| packages/core/src/services/chatRecordingService.ts | Adds FileDiff detection + size-bounded sanitization for session recording only. |
| packages/core/src/services/chatRecordingService.test.ts | Adds unit tests for “unchanged small diffs” and “shrunk large diffs without mutation”. |
| packages/cli/src/ui/utils/export/normalize.ts | Exports truncated diff previews as explanatory text instead of a diff payload. |
| packages/cli/src/ui/utils/export/normalize.test.ts | Tests that truncated previews are not exported as full diffs. |
| packages/cli/src/ui/utils/export/collect.ts | Skips line-count fallback when a diff is marked truncatedForSession. |
| packages/cli/src/ui/utils/export/collect.test.ts | Tests stats behavior for truncated saved-session previews. |
| packages/cli/src/ui/components/messages/ToolMessage.tsx | Shows a warning notice for truncated diff previews in the UI. |
| packages/cli/src/ui/components/messages/ToolMessage.test.tsx | Tests the truncated-preview notice rendering. |
| packages/cli/src/acp-integration/session/emitters/ToolCallEmitter.ts | Replays truncated previews as explanatory text content, not diffs. |
| packages/cli/src/acp-integration/session/emitters/ToolCallEmitter.test.ts | Tests replay behavior for truncated previews. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
Use one helper for ACP replay and export fallback messages so truncated session preview wording cannot drift. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
wenshao
approved these changes
May 6, 2026
wenshao
left a comment
Collaborator
There was a problem hiding this comment.
No issues found. LGTM! ✅ — gpt-5.5 via Qwen Code /review
DragonnZhang
pushed a commit
that referenced
this pull request
May 8, 2026
* fix(core): shrink file diff session records Trim oversized file edit result displays before writing them to session JSONL while preserving live tool results and diff stats. Also make resume, ACP replay, and export paths treat saved previews as incomplete so they do not reconstruct fake full diffs. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> * refactor(cli): share truncated diff preview text Use one helper for ACP replay and export fallback messages so truncated session preview wording cannot drift. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> --------- Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
xaelistic
pushed a commit
to xaelistic/qwen-code
that referenced
this pull request
Jun 7, 2026
* fix(core): shrink file diff session records Trim oversized file edit result displays before writing them to session JSONL while preserving live tool results and diff stats. Also make resume, ACP replay, and export paths treat saved previews as incomplete so they do not reconstruct fake full diffs. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> * refactor(cli): share truncated diff preview text Use one helper for ACP replay and export fallback messages so truncated session preview wording cannot drift. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> --------- Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
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
Validation
write_file-shaped result with a 5 MiB single-line original content, 5 MiB single-line new content, and a 10,485,805-character unified diff.diffStat.originalContent/newContent.npm run build && npm run typecheckcompleted successfully.ASSERTIONS: PASSandEXIT_CODE=0..qwen/e2e-tests/session-jsonl-tmux/verify-session-jsonl.mjs.qwen/e2e-tests/session-jsonl-tmux/tmux-transcript-20260506-202706.log.qwen/e2e-tests/session-jsonl-tmux/tmux-transcript-20260506-202706.clean.log{ "tool": "write_file", "syntheticOriginalContentChars": 5242880, "syntheticNewContentChars": 5242880, "syntheticFileDiffChars": 10485805, "syntheticUnsanitizedDisplayChars": 20971565 }{ "jsonlBytes": 33704, "records": 2, "listSessionsItems": 1, "listSessionsMessageCount": 1, "listSessionsMs": 2.33, "savedDisplay": { "truncatedForSession": true, "fileDiffTruncated": true, "originalContentTruncated": true, "newContentTruncated": true, "fileDiffLength": 10485805, "originalContentLength": 5242880, "newContentLength": 5242880, "savedFileDiffChars": 247, "savedOriginalContentChars": 16000, "savedNewContentChars": 16000, "syntheticDiffPreviewNotice": true } }Scope / Risk
Testing Matrix
Testing matrix notes:
Linked Issues / Bugs
Fixes #3822