Correctness and contracts scratchpad · NVIDIA/hyperflare-inference #634

Raw Markdown for agents: https://autobot.eidonix.com/p/0558e08e-b9f9-4ec1-ba7f-3a79bf12315a.md

#1 [high] PR #634: idle_seconds_before_burst is a pause self-check, not post-pause latency

scripts/benchmark_scheduler.py:227-228

                    result['idle_seconds_before_burst'] = min(
                        row['started'] for row in result['rows']) - pause_started

started is captured inside request() at scripts/benchmark_scheduler.py:27 (start = time.perf_counter()), AFTER client = connection(url) at :26 and BEFORE client.request('POST', ...) at :29. So idle_seconds_before_burst = sleep + pool/barrier dispatch + TCP connect. It contains no response time and for a local server reads ~= --idle-seconds. It is a self-check that the pause happened, not a latency.

The genuine client-observed post-pause first-token latency already exists: scripts/benchmark_scheduler.py:162 ttfts = [row['groups'][0]['seconds'] for row in rows] and :169 ttft_median_seconds; row['seconds']/groups[].seconds are measured from start at :27 (:40, :56, :65). With --requests-per-lane 1 that median IS the first-token-after-idle number across lanes.

PR text (description, "What changed"/"Benefit") says the row records "the observed interval from the start of the pause to the first request" (accurate) and that operators can "compare first-token latency and SSE delivery gaps after a pause" — but never names ttft_median_seconds, so the field the PR adds under a latency-sounding name is the one that measures nothing about the server.

Fix: name ttft_median_seconds as the idle-latency metric in the description, and/or derive an explicit first_token_after_idle_seconds = min(row['groups'][0]['seconds'] for row in rows) - pause_started (data already present in rows) and describe idle_seconds_before_burst as a pause self-check. Severity: Major.

#2 [high] PR #634: burst cannot reach the funded-refresh episode it targets (30 s TTL, credit, stale-key preconditions)

Goal of the PR: observe the post-idle funded timing-refresh wakeup (docs/scheduling-runtime-design.md:460-466: "Funding the first refresh requires 2,495 ms of cumulative credited ordinary execution ... When full credit carries across an idle gap longer than the freshness lifetime, the first waking request can execute one refresh episode").

Verified preconditions in the runtime:

  1. Credit survives idle: helios/src/scheduler.rs:1077-1083 assert_idle only checks submissions.is_empty(); refresh.abort() is called only from release_after_shutdown (helios/src/scheduler.rs:3006). Parked idle (recv_timeout at helios/src/server/runtime.rs:1244-1250) does not touch credit.
  2. Credit is earned only by Ordinary completions: helios/src/scheduler/refresh.rs:73-78 (INCOME_RATE = 0.002/0.998 at :10, CREDIT_CAP_NS = 5_000_000.0 at :9); ready() requires credit_ns >= CREDIT_CAP_NS (:43-45).
  3. The refresh fires only for a STALE key: helios/src/scheduler/policy.rs:1238-1273 uses self.costs.stale_keys() and filters *key != ordinary.cost_key(); submission rejects a fresh target (helios/src/scheduler.rs:2284-2287 "refresh target must have a stale measured cost").
  4. Freshness lifetime: helios/src/scheduler/policy.rs:38 estimate_ttl_ns: 30_000_000_000 (docs/scheduling-runtime-design.md:636 "estimate_ttl_ns | 30,000,000,000 | Timing freshness interval"); staleness test helios/src/scheduler/cost.rs:100-101, used by stale_keys at :271-274.

Consequence: a pause shorter than 30 s cannot make any cost stale, so no refresh episode can occur. The PR's own evidence ("The second burst began at least 100 ms after the preceding streams drained") is in that regime. Nothing in the CLI help (scripts/benchmark_scheduler.py:187-190), validation (:198-201) or description pins or warns that --idle-seconds must exceed the core's estimate_ttl_ns for the target state to be reachable. Also: defaults give 6 concurrencies x 5 trials, so an --idle-seconds that satisfies >30 s spends >=900 s purely sleeping — worth a note.

Severity: Major (tool silently does not exercise the case it exists to measure).

#3 [high] PR #634: burst pause is not gated on server quiescence and is contaminated by /metrics scrapes

scripts/benchmark_scheduler.py:223-228

                else:
                    pause_started = time.perf_counter()
                    time.sleep(args.idle_seconds)
                    result = trial(args.base_url, bodies[:concurrency], None,
                                   requests_per_lane=args.requests_per_lane or 1)
                    result['idle_seconds_before_burst'] = min(
                        row['started'] for row in result['rows']) - pause_started

There is no gate on server idleness; only a fixed time.sleep. Two consequences:

  1. The pause is not measured from "previous streams drained". trial() is entered only after the previous trial() returns, and trial() performs a blocking metrics(url) scrape twice — before_metrics at :141 and metrics(url) inside the returned dict at :174 — before returning. So the server-visible idle window = --idle-seconds + both scrapes + thread-pool teardown, i.e. longer than the flag says. idle_seconds_before_burst therefore does not describe the idle gap that produced whatever latency was seen, so the recorded value cannot be correlated with the stimulus.
  2. No verification that the server is actually parked. The runtime parks only when nothing is outstanding — helios/src/server/runtime.rs:1236-1251 (if !progress { if executor.outstanding() > 0 { park } else { self.scheduler.assert_idle()?; self.idle_wait(); receiver.recv_timeout(wait) } }) — and the client returns as soon as the last SSE [DONE]/finish_reason arrives (:42-44, :57-58), so the server may still be retiring/snapshotting when the sleep starts. Legacy/pooled requests are worse: begin_pool_lookups (helios/src/server/runtime.rs:1292-1297) starts host-prefix lookups at enqueue, and idle_wait() returns 50 us while inbound_in_flight > 0 (helios/src/server/runtime.rs:1257-1265), i.e. the worker is not parked across a restore.

The script already fetches the server's own snapshot twice per trial, and the server exposes the needed gauges: active and pending on Snapshot (helios/src/server/metrics.rs:88,90, serialized at :363-364) and flare_active_requests / flare_pending_requests in the Prometheus text (helios/src/server/metrics.rs:1255,1300). A poll of /metrics until pending == 0 && active == 0 (bounded by a timeout that errors) before starting the measured sleep would make the stimulus real and measurable, and would let the row record the dwell time from actual quiescence rather than from the start of a sleep.

Severity: Major.

#5 [high] PR #634 addendum: refresh requires a differing stale shape, which homogeneous bursts never create

Refines entry 2. Two distinct prerequisites, and the burst tool satisfies neither by construction in its documented use:

(a) Staleness needs > estimate_ttl_ns = 30 s (helios/src/scheduler/policy.rs:38; cost.rs:100-101). The PR's own evidence — "The second burst began at least 100 ms after the preceding streams drained" — is 300x below that. Nothing in the CLI help (scripts/benchmark_scheduler.py:187-188) or validation (:198-199) says so.

(b) A refresh can only be selected for a different, previously executed, now-stale shape:

(c) Credit (the cheap part) is normally already satisfied: 5 ms cap at INCOME_RATE = 0.002/0.998 (refresh.rs:9-10) fills after ~2,495 ms of ordinary execution, which the default --warmup-seconds 30 per concurrency supplies. So credit is not the blocker; (a)+(b) are, and neither is documented.

Severity: Major — the tool does not reach the state the PR exists to observe, and its evidence run is two orders of magnitude short of the threshold.

#6 [high] PR #634: probe-episode counter is fetched but never parsed, so no row proves a refresh happened

The server already exposes the counter that would prove the case was reached, and the script already fetches it twice per trial but never parses it.

helios/src/server/metrics.rs:931-938

        for (name, help, counts) in [
            ("execution_nanoseconds_total", ..., &self.scheduler_trace.execution_ns),
            ("executions_total", "Completed physical executions by scheduler selection reason; each generation round counts once.", &self.scheduler_trace.executions),
        ] {
            let _ = writeln!(text, "# HELP flare_scheduler_{name} {help}\n# TYPE flare_scheduler_{name} counter");
            for (reason, count) in ["ordinary", "discovery", "timing_refresh", "acceptance_learning"].into_iter().zip(counts) {

Selection reasons are PlanOrigin variants (helios/src/scheduler/refresh.rs:13-30; PlanOrigin::RefreshStart / AcceptanceStart are the probe episodes).

The script stores both scrapes as opaque strings — scripts/benchmark_scheduler.py:141 before_metrics = metrics(url) and :174 'metrics_before': before_metrics, 'metrics_after': metrics(url) — and emits them verbatim in the JSONL row (:233), so a reviewer/operator must hand-diff them.

Concrete fix: parse flare_scheduler_executions_total{reason="timing_refresh"} (and acceptance_learning, and flare_scheduler_execution_nanoseconds_total{reason=...}) out of metrics_before/metrics_after, record the per-trial delta as a row field, and fail or warn when a run intended to observe the post-idle episode records zero refreshes. Same for flare_active_requests/flare_pending_requests (helios/src/server/metrics.rs:1255,1300) to verify the server was actually parked before the burst (entry 3). Without this the PR's central claim — that a burst measures the post-idle wakeup — cannot be told apart from a burst that measured ordinary service.

Severity: Major (claim accuracy / evidence).

#10 [high] Research summary

Reviewed PR #634 (scripts/benchmark_scheduler.py, +21/−4) for correctness, contracts and system-level consequences. Nine scratchpad notes hold the verified findings with file:line citations and verbatim quotes.

Two high-signal correctness/claim problems (Major).

First, the headline new field does not measure what its name implies and cannot fail. idle_seconds_before_burst (scripts/benchmark_scheduler.py:227-228) subtracts pause_started from row['started'], and started is captured at :27 — after connection(url) at :26 and before the POST at :29. It therefore measures sleep + thread-pool dispatch + connect, contains no response time, and by construction is always ≥ --idle-seconds. The genuine post-pause first-token number already exists as ttft_median_seconds (:162, :169); the description never names it while presenting a non-latency field under a latency-sounding name.

Second, the burst tool does not reach the state it exists to observe. I traced the Helios scheduler: a funded refresh needs a cost stale beyond estimate_ttl_ns = 30_000_000_000 (helios/src/scheduler/policy.rs:38, cost.rs:100-101) and a differing previously-executed stale key — stale_keys().filter(|key| *key != ordinary.cost_key()) (policy.rs:1238-1240), where stale_keys yields only observed keys (cost.rs:271-274) and costs are recorded only per executed plan (helios/src/scheduler.rs:1060-1061). A homogeneous run only ever executes the ordinary winner shape, so targets is empty and no episode is possible however long the pause. The PR's own evidence ("at least 100 ms") is ~300× below the staleness threshold, and the in-repo analogue explicitly sets up a second shape first (helios/src/scheduler/policy_tests.rs:6253-6284). Credit, the cheap part, is already satisfied by the default 30 s warmup (refresh.rs:9-10).

Also Major: the pause has no server-quiescence gate and is not measured from drain — trial() performs two blocking /metrics scrapes (:141, :174) before returning, so the server-visible idle window exceeds the flag; the runtime parks only when nothing is outstanding (helios/src/server/runtime.rs:1236-1251), so quiescence is never verified even though flare_active_requests/flare_pending_requests are available (metrics.rs:1255,1300). And flare_scheduler_executions_total{reason="timing_refresh"} — the direct proof an episode occurred (metrics.rs:931-938) — is scraped as an opaque string and never parsed, so no JSONL row can distinguish a post-idle wakeup from ordinary service.

Minor: idle mode silently reuses JSONL keys with new meanings (issue_duration_seconds becomes null, tokens_per_second spans a burst not the --seconds window, :164-165), and --requests-per-lane counts completed synchronous requests per lane, so only round one is concurrent post-idle traffic (:147-151). I explicitly retracted a potential duration or 0 defect as a non-issue (0 or 0 == 0). No Rust behavior, lock, buffer or allocation path changes; continuous mode is untouched; validation is loud and correct. The new branches are exercised by no automated check — nothing in the repo imports the script while .github/workflows/python-cpu.yml:33 (not opened) only runs pytest tests/.

#11 [high] PR #634: verbatim description text for claim-accuracy comparison

Head a0467e2, base main (branched at 0a8c20f), branch bench/scheduler-idle-resume. One file: scripts/benchmark_scheduler.py (modified, +21 -4).

Why

"The scheduler benchmark continuously issues requests during each trial. It cannot isolate streaming behavior when traffic returns after an idle period, a qualification case for the timing credit retained by #540."

What changed

"Add an opt-in burst mode to scripts/benchmark_scheduler.py. With --idle-seconds, the driver waits after previous streams drain, then issues a fixed number of requests per concurrency lane. Each JSONL trial records the observed interval from the start of the pause to the first request, alongside the existing streaming metrics. The continuous mode remains the default."

Benefit

"Operators can replay the same request bodies and request counts across builds, and compare first-token latency and SSE delivery gaps after a pause."

Evidence

"Ran both CLI modes against a local HTTP server emitting complete SSE streams. Two lanes with one request per lane yielded two completed requests per burst. The second burst began at least 100 ms after the preceding streams drained. The continuous control retained its deadline-based output. Python compilation and git diff --check passed. Native GPU serving, scheduler idle transitions, and latency gains were not measured."

"Discord: no username provided"

Accuracy notes for the report:

#12 [high] PR #634: layer/charter placement and the unfilled TODO contract

The PR's only maintainer-side authorization is an unchecked TODO in core Flare, which it neither references nor closes:

docs/TODO.txt:110-114

[ ] Qualify retained graph costs and funded remeasurement in live Helios:
    idle/resume, concurrent decode latency, cost-change recovery, and queued
    generation transitions. Use per-fence scheduler traces and request
    latency measurements; measure GPU replay, queueing, and host planning separately.
    See scheduling-runtime-design.md#funded-timing-refresh.

The TODO names four cases; #634's burst mode addresses only the first (idle/resume), and only the client-observed half — it does not touch "per-fence scheduler traces" and its tokens_per_second/elapsed cannot separate "GPU replay, queueing, and host planning". Since no measurement is produced, leaving the entry unchecked is defensible, but nothing in the entry or in docs/ points a future reader at the new flags (search_code "benchmark_scheduler" in docs/ → only an unrelated scripts/benchmark_csf_conversion.py hit at docs/tp-checkpoint-layout.md:58). Suggest a one-line pointer in the TODO entry or a mention in the description, and referencing the TODO by number.

Layer tension, AGENTS.md:9-13:

operator-tuning fixtures, numerical references, qualification drivers, and
model test suites live in
[local-inference-lab/hyperflare-recipes](https://github.com/local-inference-lab/hyperflare-recipes),
which depends on `ignition` from this repository.

A live-server qualification capability is being added to core Flare's scripts/. Mitigating: docs/TODO.txt:110-114 is itself a core-Flare TODO, and scripts/ is documented as holding "scheduling simulator and utility scripts" (AGENTS.md:24-25), so the placement is defensible — but the reviewer's answer should hinge on the TODO, not on the script being convenient.

Contract surface: no wire/proto/captured-graph/public API change, no dependency change (stdlib only; math already imported at scripts/benchmark_scheduler.py:11), no default change (continuous path behaviour-identical; --idle-seconds default None at :187). Therefore none of AGENTS.md's owner-sign-off gates (e.g. :376 captured-graph operation families) are triggered. The only externally visible contract is the JSONL key set, addressed in entry 4.

Docs requirement cross-check: docs/core-design.md:1818-1838 lists the required live measurement set and has no idle-resume/post-pause-first-token row, so the new capability is not reflected there either; no doc update is part of the diff.

#4 [medium] PR #634: idle mode silently changes the span of issue_duration_seconds/tokens_per_second

Diff (scripts/benchmark_scheduler.py:225) passes None as duration; trial then emits reused keys with new meanings at scripts/benchmark_scheduler.py:156,164-165:

   156        deadline[0] = start + (duration or 0)
   164        return {'concurrency': len(bodies), 'issue_duration_seconds': duration, 'elapsed_seconds': elapsed,
   165                'requests': len(rows), 'generated_tokens': tokens, 'tokens_per_second': tokens / elapsed,

In idle mode:

Neither is mentioned in the PR description. No in-repo consumer parses these keys (search_code for issue_duration_seconds|tokens_per_second finds only scripts/benchmark_scheduler.py:164-165 for these names — the other hits are unrelated *_tokens_per_second fields in flare/, flare-winui/, selene/), and --reuse-requests only reads the first JSONL line's requests (:204-205), so nothing breaks today, but a JSONL-joining consumer comparing tokens_per_second across a continuous run and a burst run compares different quantities under the same key.

Fix: in idle mode emit the reuse-invariant rate under a distinct key (e.g. burst_tokens_per_second) or set tokens_per_second to None; and either omit issue_duration_seconds in burst mode or rename it. Also fix duration or 0 at :156 so an explicit --seconds 0 stays 0 rather than being coerced (currently masked because validation requires --idle-seconds > 0 and the count branch is used, but duration or 0 is the kind of implicit fallback AGENTS.md:118-119 disallows: "No magic defaults, and pin dependencies to exact versions").

Severity: Minor (latent schema/meaning change, no consumer today).

#8 [medium] PR #634: verified-sound areas and test/CI coverage gap

Areas checked and found sound (no findings):

Test gap (context for the final report): nothing in tests/ imports this script (search_code "benchmark_scheduler" → no matches anywhere in the repo), and .github/workflows/python-cpu.yml:33 runs pytest tests/, so the new branches are exercised by no automated check. The comparable script scripts/setup_preparation.py does get a load-and-call unit test at tests/preparation/test_setup_preparation.py:15-18, so the pattern for testing a script in-repo exists.

#9 [medium] PR #634 corrections: duration-or-0 is a non-issue; idle field can never fail by construction

Correcting entry 4: the duration or 0 line (scripts/benchmark_scheduler.py:156) is NOT a finding. 0 or 0 == 0, so an explicit --seconds 0 behaves exactly as on main; the or 0 is purely a None guard. Do not report it as a magic-default defect.

The one real manifest issue from the schema finding is the renamed meaning: in idle mode trial is called with duration=None (:225) so issue_duration_seconds is written as JSON null (:164) where main always wrote a float, and tokens_per_second (:165) is tokens / burst_elapsed instead of tokens / --seconds window. Severity Minor, no in-repo consumer.

Also sharpen entry 1: idle_seconds_before_burst cannot fail. pause_started = time.perf_counter(); time.sleep(args.idle_seconds) (:223-224) guarantees the next request()'s start (:27) is >= pause_started + idle_seconds, so the field is always >= --idle-seconds and only grows with client-side stalls (thread-pool start, barrier, DNS/connect). It is a lower-bound assertion on the client's own sleep, not a measurement of the server.

#7 [low] PR #634: "requests per lane" is a sequential count, not a concurrent burst

scripts/benchmark_scheduler.py:147-151

        while (len(results) < requests_per_lane if requests_per_lane is not None
               else time.perf_counter() < deadline[0]):
            row = request(url, body, stream=True)
            row['lane'] = lane
            results.append(row)

The count is of completed requests, and request() is fully synchronous per lane, so with --requests-per-lane N each lane issues request k+1 only after request k's stream ends. The help text at :189-190 says "Requests per lane in each idle-mode burst" and the description says "issues a fixed number of requests per concurrency lane", both of which read as a concurrent burst of N. What actually happens is one concurrent round of len(bodies) requests followed by N-1 serialized follow-ups per lane; only round 1 is post-idle in the sense the PR cares about, and elapsed/tokens_per_second (:159,165) span all N rounds.

Severity: Minor (documentation/semantics of the new flag; affects how an operator reads requests and elapsed_seconds). Fix: state in the help that rounds after the first are issued sequentially per lane after the previous stream completes, and expose per-round figures, or count per-round requests explicitly.