Skip to content

helios: retain measured snapshot cost after expiry and discover unmeasured cost once - #655

Merged
lukealonso merged 1 commit into
NVIDIA:mainfrom
yatesdr:fix/helios-snapshot-cost-probe
Dec 3, 2026
Merged

lukealonso merged 1 commit into
NVIDIA:mainfrom
yatesdr:fix/helios-snapshot-cost-probe

Conversation

@yatesdr

@yatesdr yatesdr commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Related to #534

Replaces the earlier 30 s probe approach with two cleaner changes that bring GraphKind::Snapshot pricing into parity with Prefill (PR #285):

  1. Retain measured snapshot cost after TTL expiry (ActionCosts::measured_duration):
    • Prefill estimates already retain measured durations after estimate_ttl_ns (30 s) and reset their rolling ReplayTimes window on the next execution (ActionCosts::observe).
    • Snapshot was the only remaining caller of ActionCosts::fresh_duration, which reverted to None after 30 s and caused terminal Endpoint captures and prefill Message extras to skip with unknown_cost after any >30 s decode or idle pause.
    • Replace fresh_duration with ActionCosts::measured_duration, scanning declared batches in ascending order and returning the smallest declared batch with nanos != 0. Once any Snapshot batch has been observed, both prefill extras and terminal captures stay available across long decodes and idle pauses, and ActionCosts::observe still resets the 9-sample rolling window on the next execution after expiry.
  2. Single in-flight cold discovery for unmeasured Snapshot (nanos == 0):
    • On a warm restart against a persistent host prefix cache (--prefix-cache-disk or --prefix-cache-pool), Snapshot starts unmeasured (nanos == 0). Requests whose Anchor is already cached execute Restore -> Resume -> Decode without an Anchor snapshot, previously leaving Snapshot permanently unmeasured.
    • Track at most one in-flight terminal discovery request via RequestScheduler::snapshot_discovery: Option<RequestHandle>. When measured_duration is None, checkpoint_extra_work_fraction > 0, and no discovery is in flight, allocate_terminal_capture prices that single capture at zero and records the handle only if snapshot storage is obtained.
    • complete_inner (normal completion and status-3 fallback) and retire (cancel / finish) clear snapshot_discovery immediately so cancellations or batch coalescing cannot leave discovery locked out.
  3. Documentation alignment:
    • Synchronized docs/scheduling-runtime-design.md, docs/core-design.md, docs/cli-design.md, and helios/README.md.

Validation

  • RUSTFLAGS="-D warnings" cargo check --locked --manifest-path helios/Cargo.toml --features runtime-core,server --all-targets: passed.
  • Targeted unit tests in helios (--release --features runtime-core,server):
    • scheduler::cost::tests::measured_duration_uses_smallest_measured_batch_and_retains_after_ttl
    • scheduler::checkpoints::tests::unknown_prefill_or_unmeasured_snapshot_cost_disables_extras
    • scheduler::checkpoints::tests::measured_prefill_and_snapshot_costs_keep_extras_available_after_idle
    • scheduler::checkpoints::tests::measured_snapshot_cost_retains_terminal_captures_after_long_decode_or_idle
    • scheduler::checkpoints::tests::unmeasured_snapshot_cost_allows_one_inflight_terminal_discovery_and_recovers_on_cancel
    • scheduler::checkpoints::tests::terminal_snapshot_discovery_end_to_end_plan_commit_complete_unblocks_subsequent_captures
  • Full helios::scheduler:: suite (--release --features runtime-core,server): 409 passed, 0 failed (4 ignored).
  • Full flare crate suite (--release): 246 passed, 0 failed (4 ignored).
  • Live SM120 verification (Qwen3.8-Flash-Next TP1, --prefix-cache-memory 4G --prefix-cache-disk ...):
    • 30 s decode (34.7 s, 6000 completion tokens): anchor=+1, endpoint=+2, unknown_cost only on initial cold prefill before first snapshot (0 on terminal decode).

    • 33 s idle pause + cached-anchor request: cached_tokens=2922, endpoint=+1, unknown_cost=0.

    • 33 s idle pause + new multi-message prompt: anchor=+1, endpoint=+2, unknown_cost=0 (prefill extras evaluated immediately).

    • Warm disk restart (Snapshot unmeasured) + cached-anchor hit: host_cache_hits=+1 (2917 tokens), endpoint=+1 via single cold discovery, and immediate follow-up unknown_cost=0, anchor=+1, endpoint=+2.
  • Scheduler-change checklist notes: scripts/scheduling_sim does not model checkpoint ActionCosts expiry/discovery (N/A); CheckpointReservation.tla reservation invariants are unchanged (CI lifecycle / kani / pytest will also verify).

Discord: D-Rock

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 655.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:caching Prefix/KV reuse, cache retention, and model or payload cache behavior. area:scheduling Request scheduling, fairness, batching, and speculative-width selection. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness. labels Dec 1, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

Lean, well-scoped (~20 net production lines) fix for three genuine upstream terminal Endpoint capture scenarios, with clean SM120 A/B evidence and green CI — no merge blockers, but three should-fix items remain before landing.

  • Blockers: 0 · Should fix: 3 · Subtract/Simplify: 2 · Nits: 2
Walkthrough
  • helios/src/scheduler/cost.rs: Added last_probe_ns: Option<u64> to Estimate (initialized None in ActionCosts::prepared), extracted smallest_batch_key(kind, tokens) (shared by fresh_duration, probe_duration, and record_probe), added probe_duration (returns Some(estimate.nanos) when not fresh and outside the TTL cooldown — 0 when unmeasured, retained duration when stale), and added record_probe plus a unit test (probe_duration_uses_smallest_declared_batch_and_bounds_by_ttl).
  • helios/src/scheduler/checkpoints.rs: Updated RequestScheduler::allocate_terminal_capture so that when fresh_duration(GraphKind::Snapshot, 1) returns None and checkpoint_extra_work_fraction > 0.0, it falls back to probe_duration(GraphKind::Snapshot, 1), runs the existing work-budget and marginal-gain storage-quote checks against that duration, and calls record_probe(GraphKind::Snapshot, 1) only when a snapshot row is actually allocated (snapshot.is_some()). Added two unit tests covering unmeasured and stale/zero-budget terminal capture probing.
  • docs/scheduling-runtime-design.md: Updated the checkpoint extra-work specification (lines 617-629) to distinguish prefill extras (still disabled when snapshot cost is unmeasured or stale) from the bounded one-probe-per-estimate_ttl_ns terminal capture when scheduler_checkpoint_extra_work_fraction > 0.
Merge Risk: Low · up to 2d9454f
  • Production footprint is tightly localized to ActionCosts (Estimate::last_probe_ns, smallest_batch_key, probe_duration, record_probe) and RequestScheduler::allocate_terminal_capture, with no wire/Protobuf, CLI, config-default, or metric-schema changes.
  • Extra work is strictly bounded to at most one Snapshot copy per estimate_ttl_ns (30 s default), prefill extras remain gated on fresh costs, checkpoint_extra_work_fraction == 0.0 is preserved byte-identically, deferred_prefill returns early before probing, and last_probe_ns is isolated from last_attempt_ns/refresh_order so funded timing refresh (Retain bounded timing-refresh and acceptance credit across idle #540) is unaffected.
  • Worst-case failure mode is transient loss of a single 30 s probe window (falling back to the pre-PR unknown_cost skip behavior until the next TTL), with no cache-ownership, fencing, or data-corruption hazard.
Pre-merge checks: ✅ 2 passed · ⚠️ 2 warnings
  • ✅ Security / malicious screen: Pure scheduler arithmetic and documentation; no I/O, FFI, parsing, privilege, or untrusted-input surface introduced.
  • ✅ Charter & value fit: Model- and core-agnostic (smallest_batch_key uses declared core metadata, no per-model branch or magic default), minimal footprint in the right runtime layer, directly supports host/Selene prefix-cache retention.
  • ⚠️ Related / duplicate / conflict check: Fixes #534 auto-closes an issue whose cold-boot deadlock was rebutted twice as fork-specific (PrefillTailMerge) without addressing the rebuttal; open draft feat(scheduler): persist learned graph costs across serving restarts #301 edits the same Estimate struct in cost.rs (complementary for warm restarts, expected small rebase).
  • ⚠️ Tests & verification evidence: CI (including helios-lifecycle TLA+ conformance and Kani) is green on 2d9454f and live SM120 A/B covers the three claimed scenarios; however, new tests call measure(...) manually rather than exercising an end-to-end plan -> commit -> complete Snapshot refresh cycle, and the Validation section omits noting why scripts/scheduling_sim is N/A (no checkpoint model).

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@yatesdr
yatesdr force-pushed the fix/helios-snapshot-cost-probe branch from 2d9454f to f7f4d25 Compare December 1, 2026 16:39
@yatesdr yatesdr changed the title helios: probe unmeasured or stale snapshot cost once per TTL on terminal capture helios: retain measured snapshot cost after expiry and discover unmeasured cost once Dec 1, 2026
@yatesdr

yatesdr commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

Replaced the 30 s TTL probe with retained measured Snapshot duration (ActionCosts::measured_duration, parity with PR #285 for Prefill) plus a single in-flight cold discovery guard (snapshot_discovery: Option<RequestHandle>) used only when nanos == 0, addressing all three review findings:

  1. Changed Fixes #534 to Related to #534 so Checkpoint captures deadlock on an unmeasured snapshot cost: host prefix cache never receives anything (unknown_cost skips forever) #534 is not auto-closed prematurely.
  2. Synchronized all four docs (docs/scheduling-runtime-design.md, docs/core-design.md, docs/cli-design.md, helios/README.md).
  3. Removed the 30 s probe timer entirely: measured_duration scans declared batches ascending (handling batch > 1 coalescing) and retains measured durations after TTL expiry (while observe() still resets the rolling window on the next execution); cold discovery (nanos == 0 only) clears on completion, status-3 fallback, finish, and cancel, and is covered by an end-to-end plan -> commit -> complete test plus live SM120 4-scenario verification on Qwen3.8-Flash-Next TP1.

@flare-autobot please re-review.

Discord: D-Rock

@flare-autobot

flare-autobot commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

Head f7f4d25 cleanly resolves all three items from the prior review (2d9454f) and replaces the 30 s probe timer with a simpler, strictly better design: ActionCosts::measured_duration brings Snapshot pricing into parity with Prefill cost retention (PR #285), and a single in-flight snapshot_discovery slot handles cold warm-restart discovery (nanos == 0). No blockers or should-fix defects remain.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 2 · Nits: 2
Walkthrough
  • helios/src/scheduler/cost.rs: Replaced ActionCosts::fresh_duration with ActionCosts::measured_duration (:783-790), returning the smallest declared batch with nanos != 0 regardless of TTL expiry (while observe() still resets ReplayTimes when stale).
  • helios/src/scheduler/checkpoints.rs: Switched all three snapshot-cost gates (checkpoint_selection_uncached:624, checkpoint_copy_allowed:965, allocate_terminal_capture:1039) to measured_duration, added snapshot_discovery_in_flight (:1018-1023) and single-in-flight zero-priced terminal discovery (:1039-1079), plus updated/added CPU tests including end-to-end plan -> commit -> complete discovery (:4125-4306).
  • helios/src/scheduler.rs: Added snapshot_discovery: Option<RequestHandle> (:661, :756) and clears in complete_inner (:2690-2692, :2700-2702) and retire (:3067-3069).
  • docs/scheduling-runtime-design.md, docs/core-design.md, docs/cli-design.md, helios/README.md: Synchronized checkpoint extra-work docs across all four documents.
Merge Risk: Low · up to f7f4d25
  • Production changes are small and tightly scoped to cost.rs, checkpoints.rs, and scheduler.rs; no wire format, CLI default, metric schema, or row-ownership/fencing logic changes.
  • RequestScheduler is single-threaded (&mut self), checkpoint_selection is memoized per planning pass, checkpoint_extra_work_fraction == 0.0 and deferred_prefill behavior are preserved, and snapshot_discovery is claimed only after a snapshot row is obtained.
  • Worst-case failure mode of the cold-discovery gate degrades benignly to pre-PR unknown_cost skips.
Pre-merge checks: ✅ 4 passed

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@yatesdr

yatesdr commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

@flare-autobot please do a a full review.

@nepenth

nepenth commented Dec 2, 2026

Copy link
Copy Markdown

+1 confirming this behavior on 2× GB10 (SM121) TP2 with GLM-5.3-Flash-FP4-Local (v0.5.0):

We observed warm multi-turn system-message prefix requests (32k and 64k shared system documents) skipping message-boundary checkpoints with unknown_cost (cached_tokens=9) whenever Snapshot duration was unmeasured or expired. Retaining measured Snapshot duration past TTL and doing one-shot cold discovery addresses the exact root cause we worked around locally (64k warm prefix TTFT dropped from 24.97 s cold to 330 ms warm with 61,910 cached tokens once checkpoints were allowed to commit).

…sured cost once

Prefill estimates already retain measured durations after TTL expiry and reset
their rolling window on the next execution, whereas snapshot-copy cost used
ActionCosts::fresh_duration and reverted to None after estimate_ttl_ns (30 s).
Any decode longer than 30 s or any idle gap longer than 30 s caused terminal
Endpoint captures and prefill Message extras to skip with unknown_cost even
though a measured snapshot duration was already recorded. Separately, a warm
restart against a persistent host prefix cache (--prefix-cache-disk or
--prefix-cache-pool) starts with unmeasured Snapshot costs (nanos == 0); when
incoming prompts hit cached anchors, no Anchor snapshot executes and terminal
captures remained permanently stuck at unknown_cost.

Replace fresh_duration (whose only callers were the three snapshot checks in
checkpoints.rs) with ActionCosts::measured_duration, which scans declared
batches in ascending order and returns the smallest declared batch with
nanos != 0, retaining measured estimates across TTL expiry with parity to
prefill pricing while ActionCosts::observe still resets the rolling window on
the next run after expiry.

For the remaining cold-start case where no Snapshot batch has been measured
yet (nanos == 0), track at most one in-flight terminal discovery request via
RequestScheduler::snapshot_discovery: Option<RequestHandle>. When
checkpoint_extra_work_fraction > 0 and no discovery is in flight,
allocate_terminal_capture prices that single capture at zero and records the
handle only if snapshot storage is obtained; snapshot completion, status-3
fallback, finish, and cancel all clear the handle so subsequent requests
recover immediately.

Update docs/scheduling-runtime-design.md, docs/core-design.md,
docs/cli-design.md, and helios/README.md, and add unit tests covering
ascending-batch fallback and post-TTL retention, long decode/idle retention,
single-flight cold discovery with cancel/storage/zero-fraction recovery, and
end-to-end plan -> commit -> complete observation unblocking prefill extras.

Related to NVIDIA#534

Signed-off-by: yatesdr <6937857+yatesdr@users.noreply.github.com>
Design-Signed-Off-By: yatesdr; design-review=2e5b
@yatesdr
yatesdr force-pushed the fix/helios-snapshot-cost-probe branch from f7f4d25 to f8e4945 Compare December 3, 2026 04:08
@lukealonso
lukealonso merged commit 99f87f7 into NVIDIA:main Dec 3, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:caching Prefix/KV reuse, cache retention, and model or payload cache behavior. area:scheduling Request scheduling, fairness, batching, and speculative-width selection. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants