Skip to content

Refresh prefix-cache recency only for selected snapshots - #299

Closed
voipmonitor wants to merge 3 commits into
mainfrom
martin/prefix-cache-snapshot-recency
Closed

voipmonitor wants to merge 3 commits into
mainfrom
martin/prefix-cache-snapshot-recency

Conversation

@voipmonitor

@voipmonitor voipmonitor commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Reusing or completing a long cached prefix refreshed every ancestor's eviction rank, allowing unused continuation snapshots to compete as recently used entries against other conversations' captures and KV pages. A descendant needs its ancestor pages but restores only its selected snapshot. Completion also needs to retain a useful earlier endpoint: follow-ups that branch or rewrite generated history can depend on the prompt or message snapshot immediately before the terminal. Leaving that snapshot at the admission epoch can lose it after a long response.

This PR changes two shared retention operations:

  • PrefixCheckpointCache::touch refreshes only the selected checkpoint, retaining the maximum epoch. Admission reuse, promotion, and duplicate publication no longer refresh the entire ancestor chain.
  • Successful terminal retirement refreshes the published terminal and its actual cached direct parent with the same completion epoch. The parent commonly holds the prompt end or last captured message boundary. It need not have been created by the completing request: shared and host-restored checkpoints are valid resume points. Duplicate publication follows the retained terminal's parent link, which can differ from the request's prefix. Grandparents keep aging. Completion without a terminal and cancellation after progress refresh only the retained prefix; preemption, execution errors, and cancellation before inference do not add completion recency.

The expected benefit is fewer storage-related capture skips while retaining useful prompt boundaries after long responses. The policy is implemented and qualified by CPU regression tests; native serving latency, hit rates, and memory savings remain unqualified. Existing compaction preserves descendant page order, direct pins, branch points, retirement fences, and compaction-heir notices. The change applies to the shared Kimi, DeepSeek, GLM, and Qwen cache contracts without core re-export. Capture budgets and role ordering remain unchanged. Completion refreshes at most two checkpoints; there is no fixed row cap or proactive thinning, and a matching prompt or message snapshot is not guaranteed to exist.

Validation used Linux x86_64, Rust 1.95.0, GCC/G++ 13.3, protoc 30.2, pinned external template fixtures, an isolated Cargo target directory, and masked CUDA devices. The root test process dropped cap_dac_override and cap_dac_read_search so filesystem permission tests remained meaningful.

Condition and check Result and conclusion
PR #298 at 3f6c74a160d00bba7ccf25f9e94b07e2e23edf15, with regression checks added Four checks for individual snapshot recency, duplicate promotion, exhausted snapshot slots, and aliased-page pressure fail. Ancestor recency propagation prevents reclaiming unused interior rows.
Terminal-only completion refresh at 8999ad14135acfb7ca0aa563ff7216d8e5e34c7d, with parent-refresh checks added Three completion checks fail for interleaved requests, duplicate publication, and a restored parent. The prompt or parent keeps its earlier epoch.
PR implementation, focused CPU coverage Both groups pass. An eight-checkpoint chain permits capture under slot exhaustion and 16-page snapshot aliases blocked by live KV. Completion preserves the terminal and its direct parent while grandparents remain compactable. Tests preserve page order, compaction heirs, preemption epochs, and client-stop fallback. Cache compaction checks cover delayed retirement fences and 64-, 128-, 256-, and 2,048-token page geometries.
Helios library with server,runtime-core, serial CPU execution 1,408 passed, 0 failed, 26 ignored. Includes scheduler/cache lifecycle checks, branch and copy-out pins, host restores, inbound tickets, cancellation, and capture budgets.
Combined patch on 3e9a95d304843fbd9251ac11a8bdd622f04d93d0 plus PR #298 Applies cleanly; 1,390 passed, 0 failed, 26 ignored with the same serial CPU configuration. This base contains 18 fewer tests.

The 26 ignored cases require assigned CUDA devices, external checkpoint/payload inputs, or manual CPU benchmarks. No GPU execution or service benchmark was performed. A parallel library run at 8999ad14 failed the unchanged core::cache::tests::store_slice_streams_multi_block_payloads_and_holds_its_guard collection assertion (zero objects collected instead of one); its isolated rerun and serial suites pass. The cause is unconfirmed, and this PR does not change payload-cache code.

To reproduce, install the documented native build dependencies and huggingface_hub, place protoc 30.2 on PATH, and provide a locked-memory limit of at least 64 MiB:

python3 tests/frontend/prepare_templates.py \
  --output /tmp/hyperflare-snapshot-templates \
  --recipe gemma4 --recipe glm53 --recipe mimo_v2 \
  --recipe nemotron_h --recipe qwen38 --recipe step5
export FLARE_TEST_TEMPLATE_DIR=/tmp/hyperflare-snapshot-templates
export PROTOC=protoc CC=gcc-13 CXX=g++-13
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/gcc-13
export CARGO_TARGET_DIR=/tmp/hyperflare-snapshot-target CARGO_BUILD_JOBS=8
export CUDA_VISIBLE_DEVICES=''
capsh --drop=cap_dac_override,cap_dac_read_search -- -c \
  'cargo test --locked --manifest-path helios/Cargo.toml --features server,runtime-core --lib -- --test-threads=1'

An unprivileged process can run the Cargo command without the capsh wrapper.

This PR targets main and is stacked on #298 at 3f6c74a160d00bba7ccf25f9e94b07e2e23edf15. That dependency supplies bounded host-restore waiting and completion-time recency. Merge #298 first; this PR limits recency propagation to the selected snapshot on reuse and to the terminal plus its direct parent on completion. Until #298 merges, the cumulative diff includes its changes. No measurement files are included.

Host restore admission discarded worthwhile cache hits when snapshot backing
was temporarily held by requests or transfers, while checkpoint recency
followed admission order even after a long request completed. Snapshot
aliases and fenced ownership make capacity failures potentially transient.

Defer restores within the existing transfer-versus-prefill cost budget and
wake admissions on expiry or resource release, including inbound completion
with no remaining waiters. Keep pooled lookup state across retries and reset
wait accounting on admission. Refresh retained checkpoint chains after
successful completion or cancellation with inference progress, excluding
preemption and execution errors. Core formats and graph contracts remain
compatible without re-export.

The implemented policy is expected to avoid unnecessary prefills and retain
recently completed conversations. CPU regressions qualify these decisions;
GPU serving and performance remain unqualified and are tracked in docs/TODO.txt.

Validation: tests for restore deferral and completion recency fail on base
7006928. The Helios library suite with server,runtime-core passes 1402
tests with 26 ignored.
The patch applies cleanly to 3e9a95d3, whose library suite passes 1384 tests
with 26 ignored using the same template fixtures. Ignored cases require
CUDA, checkpoint/payload inputs, or manual CPU benchmarking.
Nine bounded lifecycle model configurations and 361262 observed Rust
transitions pass. Mutation checks detect all 8 TLA+ and 14 Rust faults,
and restored-source checks pass. These checks assume truthful executor
completion and drain signals and do not qualify CUDA execution.

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Design-Signed-Off-By: Codex (GPT-6); design-review=ed22
Reusing or completing a long prefix refreshed every ancestor's eviction
rank, protecting unused continuation rows that compete with KV pages and
other conversations' captures. Descendants need ancestor pages, but only
the selected checkpoint's snapshot; compaction can preserve those pages.

Make PrefixCheckpointCache::touch update only the selected checkpoint's
monotonic demand epoch. Reuse, promotion, duplicate publication, and
completion use that rule. Older unpinned single-child rows can be compacted
without changing descendant pages, branch pins, or retirement fences.
Role ordering and capture budgets remain unchanged. Unused prompt and
message rows can age even when a descendant finishes. Core formats and
prepared graphs remain compatible without re-export.

The implemented change is expected to reduce storage skips and retain
more independently used prefixes under snapshot pressure. CPU regressions
qualify recency and ownership behavior; native serving performance remains
unqualified and is tracked in docs/TODO.txt.

Five focused checks fail with PR #298's implementation and pass with this
change. They cover slot and aliased-page pressure, admission, duplicate
publication, promotion, and completion recency. Compaction preserves pages
and fences at 64-, 128-, 256-, and 2048-token page geometries. The Helios
server,runtime-core CPU suite passes 1405 tests with 26 ignored when run
serially. A parallel run had one failure in unchanged payload-collection
code; that test passes in isolation and in the serial suite. Ignored cases
need CUDA, external checkpoint/payload fixtures, or manual CPU benchmarks.

The patch applies to 3e9a95d3 plus PR #298; that base passes 1387 library
tests with 26 ignored using the same serial CPU configuration.

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Design-Signed-Off-By: Codex (GPT-6); design-review=ed22
A long request can finish with a recent terminal snapshot but a prompt
snapshot still ranked by admission time. Follow-ups that branch or rewrite
generated history can then lose the prompt snapshot under pressure. The
terminal's direct parent provides a bounded second resume point; immutable
checkpoint sharing makes its usefulness independent of which request
captured or restored it.

Refresh the published terminal and its actual cached parent with the same
completion epoch. Duplicate publication follows the retained terminal's
parent link, which can differ from the completing request's prefix. Stop
at that parent so earlier ancestors keep aging. Preemption and execution
errors still suppress completion refresh, and completion without a terminal
or cancellation after progress still refreshes only the retained prefix.
Core formats, capture budgets, and resource lifetime rules remain compatible.

The implemented policy is expected to retain useful prompt boundaries after
long responses without protecting entire checkpoint chains. CPU tests
qualify the retention decisions; live serving improvements remain unmeasured.

Three regressions fail on 8999ad1 and pass with this change: interleaved
request completion, duplicate publication, and a restored parent checkpoint.
Tests also preserve grandparent compaction and page order, preemption epochs,
and client-stop fallback behavior. The Helios library suite with
server,runtime-core and pinned templates passes 1408 tests in serial CPU
execution, with 26 ignored CUDA, external-fixture, or manual-benchmark cases.
No GPU execution or service benchmark was performed.

The combined patch applies to 3e9a95d3 plus PR #298 and passes 1390 library
tests with 26 ignored using the same serial CPU configuration.

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Design-Signed-Off-By: Codex (GPT-6); design-review=ed22
@voipmonitor

Copy link
Copy Markdown
Collaborator Author

Folded into #298: its two commits (8999ad1, b4e5902) are now on that PR's branch, since they revise the recency rule #298 introduces. Closing this one.

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