Skip to content

kvstore: save continued checkpoints after crossed interval frontiers - #903

Open
JordiPosthumus wants to merge 2 commits into
antirez:mainfrom
JordiPosthumus:codex/fix-continued-kv-frontiers
Open

kvstore: save continued checkpoints after crossed interval frontiers#903
JordiPosthumus wants to merge 2 commits into
antirez:mainfrom
JordiPosthumus:codex/fix-continued-kv-frontiers

Conversation

@JordiPosthumus

@JordiPosthumus JordiPosthumus commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Continued KV saves required live_tokens % step == 0. After restoring an
unaligned checkpoint, fixed-size prefill chunks can cross every interval
without ever landing on an exact multiple, so no continued checkpoint is
written.

For example, a production run restored 9,703 tokens and advanced in
2,048-token chunks with a 16,384-token save interval. The sequence
9703 + n * 2048 never reaches an exact interval boundary.

This patch saves at the first valid live position at or beyond each crossed
frontier. It also resets the per-slot frontier to the checkpoint actually
restored, including backward restores and rebuilds from zero, and performs
interval rounding in int64_t before checking the int range.

The cache format, stored tokens, graph payload, and defaults are unchanged.

Tests cover crossed intervals, forward/backward/zero restores, and overflow
at INT_MAX. ds4_test --server, ds4_agent_test, forced Metal and CPU
builds, and the server suite under ASan+UBSan pass on Apple Silicon. No model
is required for these scheduling/state regressions.

Current-main recheck — 2026-09-03

Applied independently to main b0a147a7fba6d1a104d047d5a140e9bb4bfc13cd in a clean
worktree. The default build, ds4_test --server, and ds4_agent_test pass.
The change remains independently useful; cancellation rollback's save-counter
repair is handled separately by #960.

@JordiPosthumus
JordiPosthumus force-pushed the codex/fix-continued-kv-frontiers branch from 6336dc0 to e74f8e1 Compare September 1, 2026 16:28
@JordiPosthumus
JordiPosthumus changed the base branch from glm-5.3-flash to main September 1, 2026 16:30
@JordiPosthumus
JordiPosthumus marked this pull request as draft September 1, 2026 16:52
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