Skip to content

server: retry disk KV lookup with token text - #943

Open
JordiPosthumus wants to merge 1 commit into
antirez:mainfrom
JordiPosthumus:codex/pr-token-text-cache-lookup
Open

server: retry disk KV lookup with token text#943
JordiPosthumus wants to merge 1 commit into
antirez:mainfrom
JordiPosthumus:codex/pr-token-text-cache-lookup

Conversation

@JordiPosthumus

@JordiPosthumus JordiPosthumus commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Retry a rendered-text disk-cache miss with the decoded text of the request's
already-tokenized prompt.

Why

Continued checkpoints are keyed by token text. A client can replay identical
tokens using a byte spelling that the tokenizer canonicalizes. Looking up only
the original request bytes misses the valid checkpoint and repeats prefill.

The existing raw lookup remains first. Only after a miss, DS4 decodes the
already-tokenized prompt and retries through the same checkpoint loader and
validation. The fallback therefore changes candidate discovery, not checkpoint
acceptance.

Compatibility

No cache format, admission, image handling, sampling, launcher or default
change. Existing cache files remain usable. Live rewind is not enabled.

Validation

Rebuilt as one commit directly on main
b0a147a7fba6d1a104d047d5a140e9bb4bfc13cd. New tests cover raw-hit
short-circuit, canonical fallback and output propagation, disabled cache,
canonical-equals-raw, and raw/canonical prefix lookup. The existing loader
continues to enforce model, payload and image eligibility; this patch does not
replace those checks. A dedicated token-decoder failure-injection test is not
included.

Apple M3 Ultra, Metal default build; CPU is compile/link portability only:

make clean
make -j2
make -j2 ds4_test ds4_agent_test
./ds4_test --server
./ds4_agent_test
make -j2 cpu
git diff --check upstream/main...HEAD

All commands passed on 2026-09-04. Earlier C ASan+UBSan server checks passed.
In a fresh-process M3 Ultra/Metal run, Vision-Exp MXFP4 used as a text model
recovered 32,768 cached tokens and evaluated only a 3,664-token suffix. An
unrelated-prefix control explicitly stayed cold. The server invocation was:

./ds4-server --model "$MODEL" --vision "$VISION" \
  --host 127.0.0.1 --port 8001 --ctx 65536 --tokens 4096 \
  --prefill-chunk 4096 --warm-weights --batched-session 1 \
  --kv-disk-dir "$CACHE" --kv-disk-space-mb 16384 \
  --kv-cache-cold-max-tokens 0 \
  --kv-cache-continued-interval-tokens 16384

This is focused validation, not a full aggregate model suite.

Merge coordination: #961 adds image-conditioned candidate filtering at the same
lookup site. If either lands first, retain both the raw-first/canonical fallback
and the image filter when refreshing the other.

@JordiPosthumus
JordiPosthumus marked this pull request as draft September 2, 2026 03:26
@JordiPosthumus
JordiPosthumus deleted the codex/pr-token-text-cache-lookup branch September 2, 2026 03:28
@JordiPosthumus JordiPosthumus reopened this Sep 3, 2026
@JordiPosthumus
JordiPosthumus marked this pull request as ready for review September 3, 2026 10:59
@JordiPosthumus
JordiPosthumus force-pushed the codex/pr-token-text-cache-lookup branch from 9079d2f to 2fbb18d Compare September 3, 2026 10:59
@JordiPosthumus
JordiPosthumus force-pushed the codex/pr-token-text-cache-lookup branch from 2fbb18d to 39929a2 Compare September 4, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant