server: reuse KV when tools append images - #927
Open
JordiPosthumus wants to merge 1 commit into
Open
Conversation
JordiPosthumus
force-pushed
the
codex/fix-appended-image-kv-reuse
branch
2 times, most recently
from
September 1, 2026 16:22
50100f5 to
4a71f01
Compare
This was referenced Sep 3, 2026
JordiPosthumus
force-pushed
the
codex/fix-appended-image-kv-reuse
branch
from
September 4, 2026 18:06
4a71f01 to
1827404
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reuse an exact image-conditioned live KV prefix when a tool appends a new image
strictly after that prefix.
Why
DS4 records the image spans and embedding fingerprints that conditioned a live
checkpoint. Reuse previously required the next request to contain exactly the
same number of images. A vision tool appending a new image therefore discarded
the whole live prefix even when every old token and image was unchanged and the
new image began after the checkpoint frontier.
The prefix is reusable only when:
after the live frontier.
Changed, removed, moved or replaced images remain cold, as do images inserted
inside already-computed tokens. Protocol reconstruction, text-prefix reuse and
rewinds still require an exact image-state match. Resident-slot routing uses the
same eligibility rule.
Compatibility
Image-conditioned KV remains excluded from the text-keyed disk cache. The
multimodal protections from #916 are unchanged. There is no cache-format,
sampling, model-math, launcher or default change.
Validation
Rebuilt as one commit directly on main
b0a147a7fba6d1a104d047d5a140e9bb4bfc13cd. Unit coverage accepts one andmultiple appended images and rejects edited prefix tokens, changed
fingerprints, removed/moved images, early insertion, zero-length spans,
overlapping spans and incompatible resident slots.
Apple M3 Ultra, Metal default build; CPU is compile/link portability only:
All commands passed on 2026-09-04. Earlier C ASan+UBSan server checks and the
DeepSeek vision image test passed. A real M3 Ultra test used
DeepSeek-V4-Flash-Vision-Exp
MXFP4Experts/F16HC/F16Compressor/F16Indexer/Q8Attn/Q8Shared/Q8Out with its
matching encoder: appending images reused 10,884 and 11,288 live tokens and
evaluated only 231 and 387 new tokens; changing an existing image rebuilt cold.
The original trace had discarded 63,036 valid tokens and spent 142.6 seconds
refilling them.
Matched speed/correctness check
Two mirrored runs per build, M3 Ultra/Metal, 2,048 and 16,384-token text
frontiers, 262,144 allocated context, 4,096 prefill chunk, 64 greedy output
tokens, warmed weights and no MTP:
All frontier-logit dumps were byte-identical. Every speed difference was below
0.5%; this short engine test is not a server-scheduling, image-throughput or
long-context production guarantee.
Merge coordination: #960 touches the same reuse dispatch. If either lands
first, preserve exact cancelled-retry priority; appended-image eligibility must
not widen protocol-reconstruction matching.