Skip to content

Improve docs - #662

Merged
Ying1123 merged 3 commits into
mainfrom
docs
Jul 19, 2024
Merged

Ying1123 merged 3 commits into
mainfrom
docs

Conversation

@Ying1123

Copy link
Copy Markdown
Contributor

No description provided.

@Ying1123
Ying1123 merged commit e87c7fd into main Jul 19, 2024
@Ying1123
Ying1123 deleted the docs branch July 19, 2024 18:11
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
amote-i pushed a commit to amote-i/sglang that referenced this pull request Dec 8, 2025
* support tp-sp on qwen2/3 & deepseek v2/3

* support tp-sp on qwen2/3 & deepseek v2/3
cherryblo added a commit to cherryblo/sglang-project that referenced this pull request Jul 2, 2026
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…cal backing

The relief rung disqualified itself for the life of the process after one
shrink that returned no driver bytes, and thereafter declined every ask on
both legs while its own trace reported 170368 rows of slack. Measured on
metal 2026-08-15: the tp_to_pp seam abandoned nine times for want of ~500
MiB and the instance never reached the prefill layout again.

The zero was not the arena refusing. It was a shrink of a pool that had no
pages left to release.

`_current_rows` read `full_pool_backed_rows`, whose name promises a
measurement and which returns `full_kv_pool.size` -- a CONFIGURED row count.
That agreed with the backing for as long as the sgl-project#330 dial was the only
writer, because the dial sets `size` on every step. The phase flip is not the
dial: `release_backing` / `restore_backing` unmap and remap the pages and
state in their own comment that "SIZING IS NOT TOUCHED". So for the whole of
the TP phase the PP layout's pool holds no committed extents while `size`
still reports its pre-flip count, and every number the rung derived from it
was fiction -- including the slack it went on to refuse.

Two changes, in the order the defect runs:

* `_current_rows` asks the arena. `backed_bytes` is the reading the boot's
  own exclusive-backing pin asserts on, and it cannot report backing that is
  not mapped. Pools that do not expose it fall back exactly as before, so a
  boot without the flip is unchanged.

* exhaustion is keyed to the backing LEVEL it was observed at, not to the
  process. It expires when the backing moves, and seeing an emptied layout
  retires it outright -- the level a layout returns at can equal the level a
  failed shrink left behind, so comparing levels alone would let the latch
  survive a whole phase in a level-shaped disguise.

`_exhausted` keeps its boolean spelling through a property, so every existing
reader and the tests that arrange the state are unchanged in meaning: a rung
that paid nothing is still not asked twice AT THE SAME LEVEL. What it never
meant, and what cost the prefill layout, is that it may never be asked again.

Tests: test_kv_backing_exhaustion_662_f4.py, 10 hermetic cases. Verified RED
against the parent commit -- 4 fail there with the defect's own signatures
(backed rows 4000 instead of 0; a phantom shrink proposal where the fixed
rung abstains; the rung never asking again; the latch surviving). 105 pass
with the fix, including the whole existing relief, collective and cap-agreement
suites unchanged.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
… law, not make it

This is where the ~12.7 GiB of idle VRAM comes from, and it is not a
mis-measurement: the sizer is doing exactly what it was told.

`measure_and_record` prices the seam's fund as

    have = max(0, free_bytes - law)

i.e. free VRAM above the corridor law and nothing else, and
`seam_allowed_tokens` then cuts the id space until that idle VRAM covers the
seam. Since `have(T) = have_m + (t_m - T) * cell`, a cut below the measured
position does not find memory anywhere -- it CONVERTS KV pool into free VRAM
and holds it there for the life of the instance.

Measured on this rig 2026-08-15, one configuration, two boots:

    t_m = 590000, have_m = 0 MiB spendable  ->  solved 486403
    at-rest NVML free per card: 1139 / 1462 / 2279  ->  3153 / 4604 / 3977

The instance was ON the corridor law and the reserve moved every card ~2 GiB
above it to guarantee a seam at an occupancy the shrunken pool could no longer
reach. The corridor law has two halves -- ~1024 MiB free per card AND
best-filled -- and 2 GiB too much free is the same defect as too little,
because those bytes buy no tokens and serve no request.

Whether that trade may be made depends on WHAT A REFUSED SEAM COSTS, which is
a consequence of the purity mode and not a knob of its own:

* strict: a refused tp_to_pp means prefill never runs. That is boot E, which
  held the corridor with zero breaches and served nothing. The pool pays, and
  this path is byte-identical to before -- the boot-E/G pin is untouched and
  still passes.
* prefill_in_tp: the TP layout may do the prefill, so the refusal costs one
  flip -- free, unanimous, every request intact -- while the bytes bought with
  the cut are gone for the whole boot. The corridor law wins, and the reserve
  is bounded to the slack that actually sits above it.

`ModelRunner._seam_adjusted_budget` derives the flag from
`purity_from_server_args(...).prefill_allowed_in_tp()`. No environment
variable and no separate setting: sizing follows from the boot's own
configuration.

Tests: five cases appended to test_phase_flip_seam_reserve.py, including the
measured on-the-law position (0 MiB spendable must not move the id space at
all) and the unchanged fatal case. 18 pass; the four new ones fail against the
parent commit. The 13 unrelated failures under test/registered/unit/managers
were verified identical against the parent commit.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…ge on the pool

The seam's cost lasts for a cutover. The pool it was subtracted from lasts
for the boot. The measured record on this rig shows the shape: the ADDITIVE
arena tail alone is 854 MiB on rank1 and 1527 MiB on rank2, held free for the
life of the instance so that a ~2 s cutover can re-commit the weights-arena
tail. Together with the draft restore, the margin and the corridor law that
is most of the ~11.5 GiB this rig keeps idle.

Where a refused seam is FATAL -- strict purity, where prefill only runs in PP
-- the trade is still correct and is made exactly as before (boot E). Where
the other layout can do the work, the bytes belong AT THE SEAM, from the KV
relief rung, which returns unoccupied backing and takes it back after the
cutover. That funder only became able to pay in 997ccac: before it, the
rung read a configured row count as physical backing and disqualified itself
for the process on the first zero it produced.

So under a survivable refusal the reserve is ADVISORY: it still runs the
solve and still reports what a flip needs, and it charges the pool nothing.

Tests: 29 pass across the seam-reserve and margin suites, including the
unchanged fatal case.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…ent charge on the pool"

Falsified on metal within one boot, 2026-08-15.

With the seam charged nothing, the pool took the full 590000 tokens and the
instance reached READY with the corridor exactly where it should be --
1139 / 1462 / 2279 MiB free, no breach. Then the first load burst killed it:

    cuMemCreate: committing 8388608 bytes would leave 504 MiB free, below
    the 1024 MiB corridor law floor ... (PP1, repeatedly, down to 476 MiB)
    Scheduler hit an exception: RuntimeError: Out of memory. Try to lower
    your batch size.          (PP0, PP1 and PP2, within 30 s)

The reasoning was that a refused seam under prefill_in_tp costs one flip and
is therefore not worth a boot-long charge. The measurement says the premise
is wrong in its most important clause: the flip does not politely refuse. It
ARMS -- it is an optimisation the policy is free to take -- and then commits
the weights-arena tail that nothing is holding memory for any more. The
commit is what runs the card out, and it takes every rank with it.

So the seam reserve is not only paying for a flip that might not happen. At
this pool size it is also the term that keeps the instance alive under load,
and removing it produces exactly the failure this module was written for: an
instance that answers /health and serves nothing.

What survives from that commit: nothing in code. What survives as knowledge
is in this message and in the evidence note -- the ~11.5 GiB this rig holds
idle is NOT all waste, and any future attempt to reclaim it has to make the
seam funded at flip time FIRST (the sgl-project#662 relief path), and only then lower
the reserve. Lowering the reserve on the argument that the flip is optional
is falsified.

The two commits under this one stand and are unaffected: 997ccac (the rung
read a configured row count as physical backing) and 9768e65 (the reserve
may spend slack above the corridor law, not manufacture it).
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…not the one that is not

The rung was bound to one pool for the life of the process and the flip has
two. The scheduler's KV pool is the PP layout's, so on the pp_to_tp leg the
rung is looking at the SOURCE -- backed, with slack above the live set, able
to pay. On the tp_to_pp leg the same pool is the DESTINATION, and the seam
emptied it a phase earlier: no extents, nothing to release, and every
proposal it makes is arithmetic over memory that is not mapped.

That is why the leg into the prefill layout still had no funder after
d210158 lifted the one-leg exclusion. Lifting the exclusion let the rung be
CONSULTED on that leg; it could not make it able to PAY there.

The money on that leg is in the TP layout's pool. It is the source, it is
fully backed, and the rows above its live high-water mark hold nothing. The
seam was going to release that whole layout at the cutover anyway, so
releasing its unoccupied tail at the gate is the same memory arriving in time
to be useful instead of one gate too late.

So the pool is resolved per call, from `phase_flip_active_stack`, and falls
back to the scheduler's own pool whenever the answer is not unambiguous --
no stacks, an unrecognised phase, a missing worker -- which reproduces the
previous behaviour exactly.

WHAT DOES NOT MOVE WITH IT:

* the cap and the id space. Both layouts index the same allocator, so a target
  is a row id and means the same thing in either pool. `_reservation_rows`
  reads the id-space owner, so `exposed_rows` and the collective cap agreement
  cannot start depending on which phase a rank happens to be in -- that is the
  capacity desync of HANDOFF_675 1a.
* geometry, the boot reservation and the exhaustion marker. All three are
  facts about ONE arena and are carried per pool: a futile shrink of one
  layout must not silence the other.

Entering TP now recovers as entering PP already did. Without that the
reduction is a ratchet -- the seam restores each layout to its own `size`,
which the shrink lowered -- so the TP pool would come back smaller after every
tp_to_pp and never climb. The grow is corridor-bounded inside `recover`.

Tests: six cases appended to test_kv_backing_exhaustion_662_f4.py, all six red
against the parent commit. 129 pass across the relief, collective,
cap-agreement, evictable-fund and seam-reserve suites.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…ed by the fixed floor

`measure_and_record` priced the seam's fund as free VRAM above the corridor
law and nothing else, so the pool was cut until enough VRAM sat idle to cover
a cutover. That subtraction is the ~12.7 GiB this ticket exists to remove.

Free VRAM is no longer the only thing that can pay. The KV relief rung returns
unoccupied backing at the seam and takes it back after the cutover -- bytes
arriving exactly when the commit needs them -- and as of 7312950 it does
that from the layout that is actually resident, so it can pay on both legs.
Proven on metal the same hour: tp_to_pp DONE 15, pp_to_tp DONE 18, ABANDONED
0, no exhausted-arena trace, 8/8 requests, zero corridor breaches.

THE BOUND IS THE DESIGN. The rung's honest capacity is everything above the
live high-water mark, which at rest is nearly the whole pool; sizing against
that would grow the id space without limit and then fail under a live set the
measurement never saw. So it may cover at most the seam's FIXED floor -- the
weights-arena tail plus the drafter's restore, one-shot commits at the cutover,
and on this rig the dominant term (854 MiB and 1456 MiB of arena tail on the
two 3080 ranks). The per-row slack stays charged to the pool: it is held
across the whole wave walk and scales with the very pool this would be
growing, which is the shape that runs away.

Returns 0 whenever the rung cannot answer -- no relief object, an unreadable
bound, a pool that cannot release. Zero reproduces the previous sizing
exactly, which is the direction a term that GROWS a pool has to fail in, and
it is the can-fail arm: with nothing able to pay at the seam, the reserve
charges what it always charged.

This is deliberately not the reverted advisory (738fa90). That one removed
the charge while nothing had replaced it, and the instance reached READY at
the wanted corridor and then died -- the flip arms, commits the arena tail,
and takes every rank with it. Here the charge is reduced by exactly what a
named funder has been measured to provide, and by nothing else.

Tests: six cases in test_phase_flip_seam_reserve.py covering the bound, the
partial grant, the can-fail arm and the arithmetic effect. 24 pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
… not exist yet

Fixes an ordering defect in 0c9048b, found by reading its own absent log
line on the first metal boot.

That commit asked `scheduler.phase_flip_kv_backing_relief` for its fundable
bytes at seam-measurement time. The relief is installed at the first corridor
gate, which is later than BOTH the pool sizing and the measurement -- on this
rig the MEASURED line sits five lines above "KV backing relief is available"
in the same millisecond. So the lookup returned None every time, the term
granted zero, and the whole change was silently inert. A term that is quietly
zero is worse than one that is absent, because the log looks correct.

The question that can be answered at that point is not "how much can this
object return" but "will there be a rung able to return anything", and that is
decidable from configuration: the env switch, an allocator, a pool with
`runtime_set_backing_rows`, a chunked arena, readable row geometry. Those are
exactly `kv_backing_provider`'s own disqualifiers, so they are written once in
`kv_backing_relief.rung_can_pay` and asked from here -- re-deriving them in the
sizer would be a second source of truth for "can this rung pay" and the two
would drift.

The amount stays what it was and is decided by the caller: at most the seam's
FIXED floor, the weights-arena tail plus the drafter's restore, which are
one-shot commits at the cutover -- the moment the rung releases rows and the
moment it takes them back. The per-row slack stays charged to the pool
because it is held across the whole wave walk and scales with the pool this
term would grow.

Can-fail arm is now a real one: `SGLANG_KV_BACKING_RELIEF=0` makes
`rung_can_pay` false, the floor stays charged, and the sizing is byte-identical
to before. A chunkless arena does the same, which matters because such an
arena cannot return anything to the driver and a pool sized on that promise
would be sized on a promise nothing keeps.

Tests: five cases on the predicate path replacing the five that asked a live
object, plus the unchanged arithmetic case. 135 pass across the seam-reserve,
relief, collective, cap-agreement and evictable-fund suites.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…erved by default

Two bugs, and the second is only reachable because of the first.

1. THE AUDIT NEVER RAN. `corridor_trace.start()` returned None unless
   SGLANG_CORRIDOR_TRACE_MS was set, so on a default boot the tree's only
   continuous corridor instrument never armed. Everything downstream is fed
   from it: `Scheduler._corridor_trace_tick` reports a breach only if a trace
   exists, and `record_corridor_shortfall` only ever writes a number that
   report produced. So `corridor_shortfall_bytes` stayed 0 for ever,
   `seam_margin_bytes` stayed at its constant, and the pool sizer's fixed
   point had nothing pulling it back above the law.

   Measured here 2026-08-15 across two boots: an external 100 ms NVML sampler
   recorded 57 and 15 breaches with minima of 895 and 935 MiB, while
   "CORRIDOR LAW BREACHED on this rank's card" appeared ZERO times in either
   serving log. The instance believed it was holding the law throughout.

   The default flips. The cost it was avoiding is one daemon thread reading
   NVML every 100 ms, which is not a price worth a law nobody can see.
   SGLANG_CORRIDOR_TRACE_MS=0 (or "off") still disarms it -- and note the old
   parser treated "0" as truthy and armed anyway, so the documented escape
   hatch did not work either.

2. THE GATE ARMED ON AN ALLOWANCE, NOT A MEASUREMENT. `arming_floor_mib`
   states that its reserve is "the MEASURED draw a seam makes while it runs,
   where a measurement exists; the default is the shipped allowance" -- and
   nothing ever passed the measurement, though the seam reserve had been
   measuring and persisting exactly that number all along.

   On this rig the recorded fixed draw is 954 MiB (rank1) and 1595 MiB
   (rank2), against a gate arming at 1024 + 512 = 1536. gpu0 reached 935 MiB
   at the `weights_refill` stage with every allocation having cleared the
   gate: the breach lived precisely in the gap between 1536 and 1024 + 954,
   which is the gap the threshold-pair line predicts in words and the audit
   predicts in its own text ("the arming floor is the number to re-derive").

   The floor is now derived from this rank's recorded draw, and HIGHEST WINS:
   a configured value may raise the derived floor and may not lower it,
   because a raised floor only over-reclaims while a floor below the real draw
   launders breaches as passed checks.

Tests: the two "off by default" pins are INVERTED rather than deleted, with
the measurement that falsified them in the class docstring; three new cases
walk the whole chain trace -> summary -> report -> record, because pinning the
arming alone left three of four links uncovered, which is how this stayed dead
with green unit tests; seven cases on the measured-draw derivation including
the arithmetic of the breach. 508 pass across mem_ledger, the threshold pair,
the seam reserve and the F4 suites. Six of the new cases fail against the
parent commit.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
Operator relaxation, 2026-08-15: the ~1024 MiB free per card may be over- or
undershot by ~20 %, wherever that makes the solve or the boot-time gate
simpler.

It makes both simpler for the same reason: a solve that has to land on a point
has no feasible region and one that has to land in a band does. Three things
follow, and they are deliberately not the same threshold:

* THE VERDICT is the band FLOOR (819 MiB at the shipped law). Below it is a
  breach; nothing inside the band is. The cutover transient this rig has been
  chasing bottomed at 895-935 MiB on gpu0 at the `weights_refill` stage, so
  that class is inside the band and stops being a defect.
* THE TARGET is the CENTRE. `margin_mib` is still measured to it, because the
  self-correcting sizing pulls back to it and a mechanism that aims at the
  edge of its own tolerance has none left. The summary now reports the band
  floor alongside the margin so the two questions -- "did the law hold" and
  "how far from the target" -- can never be read as one number.
* THE GATE arms from the band floor plus the seam's measured draw. Arming from
  the centre would reserve the whole tolerance on top of the draw on every
  card of every boot -- about 205 MiB per rank here -- to defend a threshold
  that is not the verdict.

`corridor_band_floor_mib` / `_ceiling_mib` / `_mib` are the one declaration,
next to the law they derive from, so the tolerance cannot drift between the
instrument and the gate. The trace derives its band from the corridor centre
it is GIVEN rather than the global, so an explicit `corridor_mib` still
decides the verdict -- that parameter exists so a caller can audit against
another corridor, and a band read from the global would have silently ignored
it (caught by the pin that exists for exactly that).

Five existing pins are restated rather than deleted, each carrying the
measurement that moved it: the single-trough case now pins the property one
trough deeper (a sample BELOW THE BAND is still a breach, and the mean is
still not the law). 469 pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…ary work may not

Measured by F1's GATE C on the combined boot, 2026-08-15, device 0:

    staging 1059 MiB needed but only 1000 MiB is spendable
    (driver free 2024 MiB, allocator cache 100 MiB, reserve 1024 MiB kept free)
    ... tp_to_pp REFUSED 8 times consecutively and is being treated as
    unfundable

Refused by 59 MiB. The direction then latched and the instance held in TP with
50k+ tokens pending at 1000-1600 tok/s, where the PP layout does 4000-7000 --
the exact outcome this strand exists to remove, reached by a gate doing
arithmetic nobody had revisited since the corridor became a band.

The corridor is 1024 MiB +-20 % and the verdict is the continuous minimum
against the FLOOR. A cutover that dips to 819 MiB for the length of a wave
walk is therefore lawful -- that tolerance is the whole reason the band was
granted. Holding the CENTRE as a hard reserve through staging spends it on
nothing: at the refused instant the floor offers 2024 - 819 = 1205 MiB
against a 1059 MiB need, with 146 MiB to spare.

SCOPED TO THE SEAM, and the scope is the argument. This is the STAGING
reserve, not the corridor law. Every ordinary allocation is still judged
against the centre by `corridor_guard`; only the cutover may reach into the
tolerance, and a cutover is bounded, unanimous and over in seconds. The value
is derived from `CORRIDOR_BAND_FRACTION` rather than typed, so the seam cannot
drift away from the band the operator declared, and it can never exceed the
user's own reserve -- a tolerance that made the reserve LARGER would be a
refusal machine.

Falls back to the plain reserve if the band cannot be read: a seam that
reserves too much refuses a flip, one that reserves too little breaches the
law it exists to respect, so the fallback goes the refusing way.

Tests replay the GATE C instant as arithmetic, including the 146 MiB margin so
a later change that eats it is visible rather than silent. 532 pass across the
seam, corridor, enforcement and F4 suites.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…ary work may not

Measured by F1's GATE C on the combined boot, 2026-08-15, device 0:

    staging 1059 MiB needed but only 1000 MiB is spendable
    (driver free 2024 MiB, allocator cache 100 MiB, reserve 1024 MiB kept free)
    ... tp_to_pp REFUSED 8 times consecutively and is being treated as
    unfundable

Refused by 59 MiB. The direction then latched and the instance held in TP with
50k+ tokens pending at 1000-1600 tok/s, where the PP layout does 4000-7000 --
the exact outcome this strand exists to remove, reached by a gate doing
arithmetic nobody had revisited since the corridor became a band.

The corridor is 1024 MiB +-20 % and the verdict is the continuous minimum
against the FLOOR. A cutover that dips to 819 MiB for the length of a wave
walk is therefore lawful -- that tolerance is the whole reason the band was
granted. Holding the CENTRE as a hard reserve through staging spends it on
nothing: at the refused instant the floor offers 2024 - 819 = 1205 MiB
against a 1059 MiB need, with 146 MiB to spare.

SCOPED TO THE SEAM, and the scope is the argument. This is the STAGING
reserve, not the corridor law. Every ordinary allocation is still judged
against the centre by `corridor_guard`; only the cutover may reach into the
tolerance, and a cutover is bounded, unanimous and over in seconds. The value
is derived from `CORRIDOR_BAND_FRACTION` rather than typed, so the seam cannot
drift away from the band the operator declared, and it can never exceed the
user's own reserve -- a tolerance that made the reserve LARGER would be a
refusal machine.

Falls back to the plain reserve if the band cannot be read: a seam that
reserves too much refuses a flip, one that reserves too little breaches the
law it exists to respect, so the fallback goes the refusing way.

Tests replay the GATE C instant as arithmetic, including the 146 MiB margin so
a later change that eats it is visible rather than silent. 532 pass across the
seam, corridor, enforcement and F4 suites.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…wo criteria

I caused this collision and the causal chain is worth stating plainly.
Deriving the gate's arming floor from the band recovered ~205 MiB per rank;
that went into pool; device 0's under-load free fell from ~2.5 GiB to
~1.9-2.0 GiB; and the seam's 1059 MiB staging then missed by 59 MiB and
latched the direction "unfundable", holding the instance in TP with 50k+
pending at 1000-1600 tok/s where the PP layout does 4000-7000. The earlier
boot flipped BECAUSE its pool was smaller. Pool-fill maximisation and seam
fundability were being maximised as SEPARATE criteria, so every pool gain came
out of the seam's margin until one of them missed.

The runtime half was fixed in 5658c96: the seam spends to the band floor,
since a cutover dip to 819 MiB is lawful against a verdict stated as the
continuous minimum. That closes the measured 59 MiB, and it is not enough on
its own -- it just moves the collision to the next pool gain.

This is the durable half. The seam's demand becomes a TERM IN THE POOL SOLVE
rather than something the flip discovers at runtime: sizing subtracts the band
FLOOR where it used to subtract the law CENTRE, so the solve reserves exactly
`band_floor + seam_draw`. At the solved id space the resting free column is
the floor plus what a cutover draws; the dip bottoms out AT the floor, which
is lawful; and any memory a future change recovers is spendable only above
that sum instead of out of it.

Sizing and the runtime gate now read the SAME number from the same
declaration, and their disagreement was the defect -- sizing kept 1024 while
the gate spent to 819, which is precisely the gap a pool gain could hide in.
Both round in MiB before converting, so they cannot differ by a fifth of a
MiB either.

Provenance of the reserved quantity is now SOLVED rather than discovered.

Tests pin the joint constraint directly, including the regression it exists to
prevent: a 205 MiB pool gain applied on top must still leave the seam funded.
501 pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…wo criteria

I caused this collision and the causal chain is worth stating plainly.
Deriving the gate's arming floor from the band recovered ~205 MiB per rank;
that went into pool; device 0's under-load free fell from ~2.5 GiB to
~1.9-2.0 GiB; and the seam's 1059 MiB staging then missed by 59 MiB and
latched the direction "unfundable", holding the instance in TP with 50k+
pending at 1000-1600 tok/s where the PP layout does 4000-7000. The earlier
boot flipped BECAUSE its pool was smaller. Pool-fill maximisation and seam
fundability were being maximised as SEPARATE criteria, so every pool gain came
out of the seam's margin until one of them missed.

The runtime half was fixed in 5658c96: the seam spends to the band floor,
since a cutover dip to 819 MiB is lawful against a verdict stated as the
continuous minimum. That closes the measured 59 MiB, and it is not enough on
its own -- it just moves the collision to the next pool gain.

This is the durable half. The seam's demand becomes a TERM IN THE POOL SOLVE
rather than something the flip discovers at runtime: sizing subtracts the band
FLOOR where it used to subtract the law CENTRE, so the solve reserves exactly
`band_floor + seam_draw`. At the solved id space the resting free column is
the floor plus what a cutover draws; the dip bottoms out AT the floor, which
is lawful; and any memory a future change recovers is spendable only above
that sum instead of out of it.

Sizing and the runtime gate now read the SAME number from the same
declaration, and their disagreement was the defect -- sizing kept 1024 while
the gate spent to 819, which is precisely the gap a pool gain could hide in.
Both round in MiB before converting, so they cannot differ by a fifth of a
MiB either.

Provenance of the reserved quantity is now SOLVED rather than discovered.

Tests pin the joint constraint directly, including the regression it exists to
prevent: a 205 MiB pool gain applied on top must still leave the seam funded.
501 pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
Three changes, all aimed at one measured failure: tp_to_pp refused for want of
a few hundred MiB while tens of thousands of tokens sat pending, then declared
unfundable, holding the instance in TP at 1000-1600 tok/s where the PP layout
does 4000-7000.

1. THE RUNG WAS ASKED AND DECLINED, EVERY TIME, FOR AN ARITHMETIC REASON.
   `_cached_relief_estimate` returned `reserved - allocated`, an upper bound
   on what `empty_cache` really hands back, and that number was SUBTRACTED
   from the rung's deficit. The rung's own trace had already recorded the
   consequence: the deficit was NEGATIVE on 100 % of arms across two
   acceptance runs, and dropping this term alone flipped every one positive by
   260-832 MiB. So the only rung that can pay real bytes declined on every
   arm, and the guard then found the ~100 MiB the cheap tier actually had.

   The cheap tier is now TAKEN before the rung is asked, and the ask is sized
   against what the driver actually has. The reclaimed bytes land in the free
   column the rung probes, so the function returns 0 -- subtracting them a
   second time was the double-count.

   The old behaviour was justified as "under-shrinking is retried while
   over-shrinking costs admission capacity". Under-shrinking is not retried:
   it latches unfundable and costs the whole prefill layout. The trade-off was
   right about the costs and wrong about which one occurs.

2. THE BACKOFF WAS THE DEFECT WITH A TIMER ON IT. Reaching the hold means
   `_decide_from_load` has already said this load wants the other layout, so
   the arming condition PERSISTS -- and waiting frees no memory. While the
   condition holds, attempts are now paced at the plain dwell instead of a
   doubling backoff, and a degrade latch no longer vetoes: each attempt runs
   the gate, which asks the rung, which can now pay. The exponential backoff
   and the latch survive for the case they were written for, a load that has
   stopped wanting the flip, where this branch is never reached.

3. A REFUSAL NOW SAYS WHAT THE RUNG DECIDED. The proposal trace is
   edge-triggered on the deficit's sign, so at a refusal -- which is not an
   edge -- it is silent, and a silent decline is indistinguishable from a rung
   that never ran. That cost me a wrong diagnosis today: I read five minutes
   of silence as "never consulted" and went looking for a missing call that
   did not exist. The terms are now retained whether or not they are logged,
   and the refusal message carries them.

Tests: four cases pinning that a refusal can tell "declined", "abstained" and
"never reached" apart. 99 phase-policy tests pass; the seam, corridor,
enforcement and F4 suites pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
The policy's backoff was replaced with dwell-paced retry while the arming
condition persists, and the seam's own group-abandon counter then vetoed the
retry anyway -- so the KV rung was still never reached. Measured: PP0 printed
'the load still wants this layout, so the next attempt is in 0.2s and it will
ask the KV rung again', and the very next arm was declined with '5 consecutive
group abandons, next entry at arm 38 (this is arm 26)'.

While work is still waiting, the counter now stands down, for the same reason
the policy hold did: waiting frees no memory, and the full pool is what funds
the seam once the rung is asked. The counter is kept and still counts -- it is
the right damper for its actual case, an arming condition that has GONE AWAY,
where the bypass is false and the skip applies exactly as before.

_arming_condition_persists is deliberately coarse (any queued request). The
policy has already decided which layout the load wants; this only separates
'the load is still there' from 'the load has gone away', which is the one
distinction the counter needed and never had. Unreadable queue returns False,
so it can never disable the damper by accident.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
Three changes, all aimed at one measured failure: tp_to_pp refused for want of
a few hundred MiB while tens of thousands of tokens sat pending, then declared
unfundable, holding the instance in TP at 1000-1600 tok/s where the PP layout
does 4000-7000.

1. THE RUNG WAS ASKED AND DECLINED, EVERY TIME, FOR AN ARITHMETIC REASON.
   `_cached_relief_estimate` returned `reserved - allocated`, an upper bound
   on what `empty_cache` really hands back, and that number was SUBTRACTED
   from the rung's deficit. The rung's own trace had already recorded the
   consequence: the deficit was NEGATIVE on 100 % of arms across two
   acceptance runs, and dropping this term alone flipped every one positive by
   260-832 MiB. So the only rung that can pay real bytes declined on every
   arm, and the guard then found the ~100 MiB the cheap tier actually had.

   The cheap tier is now TAKEN before the rung is asked, and the ask is sized
   against what the driver actually has. The reclaimed bytes land in the free
   column the rung probes, so the function returns 0 -- subtracting them a
   second time was the double-count.

   The old behaviour was justified as "under-shrinking is retried while
   over-shrinking costs admission capacity". Under-shrinking is not retried:
   it latches unfundable and costs the whole prefill layout. The trade-off was
   right about the costs and wrong about which one occurs.

2. THE BACKOFF WAS THE DEFECT WITH A TIMER ON IT. Reaching the hold means
   `_decide_from_load` has already said this load wants the other layout, so
   the arming condition PERSISTS -- and waiting frees no memory. While the
   condition holds, attempts are now paced at the plain dwell instead of a
   doubling backoff, and a degrade latch no longer vetoes: each attempt runs
   the gate, which asks the rung, which can now pay. The exponential backoff
   and the latch survive for the case they were written for, a load that has
   stopped wanting the flip, where this branch is never reached.

3. A REFUSAL NOW SAYS WHAT THE RUNG DECIDED. The proposal trace is
   edge-triggered on the deficit's sign, so at a refusal -- which is not an
   edge -- it is silent, and a silent decline is indistinguishable from a rung
   that never ran. That cost me a wrong diagnosis today: I read five minutes
   of silence as "never consulted" and went looking for a missing call that
   did not exist. The terms are now retained whether or not they are logged,
   and the refusal message carries them.

Tests: four cases pinning that a refusal can tell "declined", "abstained" and
"never reached" apart. 99 phase-policy tests pass; the seam, corridor,
enforcement and F4 suites pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
The policy's backoff was replaced with dwell-paced retry while the arming
condition persists, and the seam's own group-abandon counter then vetoed the
retry anyway -- so the KV rung was still never reached. Measured: PP0 printed
'the load still wants this layout, so the next attempt is in 0.2s and it will
ask the KV rung again', and the very next arm was declined with '5 consecutive
group abandons, next entry at arm 38 (this is arm 26)'.

While work is still waiting, the counter now stands down, for the same reason
the policy hold did: waiting frees no memory, and the full pool is what funds
the seam once the rung is asked. The counter is kept and still counts -- it is
the right damper for its actual case, an arming condition that has GONE AWAY,
where the bypass is false and the skip applies exactly as before.

_arming_condition_persists is deliberately coarse (any queued request). The
policy has already decided which layout the load wants; this only separates
'the load is still there' from 'the load has gone away', which is the one
distinction the counter needed and never had. Unreadable queue returns False,
so it can never disable the damper by accident.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
Caught on metal at 12:16:47 with 77k tokens pending and no flip. The backoff
stood down correctly, the rung was asked on all three ranks, and all three
declined in the same second with the corridor gate then reporting
"free 1818 -> 1818 MiB, reclaimed 0 MiB from [nothing]".

Not an ordering race. Every proposal printed "against free -0 MiB", which is
the skip sentinel: the rung never priced anything. The cause is the marker I
added in 997ccac to replace the process-lifetime latch.

A SHRINK THAT RELEASES NOTHING LEAVES THE PHYSICAL LEVEL WHERE IT WAS. So a
marker keyed only to the level marks the level the rung is stuck at, and the
only thing that could move it is a successful shrink -- which the marker now
prevents. A shrink to 94955 rows returned no driver bytes at 12:16:00; 47
seconds later all three ranks were still declining, at an unchanged level,
with 72981 rows of slack in front of them. The process-lifetime latch was
replaced by one that self-locks, which is no better.

The fix is the half of the original design I did not implement: exhaustion is
keyed to the TARGET as well as the level. "A shrink to X returned nothing"
says nothing about a shrink deeper than X -- release is extent-granular, so a
deeper ask clears extents a shallower one cannot, which is the same argument
the granularity rounding in free_up_to already makes. `_declines_target` holds
only while the ask is no deeper than the failed one by a release granularity.

The deficit is now also computed BEFORE exhaustion is consulted. It had to be:
short-circuiting first meant the rung could not tell how deep an ask it was
refusing, which is exactly what made the level-keyed marker unable to expire.
Pricing first costs one free-memory probe and makes the refusal answerable --
and it removes the "against free -0 MiB" sentinel from the trace, which was
the diagnostic that told me the deficit had never been computed.

Tests: a class pinning the deadlock directly, including an arena that clears
no extent at all (the metal shape -- the existing fake models the
retain-handles variant, where the backing moves and only the driver's column
does not). One trace pin restated: it still refuses to blame the cheap tier
and now names the failed target, and it needs a TIGHT card, because with
plenty free the deficit is negative and the cheap tier IS the honest answer.
115 pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…tands down

Two defects, both caught with 92k tokens pending and no flip.

1. THE MARKER REFUSED EVERY SHALLOWER ASK. Keying exhaustion to the failed
   TARGET fixed the level deadlock and introduced a subtler one: the asks that
   follow a failure are always SHALLOWER, because the deficit only ever asks
   for what it needs. Measured 12:26:41: PP1 held 112,126 rows of slack above
   its floor (current 159,744, floor 47,618), priced a real +1009 MiB deficit,
   and still declined -- several GiB releasable behind a marker set earlier
   from a different level. No "SHRINK to" line followed, so the gate then read
   "free 2116 -> 2116, reclaimed 0 MiB from [nothing]".

   The rule the original brief asked for, and that I have now twice failed to
   implement, is "never per process, WHEN SLACK >> NEED". So slack overrides
   the marker: when the rows in front of the rung are at least two release
   granularities deep, one earlier failure stops being decisive. Trying costs
   a cap and a dial call that cannot allocate; not trying costs the prefill
   layout. A chunkless arena is excluded -- there no extent can clear at any
   depth, so slack is not evidence.

2. A THIRD DAMPER, in the guards path. The policy hold and the seam's abandon
   counter both learned to stand down while the arming condition persists;
   `arm()` then refused every entry anyway on "seam unfundable: tp_to_pp
   abandoned 8 times consecutively", so the seam was never re-priced and arms
   climbed 22, 23, 24, 25. Three independent counters guarding one decision is
   how a fix keeps looking wrong after it is right.

   Only the abandon-cap guard stands down, and the distinction is the point:
   it is a statement about AFFORDABILITY, which is exactly what a full pool
   changes. Every other blocking guard states SAFETY -- a half-built stack, a
   missing carrier -- and keeps refusing, because no amount of pending work
   makes those safe.

Tests: three cases on the slack override (shallower-with-room is tried,
no-room still declines, the deeper escape still works) and the chunkless
exclusion. Two pins restated with the reason they moved. 154 pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
Caught on metal at 12:16:47 with 77k tokens pending and no flip. The backoff
stood down correctly, the rung was asked on all three ranks, and all three
declined in the same second with the corridor gate then reporting
"free 1818 -> 1818 MiB, reclaimed 0 MiB from [nothing]".

Not an ordering race. Every proposal printed "against free -0 MiB", which is
the skip sentinel: the rung never priced anything. The cause is the marker I
added in 997ccac to replace the process-lifetime latch.

A SHRINK THAT RELEASES NOTHING LEAVES THE PHYSICAL LEVEL WHERE IT WAS. So a
marker keyed only to the level marks the level the rung is stuck at, and the
only thing that could move it is a successful shrink -- which the marker now
prevents. A shrink to 94955 rows returned no driver bytes at 12:16:00; 47
seconds later all three ranks were still declining, at an unchanged level,
with 72981 rows of slack in front of them. The process-lifetime latch was
replaced by one that self-locks, which is no better.

The fix is the half of the original design I did not implement: exhaustion is
keyed to the TARGET as well as the level. "A shrink to X returned nothing"
says nothing about a shrink deeper than X -- release is extent-granular, so a
deeper ask clears extents a shallower one cannot, which is the same argument
the granularity rounding in free_up_to already makes. `_declines_target` holds
only while the ask is no deeper than the failed one by a release granularity.

The deficit is now also computed BEFORE exhaustion is consulted. It had to be:
short-circuiting first meant the rung could not tell how deep an ask it was
refusing, which is exactly what made the level-keyed marker unable to expire.
Pricing first costs one free-memory probe and makes the refusal answerable --
and it removes the "against free -0 MiB" sentinel from the trace, which was
the diagnostic that told me the deficit had never been computed.

Tests: a class pinning the deadlock directly, including an arena that clears
no extent at all (the metal shape -- the existing fake models the
retain-handles variant, where the backing moves and only the driver's column
does not). One trace pin restated: it still refuses to blame the cheap tier
and now names the failed target, and it needs a TIGHT card, because with
plenty free the deficit is negative and the cheap tier IS the honest answer.
115 pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…tands down

Two defects, both caught with 92k tokens pending and no flip.

1. THE MARKER REFUSED EVERY SHALLOWER ASK. Keying exhaustion to the failed
   TARGET fixed the level deadlock and introduced a subtler one: the asks that
   follow a failure are always SHALLOWER, because the deficit only ever asks
   for what it needs. Measured 12:26:41: PP1 held 112,126 rows of slack above
   its floor (current 159,744, floor 47,618), priced a real +1009 MiB deficit,
   and still declined -- several GiB releasable behind a marker set earlier
   from a different level. No "SHRINK to" line followed, so the gate then read
   "free 2116 -> 2116, reclaimed 0 MiB from [nothing]".

   The rule the original brief asked for, and that I have now twice failed to
   implement, is "never per process, WHEN SLACK >> NEED". So slack overrides
   the marker: when the rows in front of the rung are at least two release
   granularities deep, one earlier failure stops being decisive. Trying costs
   a cap and a dial call that cannot allocate; not trying costs the prefill
   layout. A chunkless arena is excluded -- there no extent can clear at any
   depth, so slack is not evidence.

2. A THIRD DAMPER, in the guards path. The policy hold and the seam's abandon
   counter both learned to stand down while the arming condition persists;
   `arm()` then refused every entry anyway on "seam unfundable: tp_to_pp
   abandoned 8 times consecutively", so the seam was never re-priced and arms
   climbed 22, 23, 24, 25. Three independent counters guarding one decision is
   how a fix keeps looking wrong after it is right.

   Only the abandon-cap guard stands down, and the distinction is the point:
   it is a statement about AFFORDABILITY, which is exactly what a full pool
   changes. Every other blocking guard states SAFETY -- a half-built stack, a
   missing carrier -- and keeps refusing, because no amount of pending work
   makes those safe.

Tests: three cases on the slack override (shallower-with-room is tried,
no-room still declines, the deeper escape still works) and the chunkless
exclusion. Two pins restated with the reason they moved. 154 pass.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…orbidding it

F1's red on my tip is correct: with the three dampers standing down, arms ran
at roughly 20/min, and boot E's pathology was 179 in nine minutes. That is a
storm.

The shape of the protection is the lesson of this whole ticket. Every latch on
this path -- the policy backoff, the seam's own abandon counter, the
guards-layer unfundable flag -- refused to RE-PRICE while the arming condition
persisted, and each one cost the prefill layout at exactly the moment a full
pool could have paid for the flip. So this is a rate limiter and deliberately
not a counter:

* it bounds attempts in TIME, never by a count. However many attempts have
  been made, one interval later the next is allowed -- there is no number of
  refusals after which it stops answering, which is precisely the boot-E
  shape;
* an attempt that made PROGRESS (a completed flip, or a KV release that moved
  the driver) clears the pacing immediately via `note_seam_progress`, so a
  direction that is successfully funding itself is never throttled;
* it is per direction, so a tp_to_pp storm cannot gag pp_to_tp, which is
  staged from the other leg's buffers entirely;
* it applies only where a damper is already standing down, so the ordinary
  path is untouched.

At a 2 s interval a standing-down direction is capped at 30/min in the worst
case, and a funding run is not capped at all.

Tests: seven cases, including the two that state the distinction -- progress
clears the pacing, and no count ever refuses.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…orbidding it

F1's red on my tip is correct: with the three dampers standing down, arms ran
at roughly 20/min, and boot E's pathology was 179 in nine minutes. That is a
storm.

The shape of the protection is the lesson of this whole ticket. Every latch on
this path -- the policy backoff, the seam's own abandon counter, the
guards-layer unfundable flag -- refused to RE-PRICE while the arming condition
persisted, and each one cost the prefill layout at exactly the moment a full
pool could have paid for the flip. So this is a rate limiter and deliberately
not a counter:

* it bounds attempts in TIME, never by a count. However many attempts have
  been made, one interval later the next is allowed -- there is no number of
  refusals after which it stops answering, which is precisely the boot-E
  shape;
* an attempt that made PROGRESS (a completed flip, or a KV release that moved
  the driver) clears the pacing immediately via `note_seam_progress`, so a
  direction that is successfully funding itself is never throttled;
* it is per direction, so a tp_to_pp storm cannot gag pp_to_tp, which is
  staged from the other leg's buffers entirely;
* it applies only where a damper is already standing down, so the ordinary
  path is untouched.

At a 2 s interval a standing-down direction is capped at 30/min in the worst
case, and a funding run is not capped at all.

Tests: seven cases, including the two that state the distinction -- progress
clears the pacing, and no count ever refuses.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…er missed running work

Two desk fixes for F1's next boot cycle. I own neither the metal nor the boot;
these are commits to carry.

1. THE C20 ENTRY-MARGIN ARITHMETIC, answered rather than adjusted. Reported as
   "want 2251 with free 3206 fails a 512 MiB margin -- the arming floor looks
   double-counted". It is neither. The predicate is

       law_ok = margin_bytes > 0 and (free_after - staging >= law_floor)

   `margin_bytes` is an ENABLE FLAG and appears in no comparison; the arming
   floor appears nowhere at all; `law_floor` is `guard.law_floor_bytes`, the
   corridor CENTRE. So the binding arithmetic was 3206 - 2251 = 955 against
   1024 -- short by 69 MiB. Nothing was double-counted and the log named 512,
   a number the comparison never touches, which is why it read as a
   double-count from outside.

   955 is also 136 MiB CLEAR of the band floor at 819. A cutover transient is
   judged against the floor -- that is what the band is for, and the same rule
   as the staging reserve in 5658c96 -- so this flip was legal for the
   whole ~35 s that 21,480 tokens waited for it. Now judged against the seam
   floor, and the delay message names the number that actually bound.

2. THE DAMPER MISSED RUNNING WORK, which is my own bug from 8edeb12.
   `_arming_condition_persists` asked only about the waiting queue -- which is
   empty exactly when the work has been ADMITTED. Measured 12:49:20 with 90k
   tokens resident: "#running-req: 1, #full token: 457724, #queue-req: 0". The
   damper did not stand down, because by its reading nothing was waiting. The
   load that most wants the other layout is the load already in the machine.
   Now: queued OR running OR in the current batch. A genuinely idle instance
   still reads False, so every counter applies exactly as before in the case
   it was written for.

Tests: the reported instant replayed as arithmetic, including that the 512
margin is in neither side of it; and four cases separating queued, running,
current-batch and genuinely idle. 27 pass on the touched suites.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…er missed running work

Two desk fixes for F1's next boot cycle. I own neither the metal nor the boot;
these are commits to carry.

1. THE C20 ENTRY-MARGIN ARITHMETIC, answered rather than adjusted. Reported as
   "want 2251 with free 3206 fails a 512 MiB margin -- the arming floor looks
   double-counted". It is neither. The predicate is

       law_ok = margin_bytes > 0 and (free_after - staging >= law_floor)

   `margin_bytes` is an ENABLE FLAG and appears in no comparison; the arming
   floor appears nowhere at all; `law_floor` is `guard.law_floor_bytes`, the
   corridor CENTRE. So the binding arithmetic was 3206 - 2251 = 955 against
   1024 -- short by 69 MiB. Nothing was double-counted and the log named 512,
   a number the comparison never touches, which is why it read as a
   double-count from outside.

   955 is also 136 MiB CLEAR of the band floor at 819. A cutover transient is
   judged against the floor -- that is what the band is for, and the same rule
   as the staging reserve in 5658c96 -- so this flip was legal for the
   whole ~35 s that 21,480 tokens waited for it. Now judged against the seam
   floor, and the delay message names the number that actually bound.

2. THE DAMPER MISSED RUNNING WORK, which is my own bug from 8edeb12.
   `_arming_condition_persists` asked only about the waiting queue -- which is
   empty exactly when the work has been ADMITTED. Measured 12:49:20 with 90k
   tokens resident: "#running-req: 1, #full token: 457724, #queue-req: 0". The
   damper did not stand down, because by its reading nothing was waiting. The
   load that most wants the other layout is the load already in the machine.
   Now: queued OR running OR in the current batch. A genuinely idle instance
   still reads False, so every counter applies exactly as before in the case
   it was written for.

Tests: the reported instant replayed as arithmetic, including that the 512
margin is in neither side of it; and four cases separating queued, running,
current-batch and genuinely idle. 27 pass on the touched suites.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…owest buffer counts

Answering the 2048-chunk question: the arena is NOT structurally unable to
pay, and the allocation pattern is not the cause. The rung is also not
declining -- it executes a 271,655-row shrink and gets nothing back. The
number it derived the target from was wrong.

FROM THE BOOT, and the split is the whole diagnosis:

    shrink to 320217 rows reported 0 MiB ...            x9   (current 591872)
    KV-BACKING released 2364 MiB by backing 73345 rows
                                   instead of 149504    x6

Deep targets paid. Shallow targets from a high `current` returned nothing.
`decommit_range` frees only extents lying wholly above the keep point PER
BUFFER, so what decides is the SHALLOWEST buffer, not the total.

`backed_bytes` is a SUM across buffers, and `_physical_backed_rows` divided it
by the all-buffers per-row size -- an AVERAGE depth. That is the true depth
only when the backing is uniform, and the waved seam guarantees it is not: it
releases and restores one layer at a time. So the average overstated, the rung
chose a keep point above the shallowest watermark, and the shrink returned
zero while looking like a large one.

This is my defect from 997ccac, one level below the one it fixed. That
commit stopped the rung reading a CONFIGURED size and had it read the arena;
this one stops it reading the arena's average and has it read the depth a
shrink can act on. Same class both times: a number that is not the one the
operation uses.

`uniform_backed_tokens` on the owner is the minimum committed depth across
buffers, surfaced as `uniform_backed_rows` on both pools, and preferred by
`_physical_backed_rows` with the byte-sum kept as the fallback.

CONSEQUENCE FOR THE QUESTION ASKED: skipping to a driver-verified retry would
not help, because the retry is only ever reached after an arm has been spent,
and with an honest depth the FIRST target is already below every buffer. The
9 zero-byte shrinks and the arm each one cost should not recur. This is a
latency-of-funding fix, as the item said.

All 21 refusals on that boot were pp_to_tp, the leg whose refusal starves
decode under strict purity -- worth noting since the item read as tp_to_pp.

Tests: six cases separating average from minimum, including the measured
instant and a fully released buffer (one emptied buffer means no shrink can
release anywhere). 114 pass across the relief, seam and probe suites.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…ilure

DESIGN CHOICE: the bounded purity escape, not FORCE authority for the rung.
The two options differ in blast radius, so the reasoning is on the record.

Force authority CANNOT satisfy this invariant. Today's whole failure
catalogue is the rung EXECUTING and returning zero bytes -- a self-locking
exhaustion marker, an average-depth target, nine zero-byte shrinks at 15:14.
Force over an arena with nothing releasable still returns nothing, so it fails
in exactly the case it is written for, while spending the dampers added today
and risking a corridor breach during starvation. Running decode in the layout
the instance is already in needs no memory to succeed, and purity's own modes
(`threshold:<n>`, `off`) already run decode in PP as supported configurations
-- the documented cost is throughput, never a wrong answer.

THE HOLE. `flip_unavailable_reason` had two causes and both are COUNTS: a
blocking guard, or an abandon streak reaching `stand_down_after()`. The
decode-stall SLO is a TIME. Nothing bridged them, so a funding failure that
never accumulates a count could hold decode indefinitely INSIDE the bound.
The 15:14 window is the proof of mechanism: the seam abandoned repeatedly
with the arm rate limiter pacing the retries, and the abandon-cap guard was
deliberately stood down while work was waiting, so neither count arrived. It
was harmless only because the running batch was empty.

So time becomes a cause in its own right, checked FIRST because it is the only
one with a bound the operator stated. It reuses the existing, tested
relaxation path, so the stand-down logging, the work-class keying and the
automatic re-arm on the next committed cutover all apply unchanged.

THE CLOCK RUNS ONLY WHEN THERE IS DECODE TO HOLD. An empty batch is not
starvation, and starting on it would spend the SLO before a request arrived --
which is exactly why the 15:14 window looked harmless while the mechanism was
live. It is retired by decode becoming allowed, by leaving the PP phase, and
by an empty batch.

GROUP UNIFORMITY, stated because it is the property this file's other inputs
are chosen for: this is the first non-uniform input here. What makes it safe
is the EVENT it is stamped from -- the first iteration on which decode is
blocked in PP with a non-empty batch. Phase, purity and batch are identical on
every rank at that point, so every rank stamps on the same iteration and
crosses the SLO within ONE iteration of the others, the same bound the abandon
streak already has.

An unset SLO (0.0, the default) changes nothing: the counts govern exactly as
before.

Tests: 13 cases. The falsifier is the invariant itself -- a funding refusal
with running bs > 0, no blocking guard and no abandon streak, proving decode
proceeds once held past the SLO. Verified RED against the parent commit: 5
fail there, including that one.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
THE SLO INVARIANT COULD NOT BE REACHED ON METAL, AND THE REASON WAS A CATCH-22,
not a missing measurement. 1d1dbf9 promises that decodes are never held past
the operator's bound by a funding failure. The shape that tests it is: the
instance IN the PP layout, a decode resident, and pp_to_tp unfundable. Every
lever available on 2026-08-15 moved BOTH directions at once:

  the KV rung disabled    pp_to_tp funded from the allocator cache anyway --
                          and, because refusal_is_fatal deliberately opens the
                          host tier for exactly this leg, from system RAM too.
                          Six flips DONE, zero abandons, nothing ever held.
  the arming floor raised tp_to_pp was blocked with it, the instance rested in
                          TP, and decode was never held at all.

One global gate, two directions, and the proof needs them to disagree. So the
term added here is per DIRECTION, which is the property that was missing:
SGLANG_SEAM_UNFUNDABLE_DIRECTIONS names the legs the group must refuse. With
pp_to_tp named, tp_to_pp still funds and the instance enters PP the ordinary
way; the return leg then refuses, decode is held, and the SLO is the only thing
left that can free it.

WHERE IT LIVES IS THE LOAD-BEARING DECISION. It wraps _corridor_gate rather
than living inside it, because everything the gate runs -- the KV rung's
reduction above all -- sits on a path every rank reaches unconditionally. An
injection that short-circuited the gate would skip a reduction the peers had
already entered, the first time one rank read the variable differently, and
this file's standing rule is that "safe because a value upstream is agreed" is
precisely the reasoning that produces collective hangs. The gate therefore
always runs in full and only its VERDICT is overridden. The cost is one ladder
that spent for nothing; what it buys is that no rank can skip a collective.

WHAT IS INJECTED IS THE REFUSAL; WHAT IS PROVEN IS WHAT THE SYSTEM DOES WITH
ONE. This does not simulate a card with no memory. The verdict joins too_small
like any other objection, so everything downstream is the real abandon path:
the same unanimous MIN, the same FLIP ABANDONED log, the same per-direction
hold and backoff. It deliberately does not carry SEAM_MARGIN_DELAY_TAG -- a
margin delay is a bounded wait exempt from the abandon cap, and calling it one
would prove the wrong thing. The gate's own verdict is kept in the message,
because a proof that hides the state it overrode is not evidence.

An unparsable value arms NOTHING and does not raise: this term is read on the
seam's no-return path, where a raise climbs into the event loop and takes the
instance down. A typo costs a diagnostic, never the instance, and says so at
ERROR. An armed injection announces itself once by name, because an UNARMED
injection is this term's worst failure -- a flip that funded normally, in a
boot believed to be injected, reads as a valve that never had to fire.

Unset is the default and changes nothing.

Two pins updated, not weakened: _execute now reaches the gate through
_seam_funding_verdict, so both links are pinned (the outer call AND the inner
one), and the wrapper is held to the same no-new-collective rule as the gate.

Tests: 23 cases. Two classes PIN THE CATCH-22 itself with the shipped knobs, so
the justification for a new term is falsifiable rather than a paragraph.
Can-fail proven by mutation, which discriminates where a parent-commit run only
shows a missing import:
  term present but UNWIRED  -> 8 fail, catch-22 and default classes still green
  term present but DIRECTION-BLIND (the regression that would restore the
  catch-22) -> exactly the 2 directional falsifiers fail, 21 pass
No regressions: 485 pass across the seam/corridor/purity/kv suites, with the
same 2 failures before and after (test_seam_entry_margin_631's law-refusal
pair, pre-existing at 1d1dbf9 and filed separately).
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…spills for it

THE BOOT WITH THE LEAST INFORMATION RESERVED THE LEAST. Measured on metal
2026-08-15 (boot_maxfill.log): with a COLD seam record the sizer charged no flip
term at all and filled the pool to the corridor law. Rank 1 came up with ~875
MiB free against a ~1536 MiB arming floor, so tp_to_pp was refused on every arm,
every prefill stayed in the TP layout, and NOTHING AT RUNTIME COULD RECOVER IT
-- the pool is fixed at boot. The operator had to hand-pin --max-total-tokens.
A planner that has every input for a number must not need to be hand-corrected
for it.

THE MECHANISM. SeamReserve.active is False when every MEASURED field is zero,
which is exactly a first boot, and seam_adjusted_budget_bytes returned the
budget unchanged on that branch.

TWO QUANTITIES WERE CONFLATED, AND SEPARATING THEM IS THE WHOLE FIX:

  the seam RESERVE  what a flip COSTS WHILE IT RUNS. Knowable only by
                    measurement; legitimately zero on a first boot.
  the arming FLOOR  the LEVEL the gate compares against. Derived from the
                    corridor law the operator already stated, and knowable at
                    boot on every rig.

A cold record means the first is unknown. It never meant the second was. Folding
the floor into the reserve as a "cold default" would make a derived constant
look like a measurement -- the sgl-project#584 derived_provenance defect, which this chain
has already paid for once -- so it is a separate term, charged on every flip
boot, cold or stored.

WHAT THE POOL OWES IS THE DIFFERENCE, NOT THE FLOOR. The sizer already holds the
law free, so charging the whole floor would reserve the corridor twice and cost
the pool a gigabyte it does not owe -- the same double-count required_free_bytes
refuses with its max. The per-rank free target becomes
max(law, arming floor + load margin). A rig whose arming floor sits below its
corridor is sized exactly as before, and a caller that passes no floor gets the
previous arithmetic byte for byte.

AND AT RUNTIME, THE FLOOR IS SPILLED FOR BEFORE IT IS REFUSED FOR. "It can
always be spilled" is true BEFORE arming, and only before. A correctly planned
instance never reaches this path; what reaches it is the transient a sizer
cannot see -- a co-tenant, a capture peak, a rank that drifted. Refusing an arm
for a condition one ladder call could fix turns a recoverable dip into a phase
the instance cannot enter, which is the same defect one layer up. So a short
floor asks the existing CorridorGuard ladder for relief, and only a shortfall
that survives a bounded number of attempts refuses -- loudly, naming how much
was short and what the ladder actually freed.

THE ORDER IS THE HARD CONSTRAINT. Relief runs strictly before the arm: nothing
is armed, no rank has entered the seam, no collective has been reached, and the
staged fund does not exist yet to be pulled out from under. Spilling once the
flip has begun is the evictable-seam-fund mistake that produced the
served-nothing class in sgl-project#656 boots E/G. This rung is ADDITIONAL to the seam
gate, which still owns the in-window ladder at the last point before the
no-return region.

RANK-LOCAL BY CONSTRUCTION, AND THAT IS SAFE. A rank that refuses here does not
arm, which the consensus round already handles -- arming is reduced across the
group. No collective is added, so none can desync.

The ask is the floor MINUS the law the guard already defends: ensure_headroom
guarantees free_after - want >= law, so asking for the whole floor would spill a
second corridor for nothing.

AN UNREADABLE INSTRUMENT MAY NOT BLOCK A FLIP. A probe that raises, a missing
guard or a ladder that falls over all let the arm proceed on the seam gate's own
ladder: failing to MEASURE the floor is not evidence that it is SHORT, and
refusing on a bad reading would turn it into a permanently stuck phase. Bounds
are counts, not clocks -- the ladder is synchronous -- and a malformed or zero
bound falls back to the default rather than refusing without ever asking.

Tests: 25 cases, can-fail proven by mutation:
  sizer does not charge the floor (the metal defect restored) -> the cold-boot
    assertion fails, alone and by name
  the arm refuses a short floor without asking the ladder (the behaviour the
    order forbids) -> 8 fail
No regressions: 544 pass across the seam/corridor/purity/kv/sizer suites, with
the same 2 pre-existing failures before and after.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…s at

CAUGHT ON THIS RIG BEFORE THE PROOF BOOT, AND IT WOULD HAVE BEEN SILENT.

The previous commit derived the arming floor with a bare
``corridor_guard.arming_floor_mib()`` -- 1331 MiB here. The gate does not arm
at that number. ``get_corridor_guard`` resolves the floor as
``max(operator override, derived-from-this-rank's-measured-seam-draw)``, highest
wins, and the live instance sets SGLANG_CORRIDOR_FLOOR_MIB=1536.

So the pool would have reserved 205 MiB less than its own gate requires, on
every rank, and the result is indistinguishable from a healthy boot: the
instance comes up, serves, and never flips. That is the defect the previous
commit exists to fix, reintroduced one level down -- two numbers that must be
equal, computed in two places, which is a shape this corpus has already paid
for more than once.

FIXED BY RESOLVING IT ONCE, FROM THE SAME TWO INPUTS:
  * the operator's override, read from the same env var and the same
    server_args field the guard reads, in the same order;
  * this rank's measured seam draw, taken from the seam record the sizer
    already holds in hand -- the same record ``_measured_seam_draw_mib`` reads
    for the guard.

AND AT RUNTIME THE RELIEF NOW READS ``guard.floor_bytes`` DIRECTLY rather than
re-deriving it, for the same reason: the gate arms against that attribute, so
it is the only honest target for a rung that exists to reach the gate. A second
derivation there would spill for a level nothing enforces. The sizer targets
that floor PLUS the load margin so the card starts above it; the runtime targets
the floor itself.

Tests: 4 more cases, 29 total. Can-fail proven by mutation -- reserving for the
derived floor while ignoring the override fails the override test, alone and by
name. No regressions: 538 pass across the seam/corridor/purity/kv/sizer suites
with the same 2 pre-existing failures.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
…t deadlocks the chain

MEASURED ON METAL, boot_slo_proof_r2.log, 2026-08-15 22:10:03Z. This is the
first time the invariant's shape was reachable on demand, and it falsified the
uniformity argument the valve was shipped with.

WHAT THE PROOF BOOT SHOWED. The valve fires exactly as designed:

  22:09:18  [sgl-project#662-F4 UNFUNDABLE-SEAM] ARMED for pp_to_tp
  22:09:31  FLIP ABANDONED (pool too small for the live set): pp_to_tp --
            through the real abandon path, on ALL THREE ranks
  22:09:56  arming pp_to_tp: DRAINED, 2 req decoding -- decode resident, held
  22:10:03  RELAXING PURITY FOR DECODE: decode has been held 45.0s by an
            unfunded flip, past the 45s decode-stall SLO

and then the instance WEDGED. No decode step ever ran, all three cards at 0%
utilisation, every rank alive, /health 503.

THE TALLY IS THE WHOLE DIAGNOSIS. "FLIP ABANDONED" appears twice on each of
PP0, PP1 and PP2 -- group-uniform, as designed, because it is incremented off a
collective MIN. "RELAXING PURITY FOR DECODE" appears EXACTLY ONCE, on PP0.

So rank 0 alone relaxed, admitted a decode batch into the PP layout, and
blocked in _pp_commit_comm_work waiting on a proxy-tensor send whose matching
receives its peers never posted -- while PP1 and PP2 blocked in recv_requests
waiting for a forward rank 0 could no longer make. py-spy for all three ranks
is in evidence-662-F4/wedge_pyspy_r2.txt.

THE PREMISE THAT FAILED, precisely. The clock was started from
``running_bs > 0`` -- THIS RANK'S OWN BATCH -- and justified as group-uniform
because "phase, purity and batch are identical on every rank at that point".
That holds under TP and is FALSE UNDER PP: in a pipeline the head holds the
requests and the downstream ranks do not see them until it forwards them, and a
head that is holding decode never forwards. PP1 and PP2 therefore sat at
running_bs 0, _clear_decode_starving reset their clocks every iteration, and
only the head could ever cross the SLO. A per-rank wall clock feeding a
decision that must be unanimous is the rank-local-state-feeds-a-collective
shape this tree keeps paying for.

THE FIX: STAMP THE CLOCK FROM WHAT THE GROUP ALREADY AGREES ON -- the seam
abandon streak for the direction that starves this work class, plus the
policy's own refusal streak. Both are group-uniform for reasons this file
already relies on elsewhere: the first is incremented off the reduced verdict,
the second is produced by the same policy running over the same reduced
verdicts. No new collective is introduced; this reads numbers the group has
already reduced.

BOTH COUNTERS, not just the seam's. The seam streak CANNOT advance once the
policy backoff engages, because the policy then declines the arm without
entering the seam at all -- measured 2026-08-13, the abandon counter frozen at
3 while the policy logged "arm refused (7 in a row)" and work sat unrunnable.

A NON-ZERO COUNT IS NOT A COUNT THAT REACHED ITS BOUND, and the hole stays
closed. One refusal is merely evidence that a funding failure is happening at
all -- the precondition the invariant is stated over. The BOUNDS
(stand_down_after, the abandon cap) are what the SLO exists to outlive, and the
clock still has to run out. It is also the honest work signal: the streak only
advances because the policy ARMED the flip, and it arms the direction that
serves decode because decode is waiting.

Tests: 18, five of them new and all about the property that was missing -- a
rank with an EMPTY batch still starts its clock, the head and the tail reach
the same verdict, a policy refusal with no abandon still counts, no funding
failure anywhere starts no clock, and a committed flip retires it everywhere.
Can-fail proven by mutation: restoring the ``running_bs > 0`` premise fails
exactly those five and nothing else. One pre-existing unused import removed
from the file while editing it.
No regressions: 679 pass across the seam/corridor/purity/kv/sizer/policy
suites, with the same 2 pre-existing failures as before.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 15, 2026
The second proof boot (boot_slo_proof_r3.log, c8fb908) did not reach its
acceptance. It found two defects in the change that was supposed to prevent
exactly the condition it hit. Both are fixed here; both now have the falsifier
that would have caught them.

DEFECT 1 -- THE FLOOR CHARGE WAS THROWN AWAY BY A MIN.

The charge was applied to the budget BEFORE ``min(budget, allowed * cell)``.
That is not equivalent to applying it after: whenever the seam solve binds --
which is whenever a MEASURED record exists -- the min picks ``allowed * cell``
and the subtraction vanishes.

So the term worked on the COLD boot that wrote the record, and did nothing at
all on the next boot, which read it. Measured across the pair: pool
385927 -> 491445, free landing at 1515/3130/1983 MiB against guard floors of
1772/1964/2414 -- below the floor on two of three ranks, the exact condition
this term exists to prevent. A charge that only fires on a first boot is worse
than no charge, because the second boot looks like the fixed one.

The charge is now applied to whatever the two solves settle on. It can only
ever reduce the result, so applying it after a min that never grows it is safe.

DEFECT 2 -- MY PRE-ARM REFUSAL WAS RANK-LOCAL AND SPLIT THE ARM.

The rung returned False when the ladder could not reach the floor, on the
argument that "a rank that refuses simply does not arm, which the consensus
round already handles". Metal says otherwise, and this is the same error as the
one being fixed in the commit before it, one layer up, made while fixing it.

Measured: PP0 sat at 3130 MiB against its 1728 MiB floor and ARMED. PP1 and PP2
sat at 1514 and 1982 against 1772 and 2414 and REFUSED. The group split, and the
armed rank parked at the entry -- "WITHHOLDING presence (8854 rounds so far) --
still owes a chain send" -- spinning for ever, no decode, three cards at 0%.

The existing blocking guards get away with being rank-local because they are
config facts, identical on every rank in practice. A verdict keyed to this
rank's FREE VRAM never is.

So the rung keeps the half that is safe and rank-local -- SPENDING the ladder,
which frees memory and cannot desync anything -- and leaves REFUSING to the
seam gate, which reduces its verdict across the group and already prints the
numbers. One unanimous decision, not two. The operator's requirement is
unchanged and still met: relief runs before arming, and the shortfall is still
logged with how much was short and what the ladder freed. It is a report now,
not a decision.

The caller DISCARDS the return value, and that is the point: the property is
structural rather than a promise in a docstring, and a source-level test pins
it so a future edit cannot quietly restore the branch.

Tests: 32, three of them new -- a WARM record still gives up the floor (the min
ordering), a short floor with the host tier full still lets the arm proceed (the
split arm), and arm() does not branch on the relief verdict. Can-fail proven by
mutation: charging before the min fails the warm-record test alone; restoring
the rank-local refusal fails the split-arm pair.
No regressions: 706 pass across the seam/corridor/purity/kv/sizer/policy suites
with the same 2 pre-existing failures.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
… nobody read the receipt

TWO CLAIMS IN THE REPORT ARE WRONG, AND CORRECTING THEM CHANGES THE FIX.

1. "The 'no relief existed' line appears ZERO times." It appears THREE times,
   once per rank, at 01:46:10 -- the exact moment of the crash. The net DID
   engage, found the registry empty, said so, and let the raise proceed, which
   is precisely what it was built to do. Its diagnostic worked; the guarantee it
   points at (admission) is what failed.

2. "Pool at 0 fundable tokens / exhaustion." Not this crash. Usage was 0.85 and
   the failure's own message says:

       Try to allocate 512 tokens.
       Available full tokens: 66039 (available=273 + evictable=65766)

   512 needed against 65,766 evictable. This was never exhaustion.

WHAT ACTUALLY HAPPENED. All three ranks reported IDENTICAL numbers, so the pools
agreed, so uniform_avail_floor was None, so the eviction trigger used the local
value (273 < 512) and eviction DID run. It simply did not deliver.

`evict` walks the LEAF FRONTIER: it pops evictable leaves and re-pushes a parent
only once all its children are gone AND it is unlocked. `evictable_size_` counts
unlocked tokens ANYWHERE in the tree. Tokens sitting behind a locked chain are
counted and unreachable -- so the counter promises what the actuator cannot pay.
That is the same shape as the sgl-project#662-F5 watermark finding: a number that is
correct as a count and wrong as a capability.

AND THE RECEIPT WAS THROWN AWAY. `evict` returns num_tokens_evicted;
`evict_from_tree_cache` discarded it at both call sites. An eviction that freed
ZERO was therefore indistinguishable from one that freed everything asked, and
the allocation three lines later raised a message quoting 66,039 available
tokens. Only disaggregation/decode.py reads that receipt today -- and it uses it
for exactly this purpose ("after evicting X/Y tokens"), so the precedent existed.

THE FIX, in three parts:

* evict_from_tree_cache RETURNS what it actually freed. Callers can no longer
  proceed on the strength of a count the actuator did not honour.
* the allocation error NAMES the under-delivery -- asked, freed, still-reported
  evictable, and why the two differ. The difference between a confusing message
  and a diagnosis.
* RULE 3 OF DESIGN_679 IS CLOSED. The audit of the prefill admission path found
  THREE raise sites and only one covered:
      alloc_req_slots                 request slots (and mamba states)
      alloc_token_slots               page_size == 1        <- the covered one
      alloc_paged_token_slots_extend  page_size > 1
  All three now ask the net before raising. alloc_req_slots is asked knowing a
  token-shaped relief cannot pay a request-slot shortage: the ask is what tells
  an operator the site was covered rather than forgotten.

WHAT THIS DOES NOT FIX, stated plainly. The net still has no provider, so this
crash would still end in a raise -- but with a message that diagnoses itself
instead of blaming a full pool. And no admission accounting can prevent it:
admission budgeted 66,039 fundable tokens and it was RIGHT about the count. The
real repair is one of
  (a) make eviction able to reach tokens behind locked chains, or
  (b) make the budget count only leaf-reachable evictable tokens,
and both are design decisions with their own uniformity arguments, not desk
edits to slip into a crash fix. Filed rather than guessed.

GROUP UNIFORMITY unchanged: the trigger's rank-uniform predicate (#616g) is
untouched. Only the return value and the diagnosis are added, neither of which
enters a branch.

Tests: 10 new (30 in the file), red-first against 3374029 -- the commit that
crashed -- where 5 fail outright and 3 subtests fail on the uncovered raise
sites. 1013 pass across the suites, zero failures.

NOT BOOTED. Desk-only; READY-FOR-BOOT.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
… what we remembered

THE ROOT QUESTION IS ANSWERED, AND MY OWN CANDIDATE WAS WRONG. I had named the
flip's "released 1410.0 MiB of weights-arena tail" as the reason the
reservation ends up below `_rows_at_boot`. It is refuted twice over: that is
the WEIGHTS arena, not the KV pool, and the KV reservation cannot move at all.

    memory_pool.py:2458   reserved_num_tokens=self.size      # at construction
    kv_vmm_backing.py:979 self._reserved_num_tokens = int(...)  # assigned ONCE

The reservation is pinned to the pool's size at the moment the arena is built
and never assigned again. `size` is NOT immutable -- the sgl-project#330 dial writes it on
every step, which sgl-project#662-F4 already noted one layer up. So a grow target derived
from a remembered or configured row count can sit above a ceiling that never
moves, and `_check_final` refuses it identically, forever.

MEASURED, AND UNCONFOUNDED: 59 times between 02:15:24 and 02:35:26 on
2026-08-16, a steady 3 per minute, once per rank per flip leg --
`recovery to 270646 rows failed: ... reserved=190596`, and the same shape on
the other two ranks (180428/108912, 179466/136140). That window opens before
any test-harness CUDA activity on the rig, so unlike the free-column readings
from 02:29 onward it is not confounded.

WHY IT IS BIGGER THAN THE LINE. Recovery is what LIFTS the backing cap. 59
refusals meant the cap never lifted, the pool stayed shrunk, and every later
`free_up_to` found the backing already at its target and honestly claimed 0
MiB -- which the shrink path then reported as an exhausted ARENA. One
unsatisfiable number, and the corridor guard's only rung above
`allocator-cache` was dead for the whole boot while its diagnostic pointed
somewhere else. That is the shape sgl-project#683 was opened on.

THE REPAIR IS THE SAME CORRECTION AS sgl-project#681 AND sgl-project#682: validate against what the
ACTUATOR can pay, not against the count that proposed it. sgl-project#681 was a token
count against a leaf frontier, sgl-project#682 a guard ceiling against the bound the
scheduler actually holds, and this is a grow target against an immutable
reservation. So the clamp is deliberately NOT conditional on knowing why the
remembered number went stale -- it asks the bound.

CLAMP *AND* RE-DERIVE, because the clamp alone would only convert a loud
failure into a quiet one: `_rows_at_boot` would still name an impossible level
and every later recovery would re-clamp to the same place while believing it
had further to go. Correcting it lets the existing "fully recovered" branch
fire, which clears the remembered rows AND retires the exhaustion marker --
the latch that kept the rung off.

RANK-LOCAL, EXPLICITLY, as the brief asks. A reservation is one card's VA span;
under uneven TP the ranks hold different ones -- 190596 / 136140 / 108912 on
this boot -- so there is no group quantity here to agree on. `recover` takes no
collective, and this commit adds none. The module's collective, the sgl-project#656 C22
cap agreement, is on the SHRINK target and is untouched. The new accessor is
also NOT `_reservation_rows` (the allocator's id space, which does feed
`exposed_rows` and that agreement); the two are cross-referenced in code so a
later reader cannot conflate them.

SAFE DESK-SIDE, AND THE JUDGEMENT IS ASKED FOR, SO HERE IT IS. Two properties
make this shippable without a GPU window:
  * the clamp fires ONLY where `rows > ceiling`, which is exactly the path that
    currently fails 100% of the time. On any boot where recovery works today
    the branch is inert, so there is no working behaviour for it to change.
  * it runs AFTER the corridor-affordability bound, so when both bite the
    target is the smaller of the two and the clamp can only LOWER it. Raising
    it would commit pages the corridor law had already refused -- the failure
    that drove rank 1 to 6 MiB free and OOMed inside relief. Pinned by
    `test_the_clamp_can_only_lower_the_target_never_raise_it`.
A pool that exposes no reservation keeps its previous behaviour exactly; 0 is
read as "no arena", never as a ceiling of zero, which would be a shrink wearing
a grow's name.

TESTS, red-first. The acceptance pin committed with the verification --
`test_recovery_is_refused_forever_because_nothing_clamps_it` -- was inverted to
the post-fix expectation FIRST and failed, together with the re-derivation pin;
both pass after. It keeps its name: it asserted the defect before the clamp and
asserts the repair after it, which is what an acceptance pin is for. Seven
cases in all, four of which exist so the fix cannot pass by being broken
everywhere: the control (a reservation above the boot rows recovers normally),
the affordability bound still deferring untouched, the clamp/affordability
interaction, and the two backward-compatibility contracts.

Sweep: 2433 passed across unit/managers + unit/mem_ledger + the 681/682 files.
Four failures in that run are pre-existing and unrelated -- same four, same
messages, on the untouched tree (`BudgetHarness` and `_Sched` stubs missing
attributes in test_collective_family_siblings_610 and
test_first_chunk_dynamic_chunking); neither file references anything this
commit touches.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…chor it does not have

THE DEFECT. A cold ``SeamReserve`` has every measured field at zero,
``per_row_bytes`` included, so the per-token seam term is 0 on a first boot and
the pool is sized floor-only -- a pool whose cutover it cannot fund. The arming
FLOOR has been charged on a cold record since sgl-project#662-F4/A0; the SLOPE never was.

WHAT IS NOW DERIVED. sgl-project#685 established that a rank's per-row seam cost is the
full-attention layers it must RECEIVE at the cutover,
``max(0, share*n_total - held)``. Every term is rank-LOCAL and known at boot,
which is what makes it usable where nothing has been measured or exchanged:
the share from ``--phase-flip-tp-vector``, ``held`` from the attention modules
this runner actually built (``_lane_kv_bearing_layer_count``, family-neutral by
construction), the total from the model config, and the per-layer cell from the
configurator's own ``_cell_size`` divided by this rank's attention count. No
collective, no measurement, nothing transferred from another rig.
``derive_seam_slope_for_rank`` is the single-rank form; it agrees with the
whole-vector one, asserted.

A FALLBACK, NEVER AN OVERRIDE. Any non-cold provenance is returned untouched --
identity-asserted for both STORED and OVERRIDE. A measured record is a fact
about this rig and outranks a model of it.

ABSTAIN RATHER THAN APPROXIMATE. Missing flip vector, unparsable vector, rank
outside it, no attention layer on this runner, no single cell (the hybrid-SWA /
MiniMax case the existing cell read already refuses to invent for), no
full-attention layer in the config -- each leaves the slope at zero and says
which one. A rank that receives NOTHING is also left at zero: charging it a
per-token seam would reserve against a transfer that does not happen, which is
the over-reservation sgl-project#685 named.

AND HERE IS WHERE IT STOPS, WHICH IS THE HALF THAT MATTERS. The slope is
derived and announced, but the reserve stays INACTIVE and the budget path
still returns floor-only. ``SeamReserve.active`` requires ``id_space > 0``, and
the downstream solve anchors on that measurement point together with
``have_bytes`` (``t_floor = t_m + (have_m - A - F) // cell``). A derived slope
has no measurement point. Setting those two to make it active would fabricate
the anchor -- precisely the approximation this work is under orders not to
make, and the same watchdog-versus-live-input confusion as the
``basis_per_row_bytes`` catch one level down.

Consuming it needs an anchor-free branch. ``solve_pool_tokens`` IS that form
and takes no anchor, but it has NO live caller anywhere in the tree, so which
budget it is solved against (``budget_bytes`` net of the floor charge, or
something the sizer has not yet subtracted) is a design decision on the boot
path rather than a wiring detail. On a change that cannot be deployed or
measured from here, picking it would be guessing with the boot as the test.

SO WHAT THIS COMMIT ACTUALLY BUYS: the cold per-token seam is no longer
silently zero. It is computed, and a boot that would previously have been sized
floor-only in silence now prints the number, the layer count it came from and
the share it was derived against. That is the difference between an unfunded
cutover nobody can see coming and one named at boot. It is NOT yet the sizing
fix, and the tests say so rather than implying otherwise: a case pins that the
derived reserve does NOT become active, with the reason.

TESTS. Red-first is a genuine ImportError on the missing single-rank API, then
14 green. Covered: rank 0 receiving exactly one layer; the shedding and neutral
ranks receiving nothing; agreement with the whole-vector form; an out-of-range
rank refused; the cold reserve gaining the slope with a log naming it derived;
the consumption boundary pinned; STORED and OVERRIDE returned by identity; all
five abstentions; and two sizing cases showing a priced slope grants strictly
fewer tokens than a zero one -- so the derivation is not decoration once it can
be consumed.

test/registered/unit/managers: 2052 passed, 4 pre-existing failures (one
further ZMQ round-trip failure in the batch run passes 22/22 in isolation --
flaky, not this change). Hermetic (CUDA_VISIBLE_DEVICES=""). NO DEPLOY: this
touches the boot sizing path and F4-r4 decides when it enters his line.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…e two commits to hold

MERGE_NOTES_602.md rewritten to cover all 18 commits: what each fixes, its test
evidence, whether it touches runtime, and whether an equivalent patch is
already on the serving line (verified with `git cherry`, not by message
matching -- four are: c41645c, ce60358, 658ea3a, 84b0171).

DRY RUN: clean. Merged into `integration/r2` -- the live line, since the
serving tree descends from its tip a73a0d8 -- in a throwaway worktree,
`--no-commit --no-ff`, then aborted and the worktree dropped. Zero conflicts,
zero unmerged paths, so nothing was pre-resolved because nothing needed it.
Verified semantically as well as textually: on the MERGED tree, managers 2093
passed / 0 failed and planner 2574 passed / 2 failed, the two being the same
pre-existing test_rejected_evidence_pins pair that is already red on the base.

THE FACT THE OPERATOR NEEDS, and it is not in the commit count: `7936bc4850` is
NOT an ancestor of integration/r2, so merging this branch drags in its whole
base lineage -- 115 commits, of which 18 are mine and 97 are the hotfix/677
work (sgl-project#662 x20, [PhasePolicy] x18, sgl-project#677 x8, sgl-project#678 x7, sgl-project#679 x6, ...), 129 files,
+22731/-762. Approving this merge is approving that lineage, most of which is
not mine to vouch for. If only this work is wanted it must be cherry-picked
rather than merged.

NOT ATOMIC, and it splits cleanly into four groups with an order: (1) the four
already on serving -- merging them only reconciles integration with what is
already running; (2) the three sgl-project#624 test-only drift guards, which take managers
from 4 failures to 0 and should land early so the line stays green during
review; (3) desk tool + docs, all planner/pp_cut.py and markdown, imported by
no serving path; (4) hold.

HOLD, two commits, both runtime and neither on the serving line:
  * e21e87f (sgl-project#690) touches the seam hot path and changes the PHASE-FLIP DONE
    format. Already queued to land on deploy WITH the W=8/W=4 probe after the
    sgl-project#694 soak verdict; merging it into integration first puts it in front of
    the soak meant to measure it.
  * 5301b94 (sgl-project#685) touches the boot sizing path. Announce-only today and
    abstention-guarded, but unsoaked, and the R' decision it waits on is not
    made.

Nothing else in the chain can move serving behaviour.

Docs only; no merge performed, no deploy, scratch worktree removed.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 17, 2026
…unification

sgl-project#612: declare the decoupled_kv construction site in RUNTIME_COMMUNICATOR_GROUPS.
Declaration completeness only -- the contract checks construction SITES, and
initialize_decoupled_kv_group has no production caller yet, which the entry
says rather than implies. No behaviour change.

sgl-project#584: file both constants the newly-merged ratchet caught, with differentiated
verdicts rather than a baseline bump. planner/boot_instruments.py::
_CHAIN_TOLERANCE_MIB is NOT A DEMAND DECISION and the call site was read to say
so: it is the rounding slack for verifying the budget-chain identity, reserving
nothing. managers/phase_flip_seam_reserve.py::DEFAULT_ARMING_MARGIN_MIB is
NEEDS AUDIT: it genuinely gates a VRAM decision, its own comment argues it is
an instrument tolerance, and that call belongs to the sgl-project#662-F4 owner.

TICKET_702_unify_revisions.md files the decision that stopped fix/602-fill-side:
WorldMemory canonical (boot 2 validated it), PhasePoolModel's attention-layer
divisor and sgl-project#723 frontier completeness ported as an EXTENSION, never a parallel
model. The four mechanical resolutions from that aborted merge are recorded so
the next attempt does not re-derive them.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 17, 2026
…- unstrangle the funder

My sgl-project#744 fix has a live regression and this is the refinement. Specimen
21:46:32 on 72696b0aec: tp_to_pp refused 35x, IDLE-LOCK with 407,622 tokens
pending and 0 resident, the guard reporting "no KV provider is registered"
because the armed-only gate refused the rung at BOTH sites and left the
provider list empty. Seam staging (PP1: needs 1269 MiB, spendable 883, rung
wanted SHRINK to 126506 with slack 45526 = a 1455 MiB deficit that WAS
coverable) could never be funded.

THE ERROR WAS MINE AND IT WAS A DESIGN ERROR, not a slip. Seam-funding
eviction of recomputable prefix rows is REQUESTED BY the flip machinery -- it
is what "KV capacity is the funder" means -- so refusing the rung for the
duration of a flip protects against the 21:18 crash by disabling the thing the
flip is waiting on. A wholesale gate cannot be right when the protected party
and the requesting party are the same machinery.

THERE WERE TWO STRANGLE POINTS, not one. The armed gate was the obvious half.
The second was quieter: _nothing_resident() returning False on a parked extent
dropped through to the unknown-refuse branch, so even with the gate removed the
rung would still have declined. Both are fixed.

THE REFINEMENT. The parked extent already carries exactly the information
needed to be selective, which is why this is clean rather than a compromise:
rows INSIDE it are what the flip is about to pack and may not be touched; every
row ABOVE it is recomputable prefix and is precisely what the funding wants. So
the extent PINS THE CEILING instead of closing the rung. _parked_ceiling()
returns the highest parked row id, -1 when nothing is parked, and -2 for the
one case that still refuses wholesale: an UNKNOWN extent while a flip is armed,
where there is no boundary to name. Both call sites take req_max =
max(req_max, parked), so the evictor is handed a ceiling that cannot reach into
the extent.

UNKNOWN, DECIDED AND DOCUMENTED as asked: it refuses ONLY while a flip is
armed. Outside a flip there is nothing parked to protect, and closing the rung
there is exactly the strangle this commit removes. sgl-project#746 (the exact arm-time
snapshot) is what removes this last wholesale case; until then it is one
narrow, named condition rather than the whole flip window.

TEST RESULTS

test_evict_rung_flip_park_744.py refined to the new semantics, 19 tests + 2
subtests green. The two tests that asserted the wholesale gate are REPLACED
rather than deleted -- they now assert the funding path delivers -- and the
crash protection gets its own explicit test that the evictor's ceiling never
reaches into the parked extent.

Mutation matrix, 4 mutants, ALL KILLED, covering both directions:
  N1 exclusion removed (parked ignored)      -> 1 failed  CRASH protection dies
  N2 exclusion covers everything (gate back) -> 1 failed  FUNDING dies
  N3 collecting site ignores parked ceiling  -> 2 failed
  N4 unknown-while-armed no longer refuses   -> 3 failed
N1 and N2 are the (c) pair: neither over- nor under-covering survives.

Pinned suites green together, 142 passed + 87 subtests: sgl-project#744, sgl-project#731 + the
#731x#744 interaction pin, both sgl-project#717 suites, sgl-project#656, sgl-project#684, sgl-project#662-f4, sgl-project#713
admission intake, sgl-project#739 prefill progress.

Ruff and codespell clean.

PP2 SECONDARY, checked and NOT claimed as fixed. The 0 MiB shrink against an
unmoved driver-free column is an already-instrumented condition
(kv_backing_relief.py:1915-1927): the code detects it, names retained handles
(SGLANG_FLIP_SEAM_RETAIN_HANDLES) or a missing commit chunk as the cause, keeps
the cap on and returns 0. The gate refinement lets the rung PRICE again; it
cannot make a retained-handle arena PAY. Necessary, not sufficient -- the
retain setting needs verifying at the boot, and this commit does not pretend to
close it.

No boot.
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.

2 participants