[PR #3380] [Other] serve: an all-cached image turn never wakes the elastic encoder #4602

Open
opened 2026-11-07 15:37:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3380
Author: @jerry78424
Created: 10/20/2026
Status: 🔄 Open

Base: main ← Head: vision-cache-wake


📝 Commits (4)

  • c09e9f8 serve: an all-cached image turn never wakes the elastic encoder
  • 03ee2e0 serve: the cache lookup refreshes the LRU, and the skip stays elastic
  • 41f8c72 docs: the elastic encoder does not wake for pictures it already encoded
  • 4f19603 serve: the cached() lookup re-creates the vision work dir too

📊 Changes

4 files changed (+207 additions, -12 deletions)

View changed files

📝 docs/DETAILS.md (+1 -1)
📝 docs/VRAM_ELASTIC.md (+4 -0)
📝 serve/server.py (+42 -11)
➕ serve/test_vision_cache_wake.py (+160 -0)

📄 Description

Problem and result

An elastic image encoder is woken (seconds of start, VRAM the expert cache gives up) on every turn that re-sends pictures it has already encoded - which is what most clients do on every turn. A turn whose images are all in the hash cache needs no encoder process at all.

Measured on RTX 5090 32 GB, Windows 11 (26200), engine 0.1.44.1, nvfp4, elastic_idle_s: 10 (table and verbatim log lines in #2454): before - a text-only turn with a re-sent picture cost a 2.3 s start + 2085 MiB taken from the expert cache; after - 722 ms with no start line. A re-sent-picture turn: 1277 ms, no start. New pictures unchanged (3979-4213 ms, still start).

Resolves #2454. Follows #2455 (same branch and author; closed by the 0.2.0-beta tracker reset, and GitHub would not reopen it after the rebase force-push). Independent of the #2641 successor (the tool-picture wake lands in this same method - textual overlap only; the two changes conflict in neither order, verified by cherry-pick).

Approach

  • serve/server.py: Vision.key_of() / Vision.cached() - a hash-cache lookup that answers with the process down (the cache and its .sve files survive an unload, as before), marks a hit most recently used as encode() does on its hit path, and - as encode() now does per #3370 - calls _ensure_dir() under the same lock first: a temp cleaner can remove the empty folder while the encoder is unloaded, and the skip must not keep answering with dead .sve paths from a vanished folder (the turn that would re-encode is exactly the one it skips).
  • prepare() maps the turn's images through the cache first, for an elastic encoder only: when every one is a hit the turn skips the encode FIFO, _vision_up() and the encode. A miss - alone or alongside hits - keeps today's path byte-for-byte: FIFO, make-room, start, encode.
  • serve/test_vision_cache_wake.py (new, CPU-only, no engine): a re-sent picture does not wake a stopped encoder; a new picture alongside cached ones still wakes it; the lookup answers with the process down and keeps the re-sent picture from aging out of the 64-entry cache; a non-elastic turn keeps today's path even when every picture is cached; and when the work folder is removed during an unload, the lookup reports a miss and the dict is cleared, so the turn falls through to the encode path that recreates the folder and re-encodes.
  • docs/VRAM_ELASTIC.md, docs/DETAILS.md: both halves of the elastic rule - a picture's turn starts the encoder, a turn of pictures the cache knows takes neither the turn nor a start.

Validation

Passed:

  • Every new behavior fails on a tree without the code that provides it - including the cached() guard: on a tree without it the lookup answers with a dead .sve path after shutil.rmtree(v.dir) (AssertionError) where the guarded tree reports a miss.
  • python -m unittest serve.test_vision_elastic serve.test_vision_busy serve.test_vision_cache_wake serve.test_images serve.test_vision_workdir: the vision five 39 OK - at 2faca6e5 (this branch, rebased onto 011c9e6 2026-10-21), Windows 11 26200, Python 3.12 venv, CPU-only tests.
  • Full serve suite: python -m unittest discover -s serve -t . at the same revision: 936 OK (20 skipped).
  • With [Other] serve: a tool's picture starts the elastic encoder, and its turn counts #2641 cherry-picked on top (auto-merge, no conflict): the vision suites stay 41 OK.

Failed: none observed.

Not run: AMD/HIP and layer-split machines (a layer split refuses elastic anyway; its start failure is #2435). No native files are touched, so no native builds are required.

Limits

  • What it leaves alone: non-elastic vision, the start/stop/idle lifecycle itself, the encode path, and every native file (no CUDA/HIP/SYCL build needed).
  • The measured numbers are one machine (RTX 5090, nvfp4); the mechanism - no process start for an all-cached turn - is hardware-independent, but the saved seconds are not claimed for other machines.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3380 **Author:** [@jerry78424](https://github.com/jerry78424) **Created:** 10/20/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `vision-cache-wake` --- ### 📝 Commits (4) - [`c09e9f8`](https://github.com/Niko1221/Strata/commit/c09e9f8d04a725f4e2718b1d3638b760b1caeedf) serve: an all-cached image turn never wakes the elastic encoder - [`03ee2e0`](https://github.com/Niko1221/Strata/commit/03ee2e01255cc5f516262f516b5e8653594ec35d) serve: the cache lookup refreshes the LRU, and the skip stays elastic - [`41f8c72`](https://github.com/Niko1221/Strata/commit/41f8c725ee717f141d4bcef7b1edf35a4b0d54bd) docs: the elastic encoder does not wake for pictures it already encoded - [`4f19603`](https://github.com/Niko1221/Strata/commit/4f196033c72c4e32c636203d224e4561b30e5a5b) serve: the cached() lookup re-creates the vision work dir too ### 📊 Changes **4 files changed** (+207 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+1 -1) 📝 `docs/VRAM_ELASTIC.md` (+4 -0) 📝 `serve/server.py` (+42 -11) ➕ `serve/test_vision_cache_wake.py` (+160 -0) </details> ### 📄 Description ## Problem and result An elastic image encoder is woken (seconds of start, VRAM the expert cache gives up) on every turn that re-sends pictures it has already encoded - which is what most clients do on every turn. A turn whose images are all in the hash cache needs no encoder process at all. Measured on RTX 5090 32 GB, Windows 11 (26200), engine 0.1.44.1, nvfp4, `elastic_idle_s: 10` (table and verbatim log lines in [#2454](https://github.com/Niko1221/Strata/issues/2454)): before - a text-only turn with a re-sent picture cost a 2.3 s start + 2085 MiB taken from the expert cache; after - 722 ms with no start line. A re-sent-picture turn: 1277 ms, no start. New pictures unchanged (3979-4213 ms, still start). ## Related discussion Resolves [#2454](https://github.com/Niko1221/Strata/issues/2454). Follows [#2455](https://github.com/Niko1221/Strata/pull/2455) (same branch and author; closed by the 0.2.0-beta tracker reset, and GitHub would not reopen it after the rebase force-push). Independent of the [#2641](https://github.com/Niko1221/Strata/pull/2641) successor (the tool-picture wake lands in this same method - textual overlap only; the two changes conflict in neither order, verified by cherry-pick). ## Approach - `serve/server.py`: `Vision.key_of()` / `Vision.cached()` - a hash-cache lookup that answers with the process down (the cache and its .sve files survive an unload, as before), marks a hit most recently used as `encode()` does on its hit path, and - as `encode()` now does per [#3370](https://github.com/Niko1221/Strata/pull/3370) - calls `_ensure_dir()` under the same lock first: a temp cleaner can remove the empty folder while the encoder is unloaded, and the skip must not keep answering with dead .sve paths from a vanished folder (the turn that would re-encode is exactly the one it skips). - `prepare()` maps the turn's images through the cache first, for an elastic encoder only: when every one is a hit the turn skips the encode FIFO, `_vision_up()` and the encode. A miss - alone or alongside hits - keeps today's path byte-for-byte: FIFO, make-room, start, encode. - `serve/test_vision_cache_wake.py` (new, CPU-only, no engine): a re-sent picture does not wake a stopped encoder; a new picture alongside cached ones still wakes it; the lookup answers with the process down and keeps the re-sent picture from aging out of the 64-entry cache; a non-elastic turn keeps today's path even when every picture is cached; and when the work folder is removed during an unload, the lookup reports a miss and the dict is cleared, so the turn falls through to the encode path that recreates the folder and re-encodes. - `docs/VRAM_ELASTIC.md`, `docs/DETAILS.md`: both halves of the elastic rule - a picture's turn starts the encoder, a turn of pictures the cache knows takes neither the turn nor a start. ## Validation **Passed:** - Every new behavior fails on a tree without the code that provides it - including the `cached()` guard: on a tree without it the lookup answers with a dead .sve path after `shutil.rmtree(v.dir)` (AssertionError) where the guarded tree reports a miss. - `python -m unittest serve.test_vision_elastic serve.test_vision_busy serve.test_vision_cache_wake serve.test_images serve.test_vision_workdir`: the vision five 39 OK - at `2faca6e5` (this branch, rebased onto `011c9e6` 2026-10-21), Windows 11 26200, Python 3.12 venv, CPU-only tests. - Full serve suite: `python -m unittest discover -s serve -t .` at the same revision: 936 OK (20 skipped). - With [\[Other\] serve: a tool's picture starts the elastic encoder, and its turn counts #2641](https://github.com/Niko1221/Strata/pull/2641) cherry-picked on top (auto-merge, no conflict): the vision suites stay 41 OK. **Failed:** none observed. **Not run:** AMD/HIP and layer-split machines (a layer split refuses elastic anyway; its start failure is [#2435](https://github.com/Niko1221/Strata/pull/2435)). No native files are touched, so no native builds are required. ## Limits - What it leaves alone: non-elastic vision, the start/stop/idle lifecycle itself, the encode path, and every native file (no CUDA/HIP/SYCL build needed). - The measured numbers are one machine (RTX 5090, nvfp4); the mechanism - no process start for an all-cached turn - is hardware-independent, but the saved seconds are not claimed for other machines. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4602
No description provided.