Skip to content

fix(inference): a turn's wait bound is sized from its measured work — pre-stream and remote constants become floors (card ba82d0a0) - #4277

Merged
joelteply merged 1 commit into
canaryfrom
fix/turn-bounds-from-measured-rates
Sep 20, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/turn-bounds-from-measured-rates

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Defect (card ba82d0a0)

Fixed bounds shorter than a CPU box's prefill kill live turns and read them as dead:

  • inference/lane_send.rs PRE_STREAM_HEADER_TIMEOUT_SECS = 300 — the wait for response headers after the POST, and (via sse_stream.rs) the stream's queue budget before the slot shows work.
  • inference/airc_remote/transport.rs REMOTE_INFERENCE_DEADLINE = 600s — a remote turn end to end.

Measured tonight on the M5 (inference.prefill.complete, the serving node itself):

total=27547 cached=0 fresh=27547 ingest_ms=389376 ingest_tok_per_s=70 would_have_died=1
total=30672 cached=0            ingest_ms=331447 ingest_tok_per_s=92 would_have_died=1

331–389 s before the first byte, past the 300 s pre-stream bound. The IntelMac prefills at ~25 tok/s: a 30k prompt is ~1200 s before its first byte — past both bounds. The turn is busy, not dead. The law: a bound is sized from the measured work.

Fix

The faculty already computes expected_occupancy() for a turn (uncached prompt at this box's measured prefill rate + her last output at its measured decode rate). This PR carries it to every waiting seam:

  1. TextGenerationRequest.turn_bound: Option<Duration> — the expectation × TURN_BOUND_HEADROOM (2×, named and justified in inference/turn_bound.rs: the expectation is a median, and a co-tenant's turn-sized prefill may be queued ahead). Serde-serialized ({secs, nanos}, #[serde(default)]) so the serving peer's lane honours it too; commands/ai/generate.rs parses it off the wire (it builds the request field by field and would otherwise have dropped it on the peer). ts-rs binding regenerated by hand to what cargo test emits (CI's drift check verifies).
  2. inference::turn_bound::effective_bound(floor, turn_bound) — pure: the floor, or the turn bound above it. Applied in lane_send (header wait), sse_stream (queue budget), transport (remote deadline). Nothing renamed; the constants are documented as FLOORS. Nothing here shortens a wait.
  3. Probe inference.bound.tripped when a bound trips: at (pre_stream_headers | stream_queue | remote_deadline), name (lane / model@peer), bound_secs, source (floor | turn_bound), turn_bound_secs, expected_secs. Also delib.turn.bound when the faculty sets one. Added to the probe manual.
  4. would_have_died on inference.prefill.complete now shadows the bound in force for the turn (elapsed > queue_budget, with bound_secs / bound_source beside it) instead of the retired 90 s decode watchdog — so a 1 on a healthy lane reads directly as "the bound is undersized".
  5. Tests: effective_bound (none → floor; below → floor; above → the bound), from_expectation headroom + inverse, the faculty's occupancy physics for the IntelMac shape (30k cold @ 25 tok/s → 1280 s expected → 2560 s bound, above both floors) and a fresh mind carrying no bound, and the remote floor never lowered.

Not in this PR

Defect 2 (measured_tps_for fallback order / the output allowance) was dropped per the coordinator: #4194 is being reverted on canary tonight and this branch would conflict. Edits to build_request_within are confined to the literal's tail (turn_bound: self.turn_bound()), clear of #4194's hunks; the new faculty tests deliberately do not call build_request_within (its signature changes with the revert).

The faculty test for the Some path is at the pure-physics level: expected_occupancy() reads the live serving snapshot and the prefill/decode rate ledgers (process globals a test must not seed).

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

… the fixed pre-stream and remote constants become floors, never the bound (card ba82d0a0)

Two fixed bounds shorter than a slow box's prefill killed live turns and read them
as dead: PRE_STREAM_HEADER_TIMEOUT_SECS (300 s; the header wait after the POST and
the SSE stream's queue budget) and REMOTE_INFERENCE_DEADLINE (600 s; a remote turn
end to end). Measured on the M5 tonight (inference.prefill.complete): total=27547
cached=0 fresh=27547 ingest_ms=389376 ingest_tok_per_s=70 would_have_died=1 and
total=30672 cached=0 ingest_ms=331447 ingest_tok_per_s=92 would_have_died=1 —
331–389 s before the first byte on the serving node itself, past the 300 s bound.
The IntelMac prefills at ~25 tok/s: a 30k prompt is ~1200 s before its first byte,
past both. The law: a bound is sized from the measured work; busy is not dead.

The mind already computes what a turn is expected to cost
(LlmDeliberationFaculty::expected_occupancy: the uncached prompt at this box's
measured prefill rate plus her last output at its measured decode rate).

- TextGenerationRequest.turn_bound: Option<Duration> — the expectation with
  headroom (inference::turn_bound, TURN_BOUND_HEADROOM = 2×: the expectation is a
  median, and a co-tenant's turn may be queued ahead). Serialized (serde
  {secs, nanos}) so the SERVING peer's lane honours it; ai/generate parses it off
  the wire (it builds the request field by field and would have dropped it).
- inference::turn_bound::effective_bound(floor, turn_bound): the floor, or the turn
  bound above it. Applied at the header wait (lane_send), the stream's queue budget
  (sse_stream) and the remote deadline (transport). Nothing renamed; the constants'
  docs now say FLOOR. Nothing here shortens a wait.
- Probe inference.bound.tripped when a bound trips: at (pre_stream_headers |
  stream_queue | remote_deadline), name (lane / model@peer), bound_secs, source
  (floor | turn_bound), turn_bound_secs, expected_secs. Probe delib.turn.bound when
  the faculty sets one. inference.prefill.complete's would_have_died now shadows the
  bound in force for the turn (with bound_secs/bound_source), not the retired 90 s
  decode watchdog.
- Tests: effective_bound (no bound → floor; below → floor; above → the bound);
  from_expectation headroom + inverse; the faculty's occupancy physics for the
  IntelMac shape (30k cold at 25 tok/s → 1280 s expected, 2560 s bound, above both
  floors) and a fresh mind carrying no bound; the remote floor never lowered.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE — reviewed at exact head 8f2dff7 (the two cargo jobs running at read time; labeler and checks-selection green). This is the fix for the IntelMac hour I read: prefills that finished in 589–694 s under bounds of 300 / 600 s.

The shape is right and it is small at its core: turn_bound = expected_occupancy × TURN_BOUND_HEADROOM where the expectation is her last turn's uncached prompt at this box's measured prefill rate plus her output at its measured decode — and every waiting seam (the pre-stream header wait, the stream's queue budget, the remote deadline) takes max(its floor, the bound), so the constants stop being ceilings and become floors, an absent expectation leaves the floors governing alone (an absence is not a number), and inference.bound.tripped names which bound tripped, from which source, with the expectation behind it — that row is what turns the next dead turn into a measurement instead of a mystery. The bound rides TextGenerationRequest so the remote path carries it; ts-rs regenerated. The IntelMac pin (30k at 25 tok/s + 800 at 10 → 1,280 s expected, 2,560 s bound, above both floors) is the exact case.

One note, not a condition, so it is written down: the expectation scales with the UNCACHED prompt, and today the prompt cache buys 2 tokens on this box (c119ace7), so the bound here is ~43 minutes — a truly wedged lane is then detected by the slot-progress judgement (L11 / judge_smoke_miss), not by the bound, which is the right division of labour; once the prefix reuses, the same formula shrinks the bound to the tail's size by itself. Nothing to change here; c119ace7 is what makes this bound tight.

@joelteply
joelteply enabled auto-merge (squash) September 20, 2026 21:40
@joelteply
joelteply merged commit a6e4552 into canary Sep 20, 2026
6 checks passed
@joelteply
joelteply deleted the fix/turn-bounds-from-measured-rates branch September 20, 2026 21:47
joelteply added a commit that referenced this pull request Sep 21, 2026
…wedge bound is sized from it, and the "~0.1 s" the probes claimed was the M5's, not a fact (#4287)

Astra (Codex, reading the 5090 log 2026-09-21): "KV save 6835ms + restore
4893ms, despite static log text claiming ~0.1s." Confirmed with the
distribution: 88 switches this session, p50 4,124 ms, p90 6,835 ms, max
10,004 ms. Pages are on the NVMe; on a discrete card a page is VRAM → host →
file, while the "~0.1 s measured" baked into three probe strings was the M5
on unified memory, where the KV already lives in host RAM. On this box, two
residents on one lane pay save + restore ≈ 8–13 s before a token — a cost
the window allocator must weigh against fewer, wider lanes (card 2eec3977).

- The 10 s flat cap on `/slots/{id}?action=` was a wedge detector sized
  from that 0.1 s; max=10,004 ms says it was already cutting a healthy
  switch off here and a 60k page would trip it every time. The bound is now
  the floor (10 s) raised to 3× this node's measured p90 (Fable's #4277
  shape: a constant is a floor, never the bound). `kv_page_switch_ms()`
  exposes (p50, p90, count) for the allocator; the probe carries `ms`,
  `bound_ms` and the node's p50/p90 instead of prose.
- `WaitRing` (resource_admission) reused, made pub — one ring shape for
  every cost a node measures about itself.


Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

Co-authored-by: Claude Opus 5 <[email protected]>
joelteply added a commit that referenced this pull request Sep 21, 2026
… and the act deadline are sized from her measured turn (card ebce2ba0) (#4289)

* fix(cognition): a healthy generation is never dropped — the lane gate and the act deadline are sized from her measured turn, and a drop is a counted outcome (card ebce2ba0)

Measured on the M5, 2026-09-20, from ~/.continuum/fixtures/prompt-captures: of the last
50 submitted generations, 13 completed, 18 CANCELLED, 7 failed — 26% completion. Every
cancel read "request future dropped before a terminal response", the string only
`CaptureLease`'s Drop writes. Their elapsed_ms clustered on EXACT repeated values at
different wall-clock moments: 60,009 | 165,843–165,982 (six) | 412,216–412,346 (four) |
485,151–485,196 (three) | 1,207,290 | 1,228,814 | 1,491,253–1,492,456.

TWO dropping sites, both confirmed at the source:

1. `cognition/llm_deliberation_faculty.rs` — the `CaptureLease` is created at :1117,
   BEFORE the serving-lane gate, and the gate's `return None` (:1362) drops it. Those
   turns never reached the model. Proven by wall-clock: `delib.gate.lane_wait
   bound_secs=165 lane_hold_p50_ms=82918 queue_ahead=0 lanes_serving=2` fired SIX times
   and each cancel's submitted_at sits 1–16 ms from its probe, with elapsed == the bound.
   The bound is `lane_wait_bound` (rounds x lane_hold_p50 x SLACK, clamped): a median
   over TWO recorded lane holds, deciding how long a mind waits while the lanes were
   holding 4–7 minutes. It explains 60,009 (LANE_WAIT_FLOOR), ~165.9 s, ~412.2 s, ~485.2 s.
   NOT #4277's `from_expectation` used as a ceiling — that derivation was never consulted
   here at all.
2. `cognition/act_observe/settle.rs:565` — `timeout_at(tick_deadline, settle_step(...))`
   with a flat 25-minute `TICK_DEADLINE`, dropping the whole act future (and the
   generation inside it) mid-flight. Explains 1,207,290 / 1,228,814 / 1,491,253 /
   1,492,283 / 1,492,456 — the deadline, less how far into the act the call started.

THE FIX — the constant is a FLOOR, her measured turn is the bound:
- The gate takes `effective_bound(queue_estimate, from_expectation(expected_occupancy))`.
- The act takes `act_bound_with_source(TICK_DEADLINE, expected_occupancy)` = two turn
  bounds (a lane wait plus the generation after it), so the gate always trips first.

THE SAFEGUARDS:
- `cognition/generation_drop.rs` — `InFlight` is armed around the model call. A drop
  probes `persona.generation.dropped` with the bound, its source, the expectation behind
  it, elapsed, and the partial: answer chars, reasoning chars, prefill progress, and the
  COMPLETE tool calls thrown away (salvaged by holding the streaming receiver the
  non-observing path used to discard). It reports them; Drop is sync and the settle loop
  is being torn down, so there is no seam to execute them.
- `note_generation_outcome` counts both halves; the hour line carries `dropped N of M (P%)`
  beside acts / lane-starved / think-only, via its own `snapshot_generations_and_reset`.
- `Verdict::Dropping` outranks READING above 10%: 36% thrown away is a broken pipe, and it
  rendered as "READING: n acts, no writes" — which blames the citizens.
- A never-dispatched abandon now names itself in the capture (`CaptureLease::abandon`)
  instead of writing the same generic string a real in-flight drop writes.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* docs(settle): TICK_DEADLINE is a FLOOR now — record the stall-watchdog boundary it creates

The detached solve's ACT_STALL_ALLOWANCE reads the CONSTANT (3x), so a box whose
measured turn passes ~19 min would derive an act bound above the 75-minute stall
allowance. No box in the fleet's measured range is there; the attempt ceiling fires
first on one that slow; making the watchdog per-persona is a solve.rs change with its
own required-read. Recorded at the seam rather than half-fixed.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* test(admission): the ceiling clamps the QUEUE'S estimate, not the WAIT — fix the case's arithmetic

CI caught my own test, not the code: lane_wait_bound(7, 1, 300_000, 30) computes 4,800 s
and returns the 600 s LANE_WAIT_CEILING, so it was never the larger of the two. The
corrected case asserts the more valuable fact — her 848 s measured turn rides ABOVE that
clamp (a constant may raise a wait and never shorten one) — and takes a genuinely deeper
queue (480 s) against a one-minute turn for the queue-wins direction.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

---------

Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant