[GH-ISSUE #1072] Vision: >64 unique images can evict .sve files still referenced by the current request #461

Closed
opened 2026-11-04 01:43:13 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @jinyu0 on GitHub (Oct 6, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1072

Summary

A vision request containing more than 64 unique images can fail with FileNotFoundError.

Vision.encode() evicts and deletes the oldest cached .sve file once the cache exceeds 64 entries, but Service.prepare() may still hold that file path in the current request's encoded list. write_temporary() later tries to read the deleted file.

Reproduction

  1. Start Strata with vision enabled.
  2. Send a request whose conversation history contains more than 64 unique images (for example, a long image-tagging session in an agent that resends conversation history).
  3. Around the 65th+ unique image, the request fails.

Expected

The request should succeed, or return a clear validation error if more than 64 images per request are intentionally unsupported.

Actual

The server raises:

FileNotFoundError: [Errno 2] No such file or directory:
'C:\\Users\\...\\AppData\\Local\\Temp\\strata-vision-...\\....sve'

  File "serve/server.py", line 954, in prepare
    f.write(path.read_bytes())

The prompt was still below the configured context limit when this occurred.

Environment

  • Windows 11
  • Python 3.14
  • Vision enabled
  • Qwen3.8-Flash-Next
  • Context: 131072

Likely cause

The current cache eviction logic removes the oldest file immediately:

self.cache[key] = (out, int(line.split()[1]))
if len(self.cache) > 64:
    old = next(iter(self.cache))
    self.cache.pop(old)[0].unlink(missing_ok=True)

while the current request later combines all paths returned by Vision.encode().

It looks like active-request embeddings need to remain alive until the combined request embedding has been written, with cache eviction happening afterwards (or active entries being pinned).

Originally created by @jinyu0 on GitHub (Oct 6, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1072 ### Summary A vision request containing more than 64 unique images can fail with `FileNotFoundError`. `Vision.encode()` evicts and deletes the oldest cached `.sve` file once the cache exceeds 64 entries, but `Service.prepare()` may still hold that file path in the current request's `encoded` list. `write_temporary()` later tries to read the deleted file. ### Reproduction 1. Start Strata with vision enabled. 2. Send a request whose conversation history contains more than 64 unique images (for example, a long image-tagging session in an agent that resends conversation history). 3. Around the 65th+ unique image, the request fails. ### Expected The request should succeed, or return a clear validation error if more than 64 images per request are intentionally unsupported. ### Actual The server raises: ```text FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\...\\AppData\\Local\\Temp\\strata-vision-...\\....sve' File "serve/server.py", line 954, in prepare f.write(path.read_bytes()) ``` The prompt was still below the configured context limit when this occurred. ### Environment - Windows 11 - Python 3.14 - Vision enabled - Qwen3.8-Flash-Next - Context: 131072 ### Likely cause The current cache eviction logic removes the oldest file immediately: ```python self.cache[key] = (out, int(line.split()[1])) if len(self.cache) > 64: old = next(iter(self.cache)) self.cache.pop(old)[0].unlink(missing_ok=True) ``` while the current request later combines all paths returned by `Vision.encode()`. It looks like active-request embeddings need to remain alive until the combined request embedding has been written, with cache eviction happening afterwards (or active entries being pinned).
Author
Owner

@yeungyim commented on GitHub (Oct 6, 2026):

Confirmed on a different environment, with a smaller and fully deterministic reproduction, and a one-line fix that holds up in testing.

Environment: Linux (Ubuntu), 2x RTX 3090 layer split, Qwen3.8-Flash-Next IQ3_S, --resident-experts --vision, context 262144, Python 3.14.

Reproduction: no long history needed

The trigger is the image count of one request, not of the session, so a single call reproduces it. Sent 70 distinct 64x64 PNGs as image_url parts in one message:

FileNotFoundError: [Errno 2] No such file or directory:
'/tmp/strata-vision-kqt2ps8n/9c3fa26ef2eec6bae60e386221fd6121.sve'

  File "serve/server.py", line 2808, in prepare
    combined = combined_embeddings_path(self.vision.dir, sum(Path(p).stat().st_size for p, _ in encoded))

ls /tmp/strata-vision-*/ *.sve | wc -l sat at exactly 64 afterwards — the cache limit, not the image count. The same request succeeds unchanged after the fix below.

The client does not see the traceback. It sees the connection dropped:

RemoteDisconnected: Remote end closed connection without response

That is worth knowing for triage: from an agent or a GUI the symptom looks like "the server died", not like a vision error.

Why it is deterministic rather than a race

prepare() builds the whole list before it touches any of them:

encoded = [self.vision.encode(src) for src in images]   # every image, in order
...
combined = combined_embeddings_path(self.vision.dir, sum(Path(p).stat().st_size for p, _ in encoded))

Each encode() call returns a path and may evict an earlier entry of that same list once the cache passes 64, so with more than 64 images in one request the loss needs no concurrency at all. (Concurrency widens it, it does not cause it.)

A second, independent way in, for requests under the limit: images is not "the new pictures", it is every image the template writes a pad for, so a conversation that resends its history reaches the same state with one new image per turn — which is how the reporter's agent hits it.

Fix tested here

Dropping the entry must not unlink its file while a request can still hold the path. Removing just the unlink fixes it:

self.cache[key] = (out, int(line.split()[1]))
if len(self.cache) > 64:                                   # oldest first
    old = next(iter(self.cache))
    self.cache.pop(old)                                    # keep the file: a request may hold this path
return self.cache[key]
before after
70 images, one request RemoteDisconnected + FileNotFoundError OK, 14 s
.sve files after 64 (stuck at the cap) 70

The cost is that evicted files now live until the encoder exits (shutdown() rmtree's the directory), so tmpfs /tmp grows by roughly 1.8 MB per distinct image for the life of the server. A bounded version would reap files that are out of the cache and older than any in-flight request; pinning the entries a request is using, as the report suggests, is cleaner still if prepare() can pass them down.

Happy to test a proposed patch here on the 70-image case, and on a longer mixed run, if that helps.

<!-- gh-comment-id:6019327384 --> @yeungyim commented on GitHub (Oct 6, 2026): Confirmed on a different environment, with a smaller and fully deterministic reproduction, and a one-line fix that holds up in testing. **Environment:** Linux (Ubuntu), 2x RTX 3090 layer split, Qwen3.8-Flash-Next IQ3_S, `--resident-experts --vision`, context 262144, Python 3.14. ## Reproduction: no long history needed The trigger is the image count of **one request**, not of the session, so a single call reproduces it. Sent 70 distinct 64x64 PNGs as `image_url` parts in one message: ``` FileNotFoundError: [Errno 2] No such file or directory: '/tmp/strata-vision-kqt2ps8n/9c3fa26ef2eec6bae60e386221fd6121.sve' File "serve/server.py", line 2808, in prepare combined = combined_embeddings_path(self.vision.dir, sum(Path(p).stat().st_size for p, _ in encoded)) ``` `ls /tmp/strata-vision-*/ *.sve | wc -l` sat at exactly **64** afterwards — the cache limit, not the image count. The same request succeeds unchanged after the fix below. **The client does not see the traceback.** It sees the connection dropped: ``` RemoteDisconnected: Remote end closed connection without response ``` That is worth knowing for triage: from an agent or a GUI the symptom looks like "the server died", not like a vision error. ## Why it is deterministic rather than a race `prepare()` builds the whole list before it touches any of them: ```python encoded = [self.vision.encode(src) for src in images] # every image, in order ... combined = combined_embeddings_path(self.vision.dir, sum(Path(p).stat().st_size for p, _ in encoded)) ``` Each `encode()` call returns a path and may evict an *earlier* entry of that same list once the cache passes 64, so with more than 64 images in one request the loss needs no concurrency at all. (Concurrency widens it, it does not cause it.) A second, independent way in, for requests under the limit: `images` is not "the new pictures", it is every image the template writes a pad for, so a conversation that resends its history reaches the same state with one new image per turn — which is how the reporter's agent hits it. ## Fix tested here Dropping the entry must not unlink its file while a request can still hold the path. Removing just the `unlink` fixes it: ```python self.cache[key] = (out, int(line.split()[1])) if len(self.cache) > 64: # oldest first old = next(iter(self.cache)) self.cache.pop(old) # keep the file: a request may hold this path return self.cache[key] ``` | | before | after | | --- | --- | --- | | 70 images, one request | `RemoteDisconnected` + `FileNotFoundError` | **OK, 14 s** | | `.sve` files after | 64 (stuck at the cap) | 70 | The cost is that evicted files now live until the encoder exits (`shutdown()` rmtree's the directory), so `tmpfs` `/tmp` grows by roughly 1.8 MB per distinct image for the life of the server. A bounded version would reap files that are out of the cache *and* older than any in-flight request; pinning the entries a request is using, as the report suggests, is cleaner still if `prepare()` can pass them down. Happy to test a proposed patch here on the 70-image case, and on a longer mixed run, if that helps.
Author
Owner

@Niko1221 commented on GitHub (Oct 7, 2026):

Fixed in 0.1.40.2: a request keeps the encoded files of its own images, so more than 64 unique images in one request no longer deletes a file the request still reads (the cache shrinks back on the next insert). The large-image downscale from #1014 is not part of this fix.

<!-- gh-comment-id:6037979394 --> @Niko1221 commented on GitHub (Oct 7, 2026): Fixed in 0.1.40.2: a request keeps the encoded files of its own images, so more than 64 unique images in one request no longer deletes a file the request still reads (the cache shrinks back on the next insert). The large-image downscale from #1014 is not part of this fix.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#461
No description provided.