Description
Context
Sub-issue of #355 (Milestone 2, Story 3.2e). Builds on Stories 3.2c (focus gating) and 3.2d (per-task seq + taskId on messageUpdated).
The throttle fix in #629 reduces push frequency but doesn't address payload size. A single focused task with 3,525+ messages still serializes the full clineMessages array (~7MB) on every state push. At 10,000+ messages (long coding sessions), even throttled pushes will OOM the webview.
Developer Notes
Problem
postStateToWebviewWithoutTaskHistory sends the entire clineMessages array on every call. The lightweight { type: "messageUpdated" } path already exists for partial message updates (Task.ts:1048) but new message additions still go through the full-array path (Task.ts:1015).
Proposed Approach
Replace full-array state pushes with append/update messages for the focused task:
- New message type:
{ type: "clineMessageAppended", message: ClineMessage }— sent fromaddToClineMessagesinstead of a full state push - Webview handler:
ExtensionStateContextappends to existingclineMessagesarray instead of replacing it - Full sync retained for: task switch, initial load, checkpoint restore,
overwriteClineMessages - Sequencing: Use existing
clineMessagesSeqto detect missed appends and trigger a full resync
Depends On
- Story 3.2c — focus gating (only send messages for the focused task)
- Story 3.2d — per-task
clineMessagesSeqandtaskIdonmessageUpdated
Without focus gating, appends from background tasks would corrupt the focused task's message list.
Impact
Payload per update drops from O(N) to O(1) — a single message (~2KB) instead of the full array (~7MB at 3,525 messages). Combined with #629's throttle, this eliminates the gray screen OOM for any message count.
Acceptance Criteria
- New messages appear via append, not full-array replacement
- Full sync fires on task switch, initial load, and checkpoint restore
- Missed-append detection triggers automatic full resync
- No regression in message ordering or partial message streaming
- Works correctly with focus gating from 3.2c
Activity
edelauna commentedon Aug 9, 2026
This issue's "Proposed Approach" keeps a full sync on initial load. That still calls
postStateToWebview()with the completeclineMessagesarray fromwebviewDidLaunch(webviewMessageHandler.ts:561-566). The throttle in #629 does not wrap this call, so it stays a single unbounded payload.This path is not rare. VS Code can tear down and recreate the webview process after the panel sits in the background for a while, or after the OS wakes from sleep, even with
retainContextWhenHidden: true. Each teardown fireswebviewDidLaunchagain. So a long task can hit the full unthrottled hydration push every time the user rejoins it, not just on first install.Two open reports match this path:
Recommend widening this issue's scope so initial load also uses paged/incremental delivery, not just append events for new messages. For example, send only the last N messages on
webviewDidLaunch, then load older ones on scroll-up. Without this change, a long task can still run out of memory on first hydration after this issue ships, even though the ongoing-streaming case is fixed.spiel2001 commentedon Aug 21, 2026
Additional data supporting the payload-size argument in this issue, from a multi-day agent session
that repeatedly hit the gray-panel failure described in #629.
Short version: the payload is not large only because there are many messages. A small number of
messages can be enormous on their own, because each
appliedDiffmessage embeds a full copy ofthe edited file. In the session below, 181 diff messages account for 25.7 MB, of which 97.3% is
the
originalContentfield, against 0.34 MB of actual diff text. That is a separate contributor tothe size problem this issue is scoped to, and it is not addressed by the throttle in #1078.
Environment
3.78.0, VS Code1.128.0Note
3.78.0was published one day before #1078 merged, so these measurements are from apre-throttle build. The frequency problem may already be improved for me on upgrade; the size
problem below is independent of that.
Symptom
Developer: Reload Windowrestores a working panel, and task history survives.Where the session state actually goes
One task's
ui_messages.json, 3177 messages, 28.7 MB:toolcommand_outputtextcommandapi_req_started406 tool messages hold 95% of the file. Narrowing to the tool:
appliedDiffupdateTodoListsearchFilesreadFileA file read costs 0.2 KB. A file edit costs 142 KB on average.
The mechanism: whole files, not diffs
Each
appliedDiffpayload carriescontent,diff,diffStats,isProtected,originalContent,path,tool. Summed across all 181 messages:originalContentdiffcontentWhole-file copies are 98.6% of the payload. The actual diff text is 1.4%. The stored snapshots
are roughly 71x the size of the edits they describe.
The consequence is that recording an edit costs in proportion to the size of the file, not the
size of the change. A one-line comment fix in a 3000-line source file costs the same as rewriting
that file. Concretely, in this session:
Two files account for 20.8 MB, from ordinary implement-test-refine iteration.
Growth is monotonic, and condensing does not help
Cumulative
appliedDiffbytes over the session's life, by elapsed hours:Nothing is trimmed or evicted. Two
condense_contextoperations occurred during this session;condensing shrinks the model-facing history but not
ui_messages.json, so it does not relieve thewebview at all. That surprised me as a user, and may be worth documenting either way.
Across 47 task directories on this machine: 366 MB total, six sessions above 18 MB. Not one runaway
session.
Why I think this is display-side rather than model-side
For the same session, the two state files differ by nearly 6x:
api_conversation_history.jsonui_messages.jsonAlso, in three days: zero API errors, zero retries, and normal token accounting right through the
failures (~501k input, ~499.7k cached). Both panel failures on the last day appear in the logs as
Extension host terminating: received terminate message from renderer, 35 minutes apart, withaccumulated snapshot bytes at 25.4 MB and 25.7 MB. The renderer initiated both.
What I ruled out first
In case it saves anyone repeating it:
will wait for reconnection 3hon genuineconnection loss. That marker appears on eight other dates and is absent on the days the panel
failed. The disconnects present were logged as
disconnected gracefully, each followed by a newtoken, which is the signature of a deliberate window reload.
Developer: Reload Window, the recovery, not the failure. This initially misled me.so not discriminating.
0.60 MB, about 2% of the file.
Confidence
What I am confident of: the state file grows without bound, 90% of it is redundant whole-file
snapshots, and the renderer tears down the extension host at a consistent accumulated size.
What is inference: that the renderer fails because of that size. I have correlation plus a
plausible mechanism, not proof. It should be cheap for you to confirm or dismiss by instrumenting
webview load against a large session, or by checking for a message-size or
postMessagelimit onthe extension-to-webview channel.
Suggestions
originalContentper diff message. It is 97.3% of the payload here. Ifpre-edit content is needed for undo or a diff view, hold it in memory for the operation's
lifetime, or persist it once per file per session rather than once per edit. This alone would
have cut the session from 28.7 MB to roughly 4 MB.
changed.
The human-readable transcript is worth keeping; the redundant file bodies are not.
ui_messages.json, or document that it does not.3.78.0declares nobugsURL and registers no issue-reporting command, so there is noin-product path to report this.
On the relationship to this issue: item 1 seems complementary to incremental delivery rather than
superseded by it. Incremental delivery reduces how often the array is pushed, but a single message
here is still up to 312 KB, and the on-disk state stays large regardless of what goes over the wire.
Reproduction
No special setup; it emerges from ordinary iterative development.
Open a workspace with large source files, 1500+ lines.
Run a long agent session that repeatedly edits the same few large files: implement, build, test,
refine. Several dozen
apply_diffoperations across two or three files is enough.Watch the session file grow:
The panel eventually goes gray and needs
Developer: Reload Window, more often as the file grows.Self-check script
Prints sizes and field names only, no file contents or paths, so the output is safe to paste:
Output on the session above:
I work under source-code disclosure restrictions, so file names above are genericized and no session
contents are included; everything here is byte counts, message counts, and field names from the
extension's own schema. Happy to run any additional measurement that would be useful and report the
numbers.
edelauna commentedon Sep 6, 2026
Second data point and heap-level confirmation of the mechanism described by @spiel2001 above.
Session
3.80.1, VS Code remote-SSH, Linux serverField breakdown (spiel2001's script, same session)
97.6% whole-file copies, 2.4% actual diff text. Same ratio as the larger session above, which rules out a session-specific outlier.
Heap timeline (pre-crash, taken while the renderer was still live)
Chrome DevTools heap timeline captured immediately before the crash: 181 MB self-size across 2.78 M nodes.
appliedDiffpayload stringsThe
appliedDiffcontent (~10.6 MB on disk) appears in the 30 MB string pool. The dominant single allocation site (160 MB, 2.5 M objects) traces to(V8 API)— native bindings including the WASM heap — with no JS-level attribution because the webview bundle is minified without source maps.181 MB is below the typical Chromium renderer limit, but the WASM baseline (73 MB fixed) plus JIT (35 MB) leaves less headroom than a raw number suggests. The Chrome breakpoint fires at 90% of the renderer process ceiling, which in VS Code's sandboxed webview may be lower than a normal browser window.
Virtualisation does not help here
react-virtuosois already in the codebase (ChatView.tsx,react-virtuoso@^4.7.13). The DOM is windowed — only visible messages are mounted. But the fullclineMessagesarray lives in React state regardless of what is rendered. Virtuoso has no effect on data-layer memory. The 11.8 MB array is in the heap whether one message or all 945 are visible.Interaction with #1541 (globalState write-through)
On
Developer: Reload Window(the recovery path),scheduleGlobalStateWriteThroughserialises the full task history over the VS Code RPC bridge before the webview reloads. The freeze from #1541 and the OOM described here compound: the renderer fails first, the extension host then freezes during the "recovery" write. Fixing #1541 does not address the webview OOM, but it does make the reload recovery faster.Suggestions that add to those above
originalContentbeforepostMessage.ClineProvider.postStateToWebview(and the lightweight variants) could droporiginalContentfromappliedDiffpayloads before sending. The full field is on disk; the webview only needsdiffanddiffStatsto render a diff view. This would have cut this session from 11.8 MB to ~0.4 MB over the wire.originalContent(e.g. for a side-by-side view), fetch it on demand from the extension host rather than loading it with every state push.edelauna commentedon Sep 7, 2026
Follow-up: webview VM confirmed, 5× string duplication, allocation entry point named
The previous comment used a timeline from an earlier profiling session. A second session taken from the webview renderer process adds two concrete findings.
5× string duplication (heap snapshot, 127 MB file, 337 MB total heap)
Every large message string appears as five separate string nodes in the snapshot. A 197 KB user message costs ~985 KB. A 135 KB tool-call JSON string that appears in both an assistant message and related tool-result messages appears 15×. The 188 MB string pool in this snapshot (vs 30 MB in session 1) reflects a longer conversation; the 5× multiplier is structural, not session-specific.
This is the React state machine retaining the full
clineMessagesarray in multiple simultaneous copies: the active render fiber, the previous fiber, a queued state update, the postMessage buffer, and at least one memo or selector cache.react-virtuosowindows the DOM. It does not reduce the number of string copies held in JS memory.Allocation entry point named (heap timeline, 131 MB file)
The allocation timeline captures
trace_node_idon every live object. The top call chains by self-size:(anon)@index.js:430from(root)G_n@index.js:2790 → dL@index.js:428synthesize/isTarget/n@index.js:2793HostMessaging.channel.port1.onmessage@index.html:299HostMessaging.channel.port1.onmessageis the cut point. It allocates 0.272 MB parsing the incoming payload, then dispatches a React state update. The scheduler fires asynchronously (from the event loop root, no extension host frames in scope), which is why the 5.5 MB React render appears attributed to(root)rather than toonmessage.Each full-array state push from the extension host costs approximately 6 MB in allocation pressure on the renderer. Under a long active session with frequent tool calls, that accumulates faster than GC can reclaim it.
What this changes in the fix
The fix needs to act before
port1.onmessagereceives the payload, or inside it before the state update is dispatched. The two suggestions from the previous comment (striporiginalContentinpostStateToWebview; lazy-fetch on expand) remain the right starting points. StrippingoriginalContentbefore the message is sent would reduce the per-push allocation proportionally and break the 5× duplication of the largest strings.