Skip to content

fix: lazy-init code diff views for restored AI conversations (APP-4200)#10034

Draft
kevinchevalier wants to merge 1 commit intomasterfrom
fix/memory-ai-conversation-restore-APP-4200
Draft

fix: lazy-init code diff views for restored AI conversations (APP-4200)#10034
kevinchevalier wants to merge 1 commit intomasterfrom
fix/memory-ai-conversation-restore-APP-4200

Conversation

@kevinchevalier
Copy link
Copy Markdown
Contributor

@kevinchevalier kevinchevalier commented May 4, 2026

Closes #10072

Description

Fixes excessive memory usage during AI conversation restoration (APP-4200 / Sentry 7366781652).

Root cause: When restoring AI conversations on app startup, every RequestFileEdits action eagerly created full CodeEditorView + InlineDiffView instances for each file diff. These include editor buffers, syntax models, diff computation, and file registrations — all heavy allocations that are never used because restored diffs are always in a terminal state (Accepted/Rejected/Reverted) and rendered collapsed (header-only).

Fix: Introduces lazy initialization via DeferredDiffState:

  • set_deferred_candidate_diffs() stores lightweight metadata (file paths, pre-computed line counts from DiffType) alongside raw FileDiff data, without creating any editor views
  • The collapsed header renders using deferred metadata for the +/- line stats, file path buttons, and primary file path
  • When the user clicks to expand a diff, materialize_deferred_diffs() calls the existing set_candidate_diffs() to create the full editor views on demand
  • No visual or behavioral change — the header looks identical, and expansion works exactly as before

Impact: For a session with N restored conversations × M file edits each, this avoids creating N×M CodeEditorView + InlineDiffView instances at startup, saving significant memory from editor buffers, diff models, syntax highlighting infrastructure, and file model registrations.

Linked Issue

Testing

  • Verified compilation with cargo check -p warp (no errors, no new warnings)
  • Ran cargo fmt to ensure formatting compliance
  • Deferred → materialized path reuses the existing set_candidate_diffs code, so existing editor/diff behavior is preserved

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

CHANGELOG-BUG-FIX: Fixed excessive memory usage when restoring AI conversations with file edits

Conversation: https://staging.warp.dev/conversation/ae68e989-1130-4586-99ef-f70978a8b94a
Run: https://oz.staging.warp.dev/runs/019df333-b449-7169-9513-b7fb6fd84c9c

This PR was generated with Oz.

Defers creation of CodeEditorView/InlineDiffView instances for restored
AI conversation diffs until the user explicitly expands them. Previously,
every restored conversation eagerly materialized full editor views, diff
models, syntax models, and file registrations for each file diff, even
though restored diffs are always in a terminal state (Accepted/Rejected/
Reverted) and displayed collapsed (header-only).

The fix introduces a DeferredDiffState that stores lightweight metadata
(file paths, pre-computed line counts) alongside the raw FileDiff data.
The collapsed header renders using this metadata instead of querying
editor views. When the user clicks to expand, views are materialized
on-demand via the existing set_candidate_diffs path.

This significantly reduces memory usage during AI conversation
restoration, particularly for sessions with many conversations and file
edits (the dominant allocation path identified in Sentry heap profiles).

Fixes APP-4200
Sentry: https://sentry.io/organizations/warpdotdev/issues/7366781652/

Co-Authored-By: Oz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lazy-init code diff views for restored AI conversations

2 participants