Repository navigation
Invalidate cached local-file images in AI blocks when the file changes - #12840
Conversation
Local image files were cached by path only, with no modification-time or content check and no invalidation path, so re-displaying the same path in an AI response always returned the first-loaded image even after the file changed on disk. Add a LocalFileContentVersion (a NonZeroU64 hash of mtime + size) to AssetSource::LocalFile so the content version is part of both the decoded-bytes (AssetCache) and rendered (ImageCache) cache keys. The blocklist resolves it via AssetSource::with_local_file_content_version() inside the existing background link-detection task, so file metadata is read when the block resolves its image sources (creation/output completion), not on every render. Storing it as a NonZeroU64 keeps Option<LocalFileContentVersion> pointer-width so AssetSource does not grow. Co-Authored-By: Oz <[email protected]>
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I completed the review and no human review was requested for this pull request. Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR adds an optional local-file content version to AssetSource::LocalFile and uses it for AI block image resolution so edited local images miss the existing path-only cache. The approach is wired through the blocklist image resolution path and leaves other callers on path-only caching.
Concerns
- Versioned local-file sources create a new
AssetCache/ImageCachekey for each detected file rewrite, but the existing eviction logic only boundsAssetSource::Rawentries. Repeatedly iterating on a large image can retain every previous decoded/rendered version until the cache is torn down.
Verdict
Found: 0 critical, 1 important, 0 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
Co-Authored-By: Oz <[email protected]>
Co-Authored-By: Oz <[email protected]>
#12840) ## Description Fixes a caching bug in inline image display in AI blocks (the PR #9993 feature): if an agent displays a local image, the file is then changed on disk, and the agent is asked to display the same path again, the second display showed the **stale, first-loaded image** instead of the updated file. This made it impossible to iterate on an image with the agent. **Root cause:** `AssetSource::LocalFile` was keyed by path only. `AssetCache::load_asset()` reads a path once and never re-reads it, and the rendered-size `ImageCache` is keyed on the same source. There was no mtime/content check and no invalidation path for `LocalFile` (eviction only covered `AssetSource::Raw`), so a changed file at the same path kept hitting the cached decode. **Fix:** include an optional content version in the local-file cache key. - New `LocalFileContentVersion` (a `NonZeroU64` hash of last-modified time + file size) and a `content_version: Option<LocalFileContentVersion>` field on `AssetSource::LocalFile` (`crates/warpui_core/src/assets/asset_cache.rs`). Because it is part of the source, it flows into both the `AssetCache` (decoded bytes) and `ImageCache` (rendered) keys, so an edited file misses the cache and is re-read. - `AssetSource::with_local_file_content_version()` reads the metadata; the AI block calls it inside the existing background link-detection task (`app/src/ai/blocklist/block.rs`), which populates the per-block `resolved_blocklist_image_sources` map. - Stored as `NonZeroU64` so `Option<LocalFileContentVersion>` stays pointer-width (niche) and `AssetSource` does not grow (a `{u128,u64}` version tripped `clippy::large_enum_variant` on an unrelated enum via `WarpTheme`). **Metadata is read only when the block resolves its image sources** (block creation / output completion / restore / shell-change) — never on the per-streaming-token path and never on render. Renders reuse the cached resolved source, and the render-time fallback stays stat-free (`content_version: None`). The stat also runs in the existing background `spawn_blocking` task, off the UI thread. This is a general `AssetCache`/`ImageCache` improvement; non-blocklist callers (themes, notebooks) keep path-only caching (`content_version: None`), so their behavior is unchanged. https://www.loom.com/share/c0eab28c73f146bb9ba531d3ba5b8081 ## Linked Issue #12802 - [ ] The linked issue is labeled `ready-to-spec` or `ready-to-implement`. <!-- issue was just auto-filed by triage; not yet labeled --> ## Testing - Added 3 focused unit tests in `crates/warpui_core/src/assets/asset_cache_tests.rs`: - a changed file (different size) produces a different cache key, while an unchanged file produces the same key - `for_path` returns `None` for a missing file - `with_local_file_content_version()` leaves non-local sources unchanged - `cargo fmt -- --check`, `cargo check`, and `cargo clippy --tests -- -D warnings` are clean for the changed crates and the app (`warp` with `local_fs`); the new unit tests and the existing tests I touched pass. - Could not run in this cloud sandbox: the full app test binary OOMs while **linking** (memory limit — it compiles fine), and the full wasm bundle build needs `clang` plus app-level feature wiring unavailable here. The wasm changes are cfg-gated stubs (`for_path` returns `None` on wasm). CI will run the full presubmit. - [ ] I have manually tested my changes locally with `./script/run` <!-- not runnable in the cloud sandbox --> ## Agent Mode - [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode CHANGELOG-BUG-FIX: Re-displaying a local image in an AI response now reflects edits made to the file on disk instead of showing a stale cached copy. --- _Conversation: https://staging.warp.dev/conversation/970500d6-1824-42c3-85a4-620b31258e19_ _Run: https://oz.staging.warp.dev/runs/019ed6bb-b701-78a8-8fa2-844979f25593_ _This PR was generated with [Oz](https://warp.dev/oz)._ --------- Co-authored-by: Oz <[email protected]>
NOT COMPILED -- builds are suspended. Unverified: only read, not built.
Ports upstream `da6066b759` ("Invalidate cached local-file images in AI
blocks when the file changes", warpdotdev#12840). This was a partial port in the
"01778efe shape" flagged in tonight's task brief: the underlying
mechanism (`LocalFileContentVersion`, `AssetSource::LocalFile`'s
`content_version` field, `with_local_file_content_version()`,
`crates/warpui_core/src/assets/asset_cache.rs`) was already ported,
outside this agent's paths -- but the one call site that actually wires
it up, in this agent's area, was never updated to call it. So the whole
mechanism was dead for this consumer: an agent displaying a local image,
then the file changing on disk, then the agent displaying the same path
again, still showed the stale first-loaded image, because
`resolve_asset_source_relative_to_directory(...)`'s result was inserted
into `resolved_blocklist_image_sources` with `content_version` always
absent. Added the missing `.with_local_file_content_version()` call in
the existing background link-detection task in
`app/src/ai/blocklist/block.rs`, matching upstream's placement exactly
(off the UI thread, only when the block resolves its image sources, never
per-streaming-token or on render).
`app/src/ai/blocklist/block/view_impl/common_tests.rs`'s adjustment for
the new `content_version` struct field was already present -- it must
have been carried along when the mechanism itself was ported -- so no
test changes were needed here.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VNUMjBVuwvEnRSgaawUCR3
(cherry picked from commit a22ba4d)
warpdotdev#12840) Fixes a caching bug in inline image display in AI blocks (the PR warpdotdev#9993 feature): if an agent displays a local image, the file is then changed on disk, and the agent is asked to display the same path again, the second display showed the **stale, first-loaded image** instead of the updated file. This made it impossible to iterate on an image with the agent. **Root cause:** `AssetSource::LocalFile` was keyed by path only. `AssetCache::load_asset()` reads a path once and never re-reads it, and the rendered-size `ImageCache` is keyed on the same source. There was no mtime/content check and no invalidation path for `LocalFile` (eviction only covered `AssetSource::Raw`), so a changed file at the same path kept hitting the cached decode. **Fix:** include an optional content version in the local-file cache key. - New `LocalFileContentVersion` (a `NonZeroU64` hash of last-modified time + file size) and a `content_version: Option<LocalFileContentVersion>` field on `AssetSource::LocalFile` (`crates/warpui_core/src/assets/asset_cache.rs`). Because it is part of the source, it flows into both the `AssetCache` (decoded bytes) and `ImageCache` (rendered) keys, so an edited file misses the cache and is re-read. - `AssetSource::with_local_file_content_version()` reads the metadata; the AI block calls it inside the existing background link-detection task (`app/src/ai/blocklist/block.rs`), which populates the per-block `resolved_blocklist_image_sources` map. - Stored as `NonZeroU64` so `Option<LocalFileContentVersion>` stays pointer-width (niche) and `AssetSource` does not grow (a `{u128,u64}` version tripped `clippy::large_enum_variant` on an unrelated enum via `WarpTheme`). **Metadata is read only when the block resolves its image sources** (block creation / output completion / restore / shell-change) — never on the per-streaming-token path and never on render. Renders reuse the cached resolved source, and the render-time fallback stays stat-free (`content_version: None`). The stat also runs in the existing background `spawn_blocking` task, off the UI thread. This is a general `AssetCache`/`ImageCache` improvement; non-blocklist callers (themes, notebooks) keep path-only caching (`content_version: None`), so their behavior is unchanged. https://www.loom.com/share/c0eab28c73f146bb9ba531d3ba5b8081 warpdotdev#12802 - [ ] The linked issue is labeled `ready-to-spec` or `ready-to-implement`. <!-- issue was just auto-filed by triage; not yet labeled --> - Added 3 focused unit tests in `crates/warpui_core/src/assets/asset_cache_tests.rs`: - a changed file (different size) produces a different cache key, while an unchanged file produces the same key - `for_path` returns `None` for a missing file - `with_local_file_content_version()` leaves non-local sources unchanged - `cargo fmt -- --check`, `cargo check`, and `cargo clippy --tests -- -D warnings` are clean for the changed crates and the app (`warp` with `local_fs`); the new unit tests and the existing tests I touched pass. - Could not run in this cloud sandbox: the full app test binary OOMs while **linking** (memory limit — it compiles fine), and the full wasm bundle build needs `clang` plus app-level feature wiring unavailable here. The wasm changes are cfg-gated stubs (`for_path` returns `None` on wasm). CI will run the full presubmit. - [ ] I have manually tested my changes locally with `./script/run` <!-- not runnable in the cloud sandbox --> - [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode CHANGELOG-BUG-FIX: Re-displaying a local image in an AI response now reflects edits made to the file on disk instead of showing a stale cached copy. --- _Conversation: https://staging.warp.dev/conversation/970500d6-1824-42c3-85a4-620b31258e19_ _Run: https://oz.staging.warp.dev/runs/019ed6bb-b701-78a8-8fa2-844979f25593_ _This PR was generated with [Oz](https://warp.dev/oz)._ --------- Co-authored-by: Oz <[email protected]> (cherry picked from commit da6066b)
Local images embedded in Markdown stayed stale after their files changed on disk, because AssetSource::LocalFile was keyed by path only. Attach the file's metadata-derived content version to the asset source when the Markdown block is laid out, so an edited file gets a new image-cache key while ordinary frame rendering stays I/O-free. Remote URLs keep their existing cache identities. Requires the framework surface from warpdotdev#12840 (LocalFileContentVersion, AssetSource::with_local_file_content_version, and the versioned-local-file eviction in AssetCache), ported here since Zap does not have that commit yet. The AI-blocklist caller change of warpdotdev#12840 is not included; it belongs to that upstream task. (cherry picked from commit be54767) (cherry picked from commit c85882d)
Description
Fixes a caching bug in inline image display in AI blocks (the PR #9993 feature): if an agent displays a local image, the file is then changed on disk, and the agent is asked to display the same path again, the second display showed the stale, first-loaded image instead of the updated file. This made it impossible to iterate on an image with the agent.
Root cause:
AssetSource::LocalFilewas keyed by path only.AssetCache::load_asset()reads a path once and never re-reads it, and the rendered-sizeImageCacheis keyed on the same source. There was no mtime/content check and no invalidation path forLocalFile(eviction only coveredAssetSource::Raw), so a changed file at the same path kept hitting the cached decode.Fix: include an optional content version in the local-file cache key.
LocalFileContentVersion(aNonZeroU64hash of last-modified time + file size) and acontent_version: Option<LocalFileContentVersion>field onAssetSource::LocalFile(crates/warpui_core/src/assets/asset_cache.rs). Because it is part of the source, it flows into both theAssetCache(decoded bytes) andImageCache(rendered) keys, so an edited file misses the cache and is re-read.AssetSource::with_local_file_content_version()reads the metadata; the AI block calls it inside the existing background link-detection task (app/src/ai/blocklist/block.rs), which populates the per-blockresolved_blocklist_image_sourcesmap.NonZeroU64soOption<LocalFileContentVersion>stays pointer-width (niche) andAssetSourcedoes not grow (a{u128,u64}version trippedclippy::large_enum_varianton an unrelated enum viaWarpTheme).Metadata is read only when the block resolves its image sources (block creation / output completion / restore / shell-change) — never on the per-streaming-token path and never on render. Renders reuse the cached resolved source, and the render-time fallback stays stat-free (
content_version: None). The stat also runs in the existing backgroundspawn_blockingtask, off the UI thread.This is a general
AssetCache/ImageCacheimprovement; non-blocklist callers (themes, notebooks) keep path-only caching (content_version: None), so their behavior is unchanged.https://www.loom.com/share/c0eab28c73f146bb9ba531d3ba5b8081
Linked Issue
#12802
ready-to-specorready-to-implement.Testing
Added 3 focused unit tests in
crates/warpui_core/src/assets/asset_cache_tests.rs:for_pathreturnsNonefor a missing filewith_local_file_content_version()leaves non-local sources unchangedcargo fmt -- --check,cargo check, andcargo clippy --tests -- -D warningsare clean for the changed crates and the app (warpwithlocal_fs); the new unit tests and the existing tests I touched pass.Could not run in this cloud sandbox: the full app test binary OOMs while linking (memory limit — it compiles fine), and the full wasm bundle build needs
clangplus app-level feature wiring unavailable here. The wasm changes are cfg-gated stubs (for_pathreturnsNoneon wasm). CI will run the full presubmit.I have manually tested my changes locally with
./script/runAgent Mode
CHANGELOG-BUG-FIX: Re-displaying a local image in an AI response now reflects edits made to the file on disk instead of showing a stale cached copy.
Conversation: https://staging.warp.dev/conversation/970500d6-1824-42c3-85a4-620b31258e19
Run: https://oz.staging.warp.dev/runs/019ed6bb-b701-78a8-8fa2-844979f25593
This PR was generated with Oz.