Skip to content

Invalidate cached local-file images in AI blocks when the file changes - #12840

Merged
zachlloyd merged 4 commits into
masterfrom
oz-agent/blocklist-image-cache-invalidation
Jun 22, 2026
Merged

zachlloyd merged 4 commits into
masterfrom
oz-agent/blocklist-image-cache-invalidation

Conversation

@zachlloyd

@zachlloyd zachlloyd commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

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.

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

Agent Mode

  • 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.

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]>
@cla-bot cla-bot Bot added the cla-signed label Jun 19, 2026
@zachlloyd
zachlloyd requested a review from kevinyang372 June 19, 2026 21:25
@zachlloyd
zachlloyd marked this pull request as ready for review June 19, 2026 21:26
@warp-for-oss

warp-for-oss Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

@zachlloyd

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 /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot 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.

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/ImageCache key for each detected file rewrite, but the existing eviction logic only bounds AssetSource::Raw entries. 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

@zachlloyd
zachlloyd enabled auto-merge (squash) June 22, 2026 19:55
@zachlloyd
zachlloyd merged commit da6066b into master Jun 22, 2026
24 checks passed
@zachlloyd
zachlloyd deleted the oz-agent/blocklist-image-cache-invalidation branch June 22, 2026 19:57
dagmfactory pushed a commit that referenced this pull request Jun 30, 2026
#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]>
jwp2987 pushed a commit to jwp2987/phosphor that referenced this pull request Aug 15, 2026
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)
TranscriptionFactory pushed a commit to TranscriptionFactory/warp that referenced this pull request Aug 30, 2026
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)
NourEldinShobier pushed a commit to NourEldinShobier/MyWarp that referenced this pull request Nov 16, 2026
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)
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.

2 participants