Skip to content

[CI] Return output logprobs in unit test - #1361

Merged
Ying1123 merged 2 commits into
mainfrom
ying-output-logits
Sep 9, 2024
Merged

Ying1123 merged 2 commits into
mainfrom
ying-output-logits

Conversation

@Ying1123

@Ying1123 Ying1123 commented Sep 9, 2024

Copy link
Copy Markdown
Contributor

No description provided.

@Ying1123
Ying1123 merged commit 689ff58 into main Sep 9, 2024
@Ying1123
Ying1123 deleted the ying-output-logits branch September 9, 2024 20:05
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 12, 2026
… instead of a constant

WHAT KILLED weg2xsn26b, measured (hostsample CSV + the /.lxc cgroup):
  * the kill was the GLOBAL host OOM killer, not a cgroup limit: memory.events
    `max 0 high 0`, oom_kill 1 -> 3, memory.max is `max`, and there is no
    separate serving cgroup -- ranks, front, sampler and the Claude CLIs all sit
    in /.lxc (sgl-project#721's nine `.lxc` kills, now confirmed for this boot);
  * the CURRENCY was right: shmem climbed 49.360 -> 60.008 GiB while anon FELL
    from its own peak, and `file - shmem` at the last sample was 0.008 GiB. The
    file-backed / checkpoint-mmap hypothesis (sgl-project#738) is refuted outright;
  * the guard at 93.0 never fired because ITS SERIES STOPPED: sampler gaps of
    19 / 25 / 18 s, last reading 82.28, memory.peak 95.86;
  * the last measured seconds climbed 50.157 -> 53.415 -> 55.847, i.e.
    2.4-3.3 GiB/s, covering the remaining 13.6 GiB in FOUR TO SIX SECONDS --
    entirely inside the 19 s blind window.
So the defect is CADENCE AND BLINDNESS, not the unit.

(1) `RateLatch`: fed on the caller's OWN cadence (200-500 ms), fires on
`nonreclaim + rate x lookahead` (5 s) against the reap mark, W98
Weg2HostRateLatched with `rate=` `projected=` `now=` `gaps_seen=` on the line.
Pure but for its clock: it returns a LINE, never tears anything down -- the
caller owns that, this owns the arithmetic and the words.

THE RATE IS THE WORST PAIR IN THE WINDOW, NOT THE ENDPOINT SLOPE, and that is
the whole latch: fitted end-to-end over 3 s, xsn26b's own ramp averages to
1.98 GiB/s, which projects 3.7 GiB BELOW the mark -- the new guard would have
watched the boot die exactly as the old one did. The worst pair of the same
window is 3.26 GiB/s and projects past it. Averaging smooths away the ONSET,
and the onset is the only part there is still time to act on. Same
MAX-over-samples rule the reap samples and the ring-era transient already use.
A FALLING reading projects to itself and never below: crediting a dip as future
headroom is how a guard talks itself out of firing.

BLINDNESS IS ITSELF A FINDING: a hole longer than 3 s emits its own
`WEG2-HOST RATE-GAP gap_s=` line. The guard that goes quiet must say so.

(2) `reap_model_line`: the mark DERIVED, the constant printed beside it as the
cross-check it has become. 95.90 is not a property of the box -- it is host RAM
minus whatever is outside this cgroup, and that term is real: ZFS ARC held
5.01 GiB (c_max 5.00) against this container's Cached 1.65 and the cgroup's
file 1.58. The ARC appears in NO container figure because it is charged to no
cgroup, so capping it moves the mark with nothing in our instruments changing.
AND THE MODEL REFUSES WHERE IT CANNOT SEPARATE: MemAvailable already counts
reclaimable pages the cgroup counts too, so on a quiet box the subtraction goes
negative (measured idle: 118.05 - 117.67 - 7.56 = -7.18). Clamping that to zero
would publish reap_mark = MemTotal = 118.05, i.e. 22 GiB above two recorded
kernel reaps and in the FUNDING direction. It prints `outside=OVERLAP` and
falls back to the constant instead.

Plus the PEAK BASELINE at launch, same shape as the cumulative oom_kill
baseline: `memory.peak` is a lifetime high-water mark with no reset anywhere in
this tree, and weg2xsn26b inherited ~95.1 GiB of it from weg2xsn25's death --
its record then read the inherited figure as its own peak. Baselined and
printed so the next record states a DELTA. No reset attempted: the file is
`nobody:nogroup` in this LXC and a failed write is a silent no-op.

Tests: 14 in the new file -- the real ramp latches on its ONSET sample (one
second of warning the level guard never had), the worst-pair-vs-average
contrast, flat and falling series never latch, latch-once, the three measured
gaps each reported, normal 200-500 ms jitter is not a gap, the mark derived
under load, OVERLAP on a quiet box, unreadable terms falling back by name, and
the ARC named. Launcher dry-run rc=0 with both new lines printed.
LOCAL: 145 passed / 0 failed across the touched weg2 suites, ruff clean.
No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 12, 2026
…at already carries W22

A built-but-unwired guard is the sgl-project#464 / sgl-project#1017 class, so the latch now rides the
same loop as the level verdict -- and the SAME CLOCK, which matters: `gaps_seen`
then counts THAT loop's own blindness, not another sampler's. Boot weg2xsn26b
was killed by the global host OOM killer while the level verdict never fired,
because at its cadence the last reading before the blind window was 82.28 GiB
and the climb covered the remaining 13.6 GiB in 4-6 s.

* the loop now ticks at `min(0.5, host_watermark_period_s)` -- the fast end of
  the ordered 200-500 ms band -- and the LEVEL test gates itself on `_level_due`
  so W22's own period is unchanged;
* ONE `read_cgroup_pressure` per tick feeds the latch, and the level verdict
  reuses it: the two can never disagree about the reading they graded;
* a latch goes down the SAME NAMED TEARDOWN as W22 (`do_stop("W98
  Weg2HostRateLatched")`) -- the user's 2026-09-08 order is a controlled
  teardown, never a kernel kill and never "accept the risk";
* a RATE-GAP is logged and counted but NEVER torn down: the loop kept running,
  it just could not look. Blindness is a finding, not a verdict.

Four ratchet tests read the loop's own source: it constructs the latch, feeds
it, routes the latch to the named teardown, does NOT tear down on a gap, runs
faster than the level test, and grades both halves from one reading.

ALSO IN THIS COMMIT'S SCOPE BUT OUTSIDE THIS REPO (gpu-arb is not a git repo,
noted rather than silently split): `gpu-arb/weg2/hostsample_v2.sh` -- the six v1
columns keep their names, order and meaning so every v1 reader keeps working,
and six are APPENDED (host_memavailable_gib, root_current_gib, root_file_gib,
root_anon_gib, root_shmem_gib, root_slab_gib) plus a `sampler_version` field.
Cadence 0.5 s with sub-second timestamps, so a gap is VISIBLE as a timestamp
jump instead of inferred from a row count. Smoked: 8 rows at 0.3 s.
Its header carries the honest note that on THIS container root == the serving
cgroup (`/proc/self/cgroup` reads `0::/.lxc`, no child holds the ranks), so the
root_* columns duplicate the ones before them BY CONSTRUCTION and the genuinely
new information is `host_memavailable_gib` -- without which the outside term
(ZFS ARC 5.01 GiB against this container's Cached 1.65) cannot be attributed
from a boot at all.

And `devtools/SPEED-MODE-BRIEFING-BLOCK.md` gains the memory.peak rule: it is a
LIFETIME mark with no reset (the file is nobody:nogroup in this LXC), xsn26b
inherited ~95.1 GiB of it from xsn25's death, and a boot seat quotes it ONLY as
a delta against the launch baseline the launcher now prints.

LOCAL: 163 passed / 0 failed across the touched weg2 suites (serving venv,
-p no:randomly). ruff: 9 findings on front.py, all 9 reproduce on a pristine
checkout of the base 3a0b46e -- none new. No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…at already carries W22

A built-but-unwired guard is the sgl-project#464 / sgl-project#1017 class, so the latch now rides the
same loop as the level verdict -- and the SAME CLOCK, which matters: `gaps_seen`
then counts THAT loop's own blindness, not another sampler's. Boot weg2xsn26b
was killed by the global host OOM killer while the level verdict never fired,
because at its cadence the last reading before the blind window was 82.28 GiB
and the climb covered the remaining 13.6 GiB in 4-6 s.

* the loop now ticks at `min(0.5, host_watermark_period_s)` -- the fast end of
  the ordered 200-500 ms band -- and the LEVEL test gates itself on `_level_due`
  so W22's own period is unchanged;
* ONE `read_cgroup_pressure` per tick feeds the latch, and the level verdict
  reuses it: the two can never disagree about the reading they graded;
* a latch goes down the SAME NAMED TEARDOWN as W22 (`do_stop("W98
  Weg2HostRateLatched")`) -- the user's 2026-09-08 order is a controlled
  teardown, never a kernel kill and never "accept the risk";
* a RATE-GAP is logged and counted but NEVER torn down: the loop kept running,
  it just could not look. Blindness is a finding, not a verdict.

Four ratchet tests read the loop's own source: it constructs the latch, feeds
it, routes the latch to the named teardown, does NOT tear down on a gap, runs
faster than the level test, and grades both halves from one reading.

ALSO IN THIS COMMIT'S SCOPE BUT OUTSIDE THIS REPO (gpu-arb is not a git repo,
noted rather than silently split): `gpu-arb/weg2/hostsample_v2.sh` -- the six v1
columns keep their names, order and meaning so every v1 reader keeps working,
and six are APPENDED (host_memavailable_gib, root_current_gib, root_file_gib,
root_anon_gib, root_shmem_gib, root_slab_gib) plus a `sampler_version` field.
Cadence 0.5 s with sub-second timestamps, so a gap is VISIBLE as a timestamp
jump instead of inferred from a row count. Smoked: 8 rows at 0.3 s.
Its header carries the honest note that on THIS container root == the serving
cgroup (`/proc/self/cgroup` reads `0::/.lxc`, no child holds the ranks), so the
root_* columns duplicate the ones before them BY CONSTRUCTION and the genuinely
new information is `host_memavailable_gib` -- without which the outside term
(ZFS ARC 5.01 GiB against this container's Cached 1.65) cannot be attributed
from a boot at all.

And `devtools/SPEED-MODE-BRIEFING-BLOCK.md` gains the memory.peak rule: it is a
LIFETIME mark with no reset (the file is nobody:nogroup in this LXC), xsn26b
inherited ~95.1 GiB of it from xsn25's death, and a boot seat quotes it ONLY as
a delta against the launch baseline the launcher now prints.

LOCAL: 163 passed / 0 failed across the touched weg2 suites (serving venv,
-p no:randomly). ruff: 9 findings on front.py, all 9 reproduce on a pristine
checkout of the base 3a0b46e -- none new. No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…re reading per tick, COUNTED

[20b]'s commit message and its comment both said "ONE read_cgroup_pressure per
tick feeds the latch, and the level verdict reuses it: the two can never
disagree about the reading they graded". The loop took TWO -- `_pr_fast` for the
latch and a second call behind the `_level_due` gate for the level verdict.
Counted at b0bdf4d: 2.

AND MY OWN RATCHET DID NOT HOLD IT. `test_both_halves_grade_the_same_reading`
carried exactly that docstring and asserted only that the string
`_pr_fast = host_ledger.read_cgroup_pressure()` APPEARS in the loop body. It
stayed green at two readings and would have stayed green at ten: the DOCSTRING
and the ASSERTION of one test measured different things. Found by the train
seat's count, not by the test whose job it was.

WHAT CHANGES, and the honest size of it: `pr = _pr_fast`. Two readings lie
milliseconds apart, so at the measured 2.4-3.3 GiB/s they differ by ~10 MiB and
no verdict moves. The defect was never the number -- it was the CLAIM, and a
claim the code does not keep is how the next reader is told the two halves
cannot disagree when in fact they can.

THE TEST NOW COUNTS THE PROPERTY:
  assertEqual(body.count("read_cgroup_pressure()"), 1)
instead of asserting a substring, plus `pr = _pr_fast` by name. Verified it
would have caught this: the same assertion against b0bdf4d's loop body reads
2, i.e. red.

CLASS, and it is the eighth in a family this branch has been collecting: rc,
line count, process visibility, interpreter, hull name, intermediate state,
cross-boot counter -- and now a test whose docstring promises more than its
assertion measures. All of them are signals that LOOK like they carry the
information and only pass it along. The remedy is the same every time: count or
compare the property, never read the first thing that mentions it.

LOCAL: 18 in the file, 119 passed / 0 failed over the touched weg2 suites
(serving venv, -p no:randomly). No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…re reading per tick, COUNTED

[20b]'s commit message and its comment both said "ONE read_cgroup_pressure per
tick feeds the latch, and the level verdict reuses it: the two can never
disagree about the reading they graded". The loop took TWO -- `_pr_fast` for the
latch and a second call behind the `_level_due` gate for the level verdict.
Counted at b0bdf4d: 2.

AND MY OWN RATCHET DID NOT HOLD IT. `test_both_halves_grade_the_same_reading`
carried exactly that docstring and asserted only that the string
`_pr_fast = host_ledger.read_cgroup_pressure()` APPEARS in the loop body. It
stayed green at two readings and would have stayed green at ten: the DOCSTRING
and the ASSERTION of one test measured different things. Found by the train
seat's count, not by the test whose job it was.

WHAT CHANGES, and the honest size of it: `pr = _pr_fast`. Two readings lie
milliseconds apart, so at the measured 2.4-3.3 GiB/s they differ by ~10 MiB and
no verdict moves. The defect was never the number -- it was the CLAIM, and a
claim the code does not keep is how the next reader is told the two halves
cannot disagree when in fact they can.

THE TEST NOW COUNTS THE PROPERTY:
  assertEqual(body.count("read_cgroup_pressure()"), 1)
instead of asserting a substring, plus `pr = _pr_fast` by name. Verified it
would have caught this: the same assertion against b0bdf4d's loop body reads
2, i.e. red.

CLASS, and it is the eighth in a family this branch has been collecting: rc,
line count, process visibility, interpreter, hull name, intermediate state,
cross-boot counter -- and now a test whose docstring promises more than its
assertion measures. All of them are signals that LOOK like they carry the
information and only pass it along. The remedy is the same every time: count or
compare the property, never read the first thing that mentions it.

LOCAL: 18 in the file, 119 passed / 0 failed over the touched weg2 suites
(serving venv, -p no:randomly). No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…e launch moment charges both terms at once

THE MEASUREMENT CORRECTED THE DESIGN, and the number is the whole commit.

(b) The order asked for `projected = now + min(rate x lookahead, remaining)`.
Replayed against weg2xsn27's own v2 sampler series that is strictly WORSE than
the plain feasibility test: the leg climbed at ~1 GiB/s for its first six
seconds, so a rate-bounded projection stays SILENT through a leg that was
already impossible. At the leg's FIRST row:

    71.08 GiB now + 27.20 GiB of WEG2-XCHG-PLAN still to write = 98.28
    against the 95.90 mark

THE LEG NEVER FITTED. Nothing about its slope was the finding. So the test is
`now + remaining_leg_gib`, it needs no rate at all, and it fires 7.8 s before
the sampler goes blind instead of 1.2 s. The rate keeps its job exactly where
there is no plan to read (`remaining=None`, unchanged behaviour).

Can-fail, measured on the same rows: the rate form first reaches the mark at
t=6.579 -- six seconds and 7.4 GiB later, with the 33 s blind window about to
open and the kernel reaping inside it.

(c) `launch_moment_peak_gib`: origin + anon_load_peak + ring_fill, SUMMED.
weg2xsn27 predicted `run_peak=93.93 excess=-0.50` and named the RUN moment as
binding, then died at the LAUNCH moment at ~96: group D's ranks loaded weights
(anon 17.8 -> 23.0) WHILE writing the ring (shmem 49.4 -> 60.4) -- nonreclaim
67.2 -> 82.5 in THIRTEEN SECONDS, and `R1 READY group=D` arrived 38 s after the
kill. The two are the same seconds; a model that takes them in sequence names
the wrong moment. A `max()` model misses it by construction, and a test pins
that.

Tests: 24 in the file. The replay fires at the FIRST sample with the verbatim
98.28, the rate form is shown watching six seconds of the same doomed leg, a
healthy leg whose plan fits never latches, and the no-plan path is unchanged.

OUTSIDE THIS REPO (gpu-arb is not a git repo, named rather than silently split):
`hostsample_v2.sh` -> v3, with `psi_mem_full_total_us_delta`,
`psi_io_full_total_us_delta` and `tick_s`. PSI as a TOTAL DELTA per tick, not
an instantaneous avg10, and that choice is the point: the counter BRIDGES A
STALL. During weg2xsn27's 33 s sampler hole the avg10 figures would have been
read before and after and said nothing about the hole; the total delta carries
exactly what accumulated INSIDE it. Smoked: 16 columns, version 3, psi_io delta
non-zero on a quiet box, tick 0.408 s.

STILL OPEN AND NAMED, not silently skipped: (a) the latch must run from LAUNCH,
not from READY. Measured: the front's guard loop emits its first
`WEG2-HOST WATERMARK` line 42 s AFTER the kill, because it starts only once
both groups report READY -- so the most dangerous window in the whole boot (the
startup sleep leg, D loading weights and writing the ring at once) is
structurally UNGUARDED. That is a lifecycle change to where the loop is
started, not a line inside it, and it gets its own commit rather than a rushed
one at the end of this context.

LOCAL: 24 in the file, serving venv, -p no:randomly. No boot, no GPU, no
/dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…e launch moment charges both terms at once

THE MEASUREMENT CORRECTED THE DESIGN, and the number is the whole commit.

(b) The order asked for `projected = now + min(rate x lookahead, remaining)`.
Replayed against weg2xsn27's own v2 sampler series that is strictly WORSE than
the plain feasibility test: the leg climbed at ~1 GiB/s for its first six
seconds, so a rate-bounded projection stays SILENT through a leg that was
already impossible. At the leg's FIRST row:

    71.08 GiB now + 27.20 GiB of WEG2-XCHG-PLAN still to write = 98.28
    against the 95.90 mark

THE LEG NEVER FITTED. Nothing about its slope was the finding. So the test is
`now + remaining_leg_gib`, it needs no rate at all, and it fires 7.8 s before
the sampler goes blind instead of 1.2 s. The rate keeps its job exactly where
there is no plan to read (`remaining=None`, unchanged behaviour).

Can-fail, measured on the same rows: the rate form first reaches the mark at
t=6.579 -- six seconds and 7.4 GiB later, with the 33 s blind window about to
open and the kernel reaping inside it.

(c) `launch_moment_peak_gib`: origin + anon_load_peak + ring_fill, SUMMED.
weg2xsn27 predicted `run_peak=93.93 excess=-0.50` and named the RUN moment as
binding, then died at the LAUNCH moment at ~96: group D's ranks loaded weights
(anon 17.8 -> 23.0) WHILE writing the ring (shmem 49.4 -> 60.4) -- nonreclaim
67.2 -> 82.5 in THIRTEEN SECONDS, and `R1 READY group=D` arrived 38 s after the
kill. The two are the same seconds; a model that takes them in sequence names
the wrong moment. A `max()` model misses it by construction, and a test pins
that.

Tests: 24 in the file. The replay fires at the FIRST sample with the verbatim
98.28, the rate form is shown watching six seconds of the same doomed leg, a
healthy leg whose plan fits never latches, and the no-plan path is unchanged.

OUTSIDE THIS REPO (gpu-arb is not a git repo, named rather than silently split):
`hostsample_v2.sh` -> v3, with `psi_mem_full_total_us_delta`,
`psi_io_full_total_us_delta` and `tick_s`. PSI as a TOTAL DELTA per tick, not
an instantaneous avg10, and that choice is the point: the counter BRIDGES A
STALL. During weg2xsn27's 33 s sampler hole the avg10 figures would have been
read before and after and said nothing about the hole; the total delta carries
exactly what accumulated INSIDE it. Smoked: 16 columns, version 3, psi_io delta
non-zero on a quiet box, tick 0.408 s.

STILL OPEN AND NAMED, not silently skipped: (a) the latch must run from LAUNCH,
not from READY. Measured: the front's guard loop emits its first
`WEG2-HOST WATERMARK` line 42 s AFTER the kill, because it starts only once
both groups report READY -- so the most dangerous window in the whole boot (the
startup sleep leg, D loading weights and writing the ring at once) is
structurally UNGUARDED. That is a lifecycle change to where the loop is
started, not a line inside it, and it gets its own commit rather than a rushed
one at the end of this context.

LOCAL: 24 in the file, serving venv, -p no:randomly. No boot, no GPU, no
/dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…fourth criterion, and the first that separates

THREE CRITERIA WERE REFUTED ON THE NEGATIVE CONTROL BEFORE THIS ONE, all at the
desk and none at a boot. The pair that decides everything is weg2xsn24 (came
through its startup sleep leg and flipped, peak 90.5) against weg2xsn27 (reaped
at ~96 inside that same leg):

  now + remaining            xsn24 95.44 | xsn27 94.44 | mark 95.90
                             -> both silent, and the SURVIVOR is the closer one.
  current + max(0, fill_remaining - cushion)
                             -> FIRES ON xsn24 FIRST (95.99 at its leg start).
                                The cushion is a FLOW, not a stock: xsn24's
                                `current` did not move at all (91.80 -> 91.36)
                                while it wrote 14.80 GiB of shmem.
  fill_remaining from WEG2-XCHG-PLAN
                             -> xsn24 planned 27.15 GiB of d2h and landed 14.80
                                in shmem, so a plan-based remainder fires on the
                                survivor. Third over-pricing of one quantity.

WHAT SEPARATES THEM, measured on both whole boots:
  xsn24  75 s leg: d_shmem +14.80, d_cushion -20.54, d_current **-0.44**
                   worst cushion while shmem rose **2.67 GiB**,
                   ZERO samples under the floor in the ENTIRE boot
  xsn27  22 s leg: d_shmem +11.03, d_cushion -11.33, d_current **+4.51**
                   0.01 GiB with 16.17 GiB still to write; first sample under
                   the floor 00:13:03.631 (cushion 1.02), reaped inside a 33 s
                   stall
  xsn26b same shape, first at 23:23:47 (cushion 0.02)

So the test is `shmem is RISING and cushion < 1.5 GiB`. The floor sits 1.17 GiB
below the survivor's worst and 0.48 above the first firing sample of a dead
boot -- not a safety factor, the midpoint of a measured 2.66 GiB separation
between a boot that flipped and two the kernel reaped.

THE RISING GATE IS THE OTHER HALF, and it is why this is code and not a rule.
A remaining-bytes gate needs a TARGET the latch does not have. The rising gate
needs none -- and it structurally excludes the one-sample cushion dip at a
leg's END, where shmem stops growing. That exclusion was a JUDGEMENT CALL in my
first analysis (it is why the draft read 4.25 where a live latch reads 2.67,
caught by the train seat) and is now a property of the code: no sample is
dropped, the guard sees every one, and the gate decides.

`remaining_leg_gib` IS DELETED, not left beside the new path, and the dead
`if False:` block with it -- a term that no longer decides anything is the
present-but-unwired state this line has paid for three times. A test asserts
both, reading the signature and the CODE (the docstring names the deleted
parameter to explain it, and a bare substring check reads its own explanation --
the same shape that had to strip comments in the guard-loop test).

Sampler (gpu-arb, outside this repo, named not silently split): `cushion_gib`
column, smoked at 17 columns.

LOCAL: 88 passed / 0 failed over the touched weg2 suites, serving venv,
-p no:randomly. No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
… dead in production

[21b] was rejected and rightly so. I deleted `remaining_leg_gib` and brought the
SAME CONDITION BACK ONE NAME OVER: the whole cushion block hangs off
`if cushion_gib is not None` (host_ledger.py:1248), and the single production
call site (front.py:2308) passed neither argument, so `observe` fell through to
the old rate path. The fourth criterion was dead at the one place it has to
work, while 88 tests stayed green because every one of them passes the
arguments. THIRD instance of this class in this ticket -- remaining_leg_gib,
launch_moment_peak_gib, now cushion -- and the second time I produced it while
fixing it.

THE FIX IS ONE CALL, and the reader already carried the terms (checked before
building, because if it had not, THAT would have been the post):
`read_cgroup_pressure()` returns `file_gib` and `shmem_gib`. cushion =
file - shmem, from the SAME `_pr_fast` reading the level verdict grades, so the
two can never disagree about the moment they describe. An absent term stays
`None` and the latch keeps its rate path -- never read as `cushion=0`, which
would mean "no cushion left" and tear the boot down on a missing file.

THE RATCHET PINS REACHABILITY, NOT LOGIC, which is the whole lesson:
`test_the_call_site_passes_the_cushion` reads the production call site and
requires both arguments AND that they come from `_pr_fast`. Proven RED on the
rejected commit: at f2a371c there is no `shmem_gib` after
`rate_latch.observe(` at all. Pinning the NAME `remaining_leg_gib` would have
passed f2a371c; this pins the property.

Two more tests close the gap around it: the reader really carries both terms
(else the post moves there), and an absent term keeps the rate path instead of
latching.

COUNTING PROBE, per the order: `cushion_gib=` over python/sglang/srt/ -> 2
(host_ledger's parameter, front's argument); `rate_latch.observe(` call sites
carrying `cushion_gib=` -> 1, i.e. all of them.

LOCAL: 130 passed / 0 failed over the touched weg2 suites, ruff clean, serving
venv, -p no:randomly. No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…fourth criterion, and the first that separates

THREE CRITERIA WERE REFUTED ON THE NEGATIVE CONTROL BEFORE THIS ONE, all at the
desk and none at a boot. The pair that decides everything is weg2xsn24 (came
through its startup sleep leg and flipped, peak 90.5) against weg2xsn27 (reaped
at ~96 inside that same leg):

  now + remaining            xsn24 95.44 | xsn27 94.44 | mark 95.90
                             -> both silent, and the SURVIVOR is the closer one.
  current + max(0, fill_remaining - cushion)
                             -> FIRES ON xsn24 FIRST (95.99 at its leg start).
                                The cushion is a FLOW, not a stock: xsn24's
                                `current` did not move at all (91.80 -> 91.36)
                                while it wrote 14.80 GiB of shmem.
  fill_remaining from WEG2-XCHG-PLAN
                             -> xsn24 planned 27.15 GiB of d2h and landed 14.80
                                in shmem, so a plan-based remainder fires on the
                                survivor. Third over-pricing of one quantity.

WHAT SEPARATES THEM, measured on both whole boots:
  xsn24  75 s leg: d_shmem +14.80, d_cushion -20.54, d_current **-0.44**
                   worst cushion while shmem rose **2.67 GiB**,
                   ZERO samples under the floor in the ENTIRE boot
  xsn27  22 s leg: d_shmem +11.03, d_cushion -11.33, d_current **+4.51**
                   0.01 GiB with 16.17 GiB still to write; first sample under
                   the floor 00:13:03.631 (cushion 1.02), reaped inside a 33 s
                   stall
  xsn26b same shape, first at 23:23:47 (cushion 0.02)

So the test is `shmem is RISING and cushion < 1.5 GiB`. The floor sits 1.17 GiB
below the survivor's worst and 0.48 above the first firing sample of a dead
boot -- not a safety factor, the midpoint of a measured 2.66 GiB separation
between a boot that flipped and two the kernel reaped.

THE RISING GATE IS THE OTHER HALF, and it is why this is code and not a rule.
A remaining-bytes gate needs a TARGET the latch does not have. The rising gate
needs none -- and it structurally excludes the one-sample cushion dip at a
leg's END, where shmem stops growing. That exclusion was a JUDGEMENT CALL in my
first analysis (it is why the draft read 4.25 where a live latch reads 2.67,
caught by the train seat) and is now a property of the code: no sample is
dropped, the guard sees every one, and the gate decides.

`remaining_leg_gib` IS DELETED, not left beside the new path, and the dead
`if False:` block with it -- a term that no longer decides anything is the
present-but-unwired state this line has paid for three times. A test asserts
both, reading the signature and the CODE (the docstring names the deleted
parameter to explain it, and a bare substring check reads its own explanation --
the same shape that had to strip comments in the guard-loop test).

Sampler (gpu-arb, outside this repo, named not silently split): `cushion_gib`
column, smoked at 17 columns.

LOCAL: 88 passed / 0 failed over the touched weg2 suites, serving venv,
-p no:randomly. No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
… dead in production

[21b] was rejected and rightly so. I deleted `remaining_leg_gib` and brought the
SAME CONDITION BACK ONE NAME OVER: the whole cushion block hangs off
`if cushion_gib is not None` (host_ledger.py:1248), and the single production
call site (front.py:2308) passed neither argument, so `observe` fell through to
the old rate path. The fourth criterion was dead at the one place it has to
work, while 88 tests stayed green because every one of them passes the
arguments. THIRD instance of this class in this ticket -- remaining_leg_gib,
launch_moment_peak_gib, now cushion -- and the second time I produced it while
fixing it.

THE FIX IS ONE CALL, and the reader already carried the terms (checked before
building, because if it had not, THAT would have been the post):
`read_cgroup_pressure()` returns `file_gib` and `shmem_gib`. cushion =
file - shmem, from the SAME `_pr_fast` reading the level verdict grades, so the
two can never disagree about the moment they describe. An absent term stays
`None` and the latch keeps its rate path -- never read as `cushion=0`, which
would mean "no cushion left" and tear the boot down on a missing file.

THE RATCHET PINS REACHABILITY, NOT LOGIC, which is the whole lesson:
`test_the_call_site_passes_the_cushion` reads the production call site and
requires both arguments AND that they come from `_pr_fast`. Proven RED on the
rejected commit: at f2a371c there is no `shmem_gib` after
`rate_latch.observe(` at all. Pinning the NAME `remaining_leg_gib` would have
passed f2a371c; this pins the property.

Two more tests close the gap around it: the reader really carries both terms
(else the post moves there), and an absent term keeps the rate path instead of
latching.

COUNTING PROBE, per the order: `cushion_gib=` over python/sglang/srt/ -> 2
(host_ledger's parameter, front's argument); `rate_latch.observe(` call sites
carrying `cushion_gib=` -> 1, i.e. all of them.

LOCAL: 130 passed / 0 failed over the touched weg2 suites, ruff clean, serving
venv, -p no:randomly. No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…that kills these boots had no guard at all

MEASURED on weg2xsn27: group D emitted `WEG2-XCHG-PLAN dir=d2h` at 00:12:42, the
cushion went under the floor at 00:13:03.631, the kernel reaped at ~00:13:04 --
and the FRONT's guard loop printed its first `WEG2-HOST WATERMARK` line at
00:13:46. **64 s late, 42 s after the latch would have fired.**

The front is not slow. It is STARTED BY THIS LAUNCHER AFTER BOTH GROUPS, so the
most dangerous window of the whole boot -- the startup sleep leg, where D loads
weights into anon WHILE writing its dormant image into shmem -- is structurally
unguarded no matter how fast that loop ticks. [20b] wired the latch into the
loop that exists; this wires a loop into the window that had none.

`LaunchGuard`: same `RateLatch`, same cushion terms, ONE `read_cgroup_pressure`
per tick feeding both halves, armed BEFORE the first `launch_group(spec_p, ...)`
and disarmed exactly where `front_argv_for` builds the front -- a handover, not
a doubling. A latch in that window raises `Weg2HostLedgerRefused` carrying the
W98 line, so the boot stops by name instead of being reaped.

A DAEMON THREAD AND NOT AN ASYNCIO TASK, and that is not a style choice: the
launcher is synchronous here and blocks in `wait_ready` for minutes. A task
would not get a single tick in exactly the window this exists for.

Dry runs arm nothing (`None if dry else LaunchGuard(...)`), pinned by a test and
confirmed on a real dry run: rc=0, zero LAUNCH-GUARD lines.

RATCHET, red on f299988 where no launcher-side guard existed at all: the test
reads the launcher source and requires the arm to come BEFORE the first
launch_group and the handover to sit between that and `front_argv_for` -- an
ORDER check, not a presence check, because a guard armed after the groups is
exactly the defect this commit is about. Four more pin the one-reading rule, the
named refusal, the thread, and the dry-run exemption.

LOCAL: 114 passed / 0 failed over the touched weg2 suites, ruff clean, serving
venv, -p no:randomly. Dry-run rc=0. No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…ardown funnel

[21a] raised a bare `host_ledger.Weg2HostLedgerRefused` at launcher.py:10638.
That site sits AFTER `launch_group(spec_p)` AND `launch_group(spec_d)` -- both
groups are live -- and only `Weg2LaunchRefused` reaches the teardown funnel. So
the latch stopped the boot by name and LEFT SIX RANK PROCESSES HOLDING THREE
CARDS. A stopped boot that orphans its ranks is worse than the breach it
prevented, and it is the exact class sgl-project#1294 and sgl-project#1248 exist for. Both ratchets
caught it on the train:

  test_weg2_launcher_funnel_completeness_1294 -- "raise(s) on the post-spawn
    reachable path bypass the funnel: [('main', 10638, ...)]"
  test_weg2_launcher_teardown_1248 -- "post-spawn inline raises: 6 != 5"

THE FIX FOLLOWS sgl-project#1294'S OWN PRECEDENT and widens the CLASS instead of rewriting
the raise site: `Weg2LaunchHostLatched(Weg2LaunchRefused,
host_ledger.Weg2HostLedgerRefused)`, exactly as `Weg2ChunkCardMismatch` is both
a launch refusal and a ValueError. It is both things because it IS both things
-- a host-ledger verdict that has to tear a launch down -- and narrowing it to
a launch type would have moved the defect instead of fixing it: the ledger's
own callers catch `Weg2HostLedgerRefused`, and
test_weg2_rate_latch_1361.py:440 asserts that name. Verified by invocation:
`isinstance` true for BOTH bases. No layer inversion; this module already
imports host_ledger.

Both branches of the condition smoked, per the request: armed (`LaunchGuard`
start/stop, verdict None on a quiet box) and `_launch_guard is None` (dry run,
zero LAUNCH-GUARD lines). Dry-run rc=2 is the pre-existing W21 arm ladder,
identical on the base -- not this commit, and independently confirmed on
1f7b2d8.

LOCAL: 57 passed / 0 failed over the two ratchet suites plus the sgl-project#1361 file,
serving venv, -p no:randomly. No boot, no GPU, no /dev/shm.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…ardown funnel

[21a] raised a bare `host_ledger.Weg2HostLedgerRefused` at launcher.py:10638.
That site sits AFTER `launch_group(spec_p)` AND `launch_group(spec_d)` -- both
groups are live -- and only `Weg2LaunchRefused` reaches the teardown funnel. So
the latch stopped the boot by name and LEFT SIX RANK PROCESSES HOLDING THREE
CARDS. A stopped boot that orphans its ranks is worse than the breach it
prevented, and it is the exact class sgl-project#1294 and sgl-project#1248 exist for. Both ratchets
caught it on the train:

  test_weg2_launcher_funnel_completeness_1294 -- "raise(s) on the post-spawn
    reachable path bypass the funnel: [('main', 10638, ...)]"
  test_weg2_launcher_teardown_1248 -- "post-spawn inline raises: 6 != 5"

THE FIX FOLLOWS sgl-project#1294'S OWN PRECEDENT and widens the CLASS instead of rewriting
the raise site: `Weg2LaunchHostLatched(Weg2LaunchRefused,
host_ledger.Weg2HostLedgerRefused)`, exactly as `Weg2ChunkCardMismatch` is both
a launch refusal and a ValueError. It is both things because it IS both things
-- a host-ledger verdict that has to tear a launch down -- and narrowing it to
a launch type would have moved the defect instead of fixing it: the ledger's
own callers catch `Weg2HostLedgerRefused`, and
test_weg2_rate_latch_1361.py:440 asserts that name. Verified by invocation:
`isinstance` true for BOTH bases. No layer inversion; this module already
imports host_ledger.

Both branches of the condition smoked, per the request: armed (`LaunchGuard`
start/stop, verdict None on a quiet box) and `_launch_guard is None` (dry run,
zero LAUNCH-GUARD lines). Dry-run rc=2 is the pre-existing W21 arm ladder,
identical on the base -- not this commit, and independently confirmed on
1f7b2d8.

LOCAL: 57 passed / 0 failed over the two ratchet suites plus the sgl-project#1361 file,
serving venv, -p no:randomly. No boot, no GPU, no /dev/shm.

(cherry picked from commit 01bb311)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…icle at the desk

The desk run of RedHatAI/Qwen3.5-4B-FP8-dynamic (7.48 GiB, 32 layers, LLLA x8)
exposed three constants measured on the 27B that say so NOWHERE.

(3) SIGMA H COMES FROM THE PREVIOUS BOOT'S CENSUS. The 4B would have been
handed `Sigma H 48240 MiB = per card the LARGER of [tag census 47512, measured
dormant image 48672]` -- weg2xsn25's figures digit for digit, a 47 GiB ring for
a 7.48 GiB model -- and died in W48 plus three W51, none of which says "wrong
model". Hen-and-egg: the record can only come from a boot, and the boot cannot
start because it is priced from the old one.
  `model_digest()` + `refuse_foreign_image()` (W99 Weg2ModelIdentityMismatch),
  AN EMPTY DIGEST IS UNKNOWN AND NOT MATCHING -- pre-sgl-project#1362 records must not pass
  as "same model", which would re-open the hole for exactly the boots most
  likely to hit it. The refusal names the way forward: one boot of the new model,
  or the manifest anchor WITH its printed surcharge.
  sgl-project#1359 STANDS: the census LEVEL is right and sigma_h_from_manifests undercounts
  40.6 % on the 27B (32783 vs 47512 MiB). So the manifest route carries
  MANIFEST_CENSUS_SURCHARGE = 1.449 as a NAMED, PRINTED term that states it is
  BORROWED from another model and is the conservative direction (bigger ring,
  never smaller), retired by the model's own census after its first boot.
  AND IT IS WIRED, not merely built: the launcher stamps the digest into the
  record at the `dormant_image_sample` call site, with a ratchet that reads that
  call site. That ratchet exists because sgl-project#1361's [21b] shipped a criterion whose
  production call site passed nothing -- the fourth instance of built-but-unwired
  in this ticket family, and the reason this one is checked before it is claimed.

(1) THE CALIBRATION HAS NO MODEL. P_PP_STAGE_RATIO_SCORES=(32,18,14) and
MEASURED_MS_PER_LAYER are a 64-layer measurement from boot bsscale; on 32 layers
the chain ends in a BARE ValueError from the cut solver ("the anchor stage 1
holds 18 linear and 0 attention layers in the calibration cut") -- the only
unnamed refusal in the launch path.
  `read_pp_calibration()` reads one file per model keyed by the CHECKPOINT
  digest, `refuse_foreign_calibration()` raises W99 naming the missing measuring
  run. Four properties are checked, each because its absence is a real failure
  mode: schema, digest match (a file named for one model holding another's
  numbers is the exact transfer this stops), ms and counts validated AS A PAIR
  (the solver consumes them together; separately they let ms from one cut be
  divided by layer counts from another), and `refused` as an ABSENCE WITH A
  REASON -- "the calibration refused" and "nobody measured" are different states
  and only one is fixed by booking a window.

(4) `--served-model-name "Qwen3.8-27B"` WAS A LITERAL ON EVERY BOOT. It is what
the front routes on, the load drivers address and every probe asserts against,
so a 4B boot would have answered under the 27B's name -- a silent identity swap
in the one field whose whole job is identity. Now derived from the model path,
overridable, and a snapshot path resolves to the repo rather than the commit.
  SIDE EFFECT FOUND AND CLOSED: deriving it moved the FORM KEY
  (237e36801f4b -> 984effac8fb6 on a dry run) and would have invalidated every
  ring table this line owns -- for a string change on a model that did not move
  a byte. `--served-model-name` is a LABEL and is now in
  FORM_KEY_EXCLUDED_FLAGS; `--model-path` carries the identity and always was in
  the key. Dry run after: `form key ... MATCHES`.

Tests: 20, red-first against the 4B config double and byte-identical for the
27B, plus the reachability ratchet and the danger-direction case (an empty
digest must never pass silently).

LOCAL: 132 passed / 3 failed. All three are pre-existing on the base
cd01231 and none is from this commit: two are the [21a] funnel defect the
train seat caught, already fixed by 01bb311 on weg2/rate-latch-1361-0913
which this base predates, and one is the known sgl-project#1349 stale-fixture red. ruff
clean. No boot, no GPU, no /dev/shm.

(cherry picked from commit 8509b9e)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
… value to the flag, and never mint a leading '-'

Boot weg2xsn25's FIRST launch (log ...0913_065608) died on

  argument --admin-api-key: expected one argument

`admin_key.mint()` is `secrets.token_urlsafe(32)`, which draws from base64url
-- A-Za-z0-9 plus '-' and '_' -- so 1 key in 64 begins with a hyphen. Emitted
as the two-token form `["--admin-api-key", "-xY..."]`, argparse reads the VALUE
as an option and the launch is dead. The boot seat measured the rate directly:
3076 of 200000 mints = 1.54 %, which is 1/64 to two digits.

A dud roughly every 65th boot, a message that names the flag and never the
cause, and no dry run reproduces it because the next mint is fine. That is the
worst shape a defect can have: it looks like a different bug every time it
fires, and it never fires while you are looking for it.

TWO INDEPENDENT FIXES, because the value travels into argv, /proc, a file and
an HTTP header, and a rule that holds in one of those is not a rule:

  mint()           re-draws while the token starts with '-'. Entropy cost
                   log2(63/64) = 0.023 bits out of 256. Re-draw rather than
                   lstrip(), which would shorten the key and bias its first
                   character while passing the same test.
  admin_key_flag() emits ONE token, `--admin-api-key=<value>`. This makes the
                   argv safe for ANY key -- including one an operator passes by
                   hand, which never goes through mint() at all.

A KEY STARTING WITH TWO HYPHENS IS RARER AND WORSE (1/4096): `_flag_pairs`
would read it as a flag of its own and MOVE THE P FORM KEY, invalidating every
ring table for that boot. The welded form closes that too; verified, all four
spellings hash identically (test).

TWO GUARDS HAD TO BE RETIGHTENED, and the second is the interesting one:

  * the helper's own pin moved from the two-token form to the welded one;
  * `test_the_front_argv_carries_the_path_not_the_key` asserted
    `assertNotIn("--admin-api-key", argv)` -- an EXACT-TOKEN membership test.
    With the welded spelling that guard would have gone on passing while the
    argv carried `--admin-api-key=<secret>`: a leak detector that silently
    stops detecting. It now filters BY PREFIX.
  * `redact_argv` likewise only knew the two-token form. A redactor that stops
    matching is worse than none, because the call site still believes it
    redacted and the key lands in a log that gets pasted into records and
    tickets. Both spellings now.

TESTS (test_weg2_admin_key_1275.py, 35 total, +7 and 2 retightened):
  200k mints carry no leading '-' -- the boot seat's own sample size, so this
  test is at least as sensitive as the measurement that found the defect;
  the mint is still full length and non-repeating (a truncation would pass the
  first test);
  CAN-FAIL: keys "-xY7abc", "--weird", "-" are built and PARSED by a real
  argparse under the welded form;
  CAN-FAIL COUNTER-PROOF: the same key under the old two-token form raises
  SystemExit -- a can-fail that never shows the failure asserts nothing;
  the P form key is identical across all four spellings;
  the redactor knows both.
  Red-first on 9c22254: 7 failed / 31 passed, including the 200k mint case
  and all three can-fail subtests.
  ruff clean. Reachability + W-code uniqueness suites: 103 passed together.

(cherry picked from commit 7d9e8af802227cc7e187312a8353fd399a65c2f0)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…dger: DEATH-SAMPLE, refused by name

BOOT BLOCKER. Boot weg2xsn25 died on 2026-09-13 between 07:01:14 (first rank
lost) and 07:04:16 (no live schedulers). At 07:03:59Z, three minutes into that
cascade, its sampler wrote

    run_residual_gib = 34.61,  load_class = "idle",  pids = [],  pids_asked = []

The load class was TRUE and meaningless: a box with no live ranks has no queue,
so it measures idle. What that sample actually measured is whatever else was on
the host. The ledger took it as this line's RUN-MOMENT RESIDUAL FLOOR and every
arm gained ~28 GiB:

    run origin  6.56 -> 34.61 GiB
    run_peak    95.18 -> 132.49 / 127.55 / 125.08 GiB  vs hard bound 94.43

No arm funded. Measured on THREE independent trees (9c22254, 7d9e8af802,
train 3ce5920), and decisively on ONE tree across the record's own change
with no code difference between the runs: 95.22 GiB at 06:51:24Z, 123.23 GiB
after xsn25 died.

A RECORD IS NOT A COMMIT. It is not picked, not gated, not rolled back -- and it
prices every boot that follows. Our merge discipline cannot catch that class at
all, which is why the guard belongs in the reader.

THE EVIDENCE WAS ALREADY IN EVERY SAMPLE EVER WRITTEN, with no consumer:
`pids`. #1350e rejects samples measured DURING A FLIP; nothing rejected one
measured DURING A DEATH. Third instance of the shape, after #1350b (Sigma H
raise refused) and #1350e.

THE FILTER, in the reader, by name:

  (1) pids EMPTY -> DEATH-SAMPLE. A run-moment residual is a statement about
      THIS LINE's processes; with none alive there is nothing for it to be a
      statement about. The refusal prints boot, group, timestamp and the
      rejected number, and says why load_class=idle is "true and empty".
  (2) the cgroup kill counter, newly stamped into every sample by the writer
      (`cg_oom_kill`, read here rather than passed in, so no caller has to be
      taught and no sample can be written without it). A sample whose counter
      sits ABOVE the LOWEST one this record holds for the same boot was taken
      after something in this cgroup was killed. Absolute, not a delta: the
      sidecar is append-only, so successive samples of one boot ARE the
      baseline; a delta against a baseline the record does not carry would be a
      number nobody can check. `None` (unreadable) is never scored as zero --
      an absent counter is not evidence of health.

  MIN AND NOT MAX, and this cost a test: the first draft compared each sample
  against the MAXIMUM counter for its boot, which includes the sample itself,
  so the guard could never fire and its unit test went green proving nothing.
  Caught by the test failing for the right reason, fixed to the minimum.

WHAT IS NOT BUILT, named rather than implied: the order lists four health
conditions. Two are enforced above from evidence the record carries. The other
two -- "no exception/traceback entry" and "no STOP verdict" -- live in the boot
LOGS, not in the sidecar, and a reader of the ledger has no access to them. A
field for either would be a new write-side stamp with no consumer until the
next boot writes one; I have not added an unwired one.

VERIFIED, serving form, form key 24eb56724d73, quiet box:
    rc=0, ARM 1, run origin 6.62 GiB, run_peak 95.25 vs hard bound 94.43,
    0 REFUSED, and the printed refusal names the sample:
    "34.61 (boot weg2xsn25, group D, at 2026-09-13T07:03:59Z) DEATH-SAMPLE:
     NO live rank (pids=0 of 0 asked) ..."
That is back in band with this morning's 95.18 GiB on the same form.

TESTS (test_weg2_death_sample_1361.py, 7 new): the two REAL xsn25 samples as
verbatim fixtures; the 34.61 sample must not become the floor; the refusal must
name boot, timestamp and number; load_class=idle explicitly asserted as NOT
evidence of health (a guard keyed on it would have passed this sample); the
healthy 9-pid sample still read; a kill between two samples of one boot caught;
an unreadable counter not scored as healthy; and the writer's stamp asserted so
the filter is not reading a field nobody writes.
Red-first on 7d9e8af802: 4 failed / 3 passed, including the floor case.
93 green across the affected suites. ruff: unchanged (the 6 on host_ledger.py
are present at the parent).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…ath: the pids key must be PRESENT

[22-fix5] wrote

    _alive = len(e.get("pids") or [])
    if _alive == 0: -> DEATH-SAMPLE

which reads an ABSENT field as an empty one. Every record written before
`pids` existed was then refused as a death sample. Measured by the train seat
on the pick, and reproduced here: weg2sn6s's origin fell from 7.63 GiB to 0.0
and two sgl-project#1325 tests went red --

    test_the_origin_falls_to_the_launch_reading_once_the_floor_is_repriced
    test_the_origin_line_prints_both_the_stored_and_the_repriced_figure

THIS IS MY DEFECT, NOT AN OBSOLETE EXPECTATION, and the distinction was the
question the train seat put to me. The sgl-project#1325 contract says: when a run-moment
sample is rejected, the origin falls to the LAUNCH READING and the line says
`AT OR ABOVE`. My filter made it fall to 0.0 instead and replaced the text with
a refusal. The old semantics are right and the new rejecter has to preserve
them; the tests stay as they are.

It is also the same error twice from the same seat: [22-fix] refused every
record whose model digest was empty, and [22-fix2] had to build a transition
path to undo it. Four commits later I scored an absent field as a positive
finding again, in the other direction.

THE DISCRIMINATOR, and it is already in the data: the real weg2xsn25 death
sample carries `pids: []` AND `pids_asked: []` -- the keys are PRESENT and
empty, which is the sampler reporting that it LOOKED and found nothing. A
legacy record has no such keys at all and says nothing either way. So the guard
now requires `"pids" in e` before it judges, which keeps it strict on the
sample it was built for and silent on records that cannot testify.

VERIFIED:
  * the 2 ONLY-NEW reds are gone. test_weg2_run_residual_currency_1325 now
    reads 3 failed / 25 passed against the base's 3 failed / 18 passed -- the
    SAME three pre-existing names (sn6s_record_no_longer_exceeds,
    quiet_launch_still_charges, arm_line_carries_both_currencies), measured on
    c67f767 in a scratch worktree.
  * the xsn25 death sample is STILL caught: dry run, serving form, form key
    24eb56724d73, quiet box -> rc=0, ARM 1, REFUSED 0, run origin 6.68 GiB,
    run_peak 95.31 vs hard bound 94.43, 2 DEATH-SAMPLE lines.
  * 3 new tests, red-first on be3162a (2 failed / 8 passed): a record with
    no pids key is not a death sample; the sgl-project#1325 origin contract (8.0 and
    `AT OR ABOVE`) pinned HERE as well, so whoever touches this filter sees
    from the guard's own side what it may not move; and the complement -- a
    PRESENT but empty pids set is still refused, so the guard cannot be
    softened into uselessness.
  ruff clean.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…dger: DEATH-SAMPLE, refused by name

BOOT BLOCKER. Boot weg2xsn25 died on 2026-09-13 between 07:01:14 (first rank
lost) and 07:04:16 (no live schedulers). At 07:03:59Z, three minutes into that
cascade, its sampler wrote

    run_residual_gib = 34.61,  load_class = "idle",  pids = [],  pids_asked = []

The load class was TRUE and meaningless: a box with no live ranks has no queue,
so it measures idle. What that sample actually measured is whatever else was on
the host. The ledger took it as this line's RUN-MOMENT RESIDUAL FLOOR and every
arm gained ~28 GiB:

    run origin  6.56 -> 34.61 GiB
    run_peak    95.18 -> 132.49 / 127.55 / 125.08 GiB  vs hard bound 94.43

No arm funded. Measured on THREE independent trees (9c22254, 7d9e8af802,
train 3ce5920), and decisively on ONE tree across the record's own change
with no code difference between the runs: 95.22 GiB at 06:51:24Z, 123.23 GiB
after xsn25 died.

A RECORD IS NOT A COMMIT. It is not picked, not gated, not rolled back -- and it
prices every boot that follows. Our merge discipline cannot catch that class at
all, which is why the guard belongs in the reader.

THE EVIDENCE WAS ALREADY IN EVERY SAMPLE EVER WRITTEN, with no consumer:
`pids`. #1350e rejects samples measured DURING A FLIP; nothing rejected one
measured DURING A DEATH. Third instance of the shape, after #1350b (Sigma H
raise refused) and #1350e.

THE FILTER, in the reader, by name:

  (1) pids EMPTY -> DEATH-SAMPLE. A run-moment residual is a statement about
      THIS LINE's processes; with none alive there is nothing for it to be a
      statement about. The refusal prints boot, group, timestamp and the
      rejected number, and says why load_class=idle is "true and empty".
  (2) the cgroup kill counter, newly stamped into every sample by the writer
      (`cg_oom_kill`, read here rather than passed in, so no caller has to be
      taught and no sample can be written without it). A sample whose counter
      sits ABOVE the LOWEST one this record holds for the same boot was taken
      after something in this cgroup was killed. Absolute, not a delta: the
      sidecar is append-only, so successive samples of one boot ARE the
      baseline; a delta against a baseline the record does not carry would be a
      number nobody can check. `None` (unreadable) is never scored as zero --
      an absent counter is not evidence of health.

  MIN AND NOT MAX, and this cost a test: the first draft compared each sample
  against the MAXIMUM counter for its boot, which includes the sample itself,
  so the guard could never fire and its unit test went green proving nothing.
  Caught by the test failing for the right reason, fixed to the minimum.

WHAT IS NOT BUILT, named rather than implied: the order lists four health
conditions. Two are enforced above from evidence the record carries. The other
two -- "no exception/traceback entry" and "no STOP verdict" -- live in the boot
LOGS, not in the sidecar, and a reader of the ledger has no access to them. A
field for either would be a new write-side stamp with no consumer until the
next boot writes one; I have not added an unwired one.

VERIFIED, serving form, form key 24eb56724d73, quiet box:
    rc=0, ARM 1, run origin 6.62 GiB, run_peak 95.25 vs hard bound 94.43,
    0 REFUSED, and the printed refusal names the sample:
    "34.61 (boot weg2xsn25, group D, at 2026-09-13T07:03:59Z) DEATH-SAMPLE:
     NO live rank (pids=0 of 0 asked) ..."
That is back in band with this morning's 95.18 GiB on the same form.

TESTS (test_weg2_death_sample_1361.py, 7 new): the two REAL xsn25 samples as
verbatim fixtures; the 34.61 sample must not become the floor; the refusal must
name boot, timestamp and number; load_class=idle explicitly asserted as NOT
evidence of health (a guard keyed on it would have passed this sample); the
healthy 9-pid sample still read; a kill between two samples of one boot caught;
an unreadable counter not scored as healthy; and the writer's stamp asserted so
the filter is not reading a field nobody writes.
Red-first on 7d9e8af802: 4 failed / 3 passed, including the floor case.
93 green across the affected suites. ruff: unchanged (the 6 on host_ledger.py
are present at the parent).

(cherry picked from commit be3162a)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…ath: the pids key must be PRESENT

[22-fix5] wrote

    _alive = len(e.get("pids") or [])
    if _alive == 0: -> DEATH-SAMPLE

which reads an ABSENT field as an empty one. Every record written before
`pids` existed was then refused as a death sample. Measured by the train seat
on the pick, and reproduced here: weg2sn6s's origin fell from 7.63 GiB to 0.0
and two sgl-project#1325 tests went red --

    test_the_origin_falls_to_the_launch_reading_once_the_floor_is_repriced
    test_the_origin_line_prints_both_the_stored_and_the_repriced_figure

THIS IS MY DEFECT, NOT AN OBSOLETE EXPECTATION, and the distinction was the
question the train seat put to me. The sgl-project#1325 contract says: when a run-moment
sample is rejected, the origin falls to the LAUNCH READING and the line says
`AT OR ABOVE`. My filter made it fall to 0.0 instead and replaced the text with
a refusal. The old semantics are right and the new rejecter has to preserve
them; the tests stay as they are.

It is also the same error twice from the same seat: [22-fix] refused every
record whose model digest was empty, and [22-fix2] had to build a transition
path to undo it. Four commits later I scored an absent field as a positive
finding again, in the other direction.

THE DISCRIMINATOR, and it is already in the data: the real weg2xsn25 death
sample carries `pids: []` AND `pids_asked: []` -- the keys are PRESENT and
empty, which is the sampler reporting that it LOOKED and found nothing. A
legacy record has no such keys at all and says nothing either way. So the guard
now requires `"pids" in e` before it judges, which keeps it strict on the
sample it was built for and silent on records that cannot testify.

VERIFIED:
  * the 2 ONLY-NEW reds are gone. test_weg2_run_residual_currency_1325 now
    reads 3 failed / 25 passed against the base's 3 failed / 18 passed -- the
    SAME three pre-existing names (sn6s_record_no_longer_exceeds,
    quiet_launch_still_charges, arm_line_carries_both_currencies), measured on
    c67f767 in a scratch worktree.
  * the xsn25 death sample is STILL caught: dry run, serving form, form key
    24eb56724d73, quiet box -> rc=0, ARM 1, REFUSED 0, run origin 6.68 GiB,
    run_peak 95.31 vs hard bound 94.43, 2 DEATH-SAMPLE lines.
  * 3 new tests, red-first on be3162a (2 failed / 8 passed): a record with
    no pids key is not a death sample; the sgl-project#1325 origin contract (8.0 and
    `AT OR ABOVE`) pinned HERE as well, so whoever touches this filter sees
    from the guard's own side what it may not move; and the complement -- a
    PRESENT but empty pids set is still refused, so the guard cannot be
    softened into uselessness.
  ruff clean.
(cherry picked from commit 44dd367)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…ared sentence four tests assert

MEASURED ON cb67120 ITSELF, not inferred: test_weg2_flip_ratchet_1350.py
reads 4 failed / 46 passed at the tip. The pair fix5+fix5b is already picked
there, so these four are LIVE on the line right now.

    NoDoubleCount1350::test_a_pre_1350_record_is_covered_by_its_interleaved_flag
    NoDoubleCount1350::test_an_origin_floor_sampled_during_a_flip_may_not_carry_the_term_too
    OriginAndResidualCorrections1350e::test_W95_still_fires_when_there_is_no_launch_reading_to_fall_back_on
    OriginAndResidualCorrections1350e::test_a_mid_flip_run_moment_sample_is_rejected_in_favour_of_the_launch_reading

THE CAUSE IS PROSE, NOT SEMANTICS, and that makes it worse rather than better.
[22-fix5] rewrote the SHARED tail of the rejection sentence for every caller:

    was:  "... REJECTED: interleaved, i.e. measured DURING a flip, so they
           already contain the permanent step `flip_ratchet_gib` charges
           separately (#1350e)"
    became: "... REJECTED. An entry marked DEATH-SAMPLE was measured while this
           line was not alive (sgl-project#1361); the others are interleaved, ..."

The four tests assert the literal "REJECTED: interleaved". The behaviour they
guard is UNTOUCHED -- the failing run still reports origin 6.44, source=launch,
and names the rejected 7.49 -- so this broke four green tests for nothing but a
sentence. The cheapest possible regression, and mine.

FIX: the #1350e tail is emitted VERBATIM when it is the only reason that
applied, and the combined wording only when a death sample is actually among
the rejected. Each rejected entry already carries its own reason in its own
string; this tail names the RULE, so it now names the rule that applied.

ALSO IN THIS COMMIT, and it is the part worth keeping: the death filter is
placed AFTER the #1350e check instead of before it. The two rejecters overlap
-- a fixture that passes `pids=[]` to `dormant_image_sample` gets a PRESENT and
empty process set, exactly like the xsn25 death sample -- so whichever runs
first owns the printed reason. The established rule keeps its samples and the
new one judges only what #1350e lets through. This costs the xsn25 case
nothing: that sample carries `sampled_at_flip_epoch=0`, `_mid` is False, and it
still reaches the death filter. An added case rather than a shadowed one.

WHY THE TRAIN'S UNION DID NOT SEE IT: its targeted union covered the files it
judged affected; mine enumerated all 34 test files that mention `host_ledger`
(base 9 failed / 1003 passed on c67f767, cand 13 / 1009, GONE empty). The
four names are the whole ONLY-NEW set and they live in a file the narrower
union did not open. The lesson is the day's own: a scope chosen by judgement is
a scope that can miss, and the cheap defence is to derive it mechanically --
"every test file that imports the module I touched".

VERIFIED on cb67120 + this commit: test_weg2_flip_ratchet_1350.py,
test_weg2_run_residual_currency_1325.py and test_weg2_death_sample_1361.py
together read 3 failed / 78 passed, and those three are the known pre-existing
sgl-project#1325 names (sn6s_record_no_longer_exceeds, quiet_launch_still_charges,
arm_line_carries_both_currencies) measured identically on the bare tip.
ruff clean.

(cherry picked from commit b5f4b30)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…mpare BEFORE the overwrite

`_derive_d_l2_budget` read, in straight-line code with no branch between:

    share = float(ns.d_cap_rank_share)
    if rec_share is not None:
        share = rec_share                       # the overwrite
    if rec_share is not None and rec_share > share + 1e-9:
        raise Weg2L2ShareBelowInstalled(...)    # compares y against y

After the overwrite `share == rec_share`, so `rec_share > share + 1e-9` is
false on every input. W89x could not fire. The refusal existed in the source,
in the W-code census and in the comments, and was dead.

That is worse than no refusal. A named guard is read downstream as proof the
case is covered -- by this seat twice in one day. Same family as a reader
nobody calls and a comment promising a property the code lacks, except that
here the condition is killed by its own precedent rather than by a missing
consumer.

TWO HALVES OF ONE DEFECT. The boot seat reported `S_D=1 pinned` while the ARM
line said `S_D=2`, because the sizing record silently overrides
`--d-cap-rank-share`. The ONE thing that would have told anybody is this
refusal -- the one that cannot fire. [23b] closed the visibility half
(`source=record|flag|unknown` on the ARM line) before the reachability half
existed; this closes the reachability half. They belong in one framing.

THE TEXT WAS ALSO WRONG, and fixing only the reachability would have shipped an
unreadable message: it says "max(v)/sum(v) = {rec_share}, above
--d-cap-rank-share {share}" while `share` had already become `rec_share` -- it
would print a number against itself. The flag value is now captured as
`_flag_share` before anything overwrites it, and the message names that.
(Independently reached by the train seat on its own read of :4735-4751.)

Behaviour for every input that is NOT refused is unchanged: the record still
wins as the share source (#1317n -- a measured share is a reading, the flag is
a margin), it just no longer wins BEFORE the guard has looked.

TESTS (4, red-first on c73c361 for the case that could never fire):
  * a record share above the flag is refused by name, and the message names
    the FLAG it compared against;
  * the ordinary case still passes -- weg2sn6p's measured 0.3750 against the
    shipped default 0.4, the configuration every boot on this rig has run;
  * no record -> the flag stands and the terms say `source=flag`;
  * THE SHAPE, pinned in source: the W89x comparison must appear BEFORE
    `share = rec_share`. A behavioural test alone goes green again the day
    someone re-orders the lines, because the refusal would simply stop firing
    on inputs no test happens to supply. The order IS the property.

THE SHAPE TEST TRIPPED OVER ITS OWN SUBJECT FIRST, and the fix is worth
recording: it searched the raw source and matched `share = rec_share` inside
the comment that EXPLAINS the defect. That is sgl-project#1362 [22-fix3] again -- an
instrument that cannot tell its subject from a description of its subject
reports on the description. It now strips comment lines before searching.

SIBLING GREP for the same shape (`x = y` then a comparison of `y` against `x`)
across host_ledger.py and launcher.py: two hits, and only one is a defect.
launcher.py:4739 is this one. host_ledger.py:2575 (`floor = cg_nonreclaim_gib`
followed by `if cg_nonreclaim_gib >= floor`) is vacuously true by the same
mechanism, but its branch INTENDS to return the launch reading and does, so the
outcome is correct and the comparison is merely redundant. Named here rather
than changed: a true-by-construction test that yields the intended result is
not the same defect as a false-by-construction guard that yields none.
ruff clean.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…urces

Train-seat addendum to [23c], and the half it caught that the
reachability fix alone would have left broken.

[23c] made W89x able to fire and pinned the flag value as `_flag_share`
so the message no longer compares a number against itself. It still
named only ONE source. The record overrides the flag a few lines below
the guard, so a refusal naming one value leaves the reader unable to
tell which of the two actually sized the arm -- which is precisely the
gap that let the boot seat report S_D=1 while the ARM line said S_D=2.

The refusal now reads:

  max(v)/sum(v) = 0.5000 (source=record), above --d-cap-rank-share
  0.4000 (source=flag). BOTH NUMBERS AND BOTH SOURCES are named because
  the record SILENTLY OVERRIDES the flag a few lines below this guard ...

and says WHY the pair is there, so the next reader does not have to
rediscover the precedence from the source. Two assertions added to the
red-first case. No behaviour change beyond the text: the guard fires on
exactly the same inputs as in [23c]. ruff clean.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
… not latched after it

W98 fired 4 seconds before boot weg2xsn25's first OOM kill and prevented
nothing. The reason is structural, not a tuning failure: the STOP stops
ADMISSION, and the bytes that spent the cushion were D's own sleep leg, already
3.3 s into a 5.6 s RPC when the latch fired. You cannot recall bytes being
written by refusing new requests.

    07:00:50..07:01:09  cushion FLAT at 2.697 GiB, PSI 0.00
    ~07:01:07.6         the sleep leg starts (/release_memory_occupation)
    07:01:10.0 -> .5    cushion 2.591 -> 0.548 in ONE 0.5 s tick, shmem +2.26
    07:01:10.870        W98 latches, WEG2 STOP
    07:01:13.188        the sleep RPC RETURNS (ms=5572)
    07:01:14.6..24.8    first rank killed, global host OOM

WIDENING THE FLOOR IS NOT THE LEVER, and that was measured rather than assumed:
floors 1.0, 1.5, 2.0, 2.5, 2.60 and 2.69 GiB ALL latch on the SAME sample with
the SAME 4.1 s lead, because the cushion is flat for a minute and then vertical
inside one 0.5 s tick. Only 3.0 moves it one tick; 5.0 buys 46 s while firing 8
times on the SURVIVING boot weg2xsn24.

So the lever belongs where the arithmetic is still ordinary: 2.697 GiB of
cushion against a 4.32 GiB write, knowable ~3 s before the first byte.

THE GATE. `host_ledger.refuse_sleep_leg_deficit(cushion, need, margin, source,
group)` raises W100 Weg2SleepLegCushionDeficit, naming `cushion_gib=`,
`need_gib=`, `margin=` and `source=`. It is a `Weg2HostLedgerRefused`, so the
teardown funnel catches it like every other ledger refusal (the sgl-project#1294 lesson).

NO TUNABLE NUMBER IS INTRODUCED. It compares two MEASURED quantities and
refuses when one does not cover the other; `margin_gib` is supplied by the
caller and printed, never chosen here.

BOTH TERMS COME FROM READINGS THAT ALREADY EXIST AT THE CALL SITE. The cushion
is `file - shmem` from `read_cgroup_pressure` -- the SAME call the rate latch
is fed, so gate and latch can never disagree about the moment they describe.
The write size is the sidecar's own `shmem_delta_gib` for this group: the
measured growth of shmem across that group's last sleep leg, which is the
plan's own number for the quantity, and the only one available BEFORE the leg
runs. It is read from `self.measured_record` -- the same path this front
appends its own samples to, not a second spelling of it.

EITHER TERM UNREADABLE -> NO VERDICT, on both sides. `None` is not zero: an
unreadable cushion is not "no cushion left" and an unknown write size is not
"writes nothing". Both would turn a blind gate into a boot killer at the one
moment where a wrong refusal costs the whole window. A front with no sidecar
proceeds exactly as before this ticket.

WIRED AT THE REAL CALL SITE, and the tests execute it rather than reading it.
`_sleep_leg_gate(S)` runs inside `_drain_and_flip`'s gathered-leg block,
immediately before the `asyncio.gather` that issues
`/release_memory_occupation`. That placement is asserted two ways: the gate
must appear BEFORE the gather in source, and within 1200 characters of it, so
it cannot drift away from the leg it guards. Two further tests CALL
`_sleep_leg_gate` with a real sidecar file and a patched cgroup reading and
require it to raise on xsn25's numbers and stay silent on xsn26's. That is
deliberate: this week produced four defects where a built reader had no caller,
and the xsn26 class specifically -- a leg that died on a refusal whose unit
tests were all green because the D path never passed the terms through.

TESTS (8, red-first on c73c361: 8 failed / 0 passed):
  red on the xsn25 numbers (2.697 vs 4.32) with every field named;
  GREEN on weg2xsn26 (cushion 8.11 GiB; that boot came through its sleep leg,
    peak non-reclaimable 84.28 GiB over n=964, riegel never fired, oom_kill
    5 -> 5) -- the negative control, and the half that decides whether this is
    a gate or a boot killer;
  neither term guessed when missing; the class is a ledger refusal;
  plus the four call-site tests above.

NAMED, NOT CHANGED: `host_ledger.py:2575` (`floor = cg_nonreclaim_gib` followed
by `if cg_nonreclaim_gib >= floor`) is vacuously true by the same mechanism as
the dead W89x guard fixed in [23c] -- but its branch INTENDS to return the
launch reading and does, so the outcome is correct and the comparison is merely
redundant. A true-by-construction test with the intended result is not the same
defect as a false-by-construction guard with none, and touching it would put a
working path at risk for a cosmetic gain.
ruff clean.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…t each other on one line

B4n found it on the env publication, not this seat on its own field.

`assemble_slots(depth)` with `comparing=None` asks
`weight_exchange.inject_mode()`, which reads INJECT_ENV. The launcher
NEVER sets that for itself: `prepare_xchg_env` puts it only into the
dict handed to the ranks (launcher.py:3594), while the launcher sets
WEIGHT_SOURCE_ENV for its own process (:9631) and not this one.

So on a boot armed `authoritative`, [23a] printed

    bounce_slots=3        <- computed as if shadow, from the default
    bounce_inject=authoritative   <- from the argv, correct

on the SAME line. Two fields disagreeing about the same arm, and the
one that was wrong about what the ranks would do is the one nobody
would have checked -- a provenance field that misreports provenance is
worse than no field, because it is read as the answer.

`comparing` is now passed explicitly from the argv value, so both
fields describe the arm the ranks actually get: shadow -> 3 slots,
authoritative -> 2.

That [23a] shipped this at all is the days own lesson turned on its
author: I added the field to make a wrong attribution findable, and
the field itself carried one. The instrument found it -- printing the
state beside the number is what let B4n see the contradiction from
another file.

NOT FIXED HERE, and it belongs to whoever owns the launchers env
publication: a launcher-side `inject_mode()` still answers `shadow` by
default regardless of the boots arm. [23a]/[23e] no longer depend on
it, but any future reader of that function in the launcher process
has the same trap waiting.

Tests: 2 added (9 total in the file, all green). One pins that
`comparing=` is passed rather than defaulted; one pins that the two
spellings produce 3 and 2 slots. ruff clean.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…e reading now name their input

(23a) THE BOUNCE STATE, BESIDE THE BOUNCE TERM.

The exchange seat measured THREE distinct states that all price 2.16 GiB:
(depth=1, comparing=True), (depth=2, comparing=False), and (depth=2 under the
pre-sgl-project#1335 expression that under-priced by one widest layer). The figure alone
cannot tell a correctly priced shallow arm from the underpricing.

I proved that the hard way and it is why this commit exists rather than being a
tidy-up. I read 2.16 off my own dry run, told the exchange seat the cause was
`depth=1`, and was wrong: my branch forked from 9c22254 and simply did not
carry his fix. It was his THIRD case. Same number, three causes, wrong one
picked -- two messages after he had written the three cases out for me. The
wrong attribution had already gone to the boot seat and the coordinator.

Every ARM line now carries `bounce_depth=`, `bounce_slots=`, `bounce_inject=`
beside `xchg_bounce=`, and `bounce_state=absent` when the arm pins no bounce at
all -- an unpriced state and a state priced at defaults must not share a
spelling, the rule the ratchet fields already obey. `slots` comes from
`xchg_bounce.assemble_slots`, the one authority (sgl-project#1335), never a second
expression. `inject_mode` is resolved in the launcher's own process, which is
exactly the term a desk run and a boot can disagree about -- printing it makes
the disagreement readable instead of hidden inside an equal number.

(23b) WHICH INPUT PRODUCED S_D.

`_derive_d_l2_budget` lets a measured ownership vector in the sizing record
OVERRIDE `--d-cap-rank-share`, silently. The boot seat read `S_D=1` off its own
sizing table while the ARM line said `S_D=2`. Effective and unprinted: sgl-project#896.

The line now reads `S_D=2 (sd_share=0.3750 source=record)` or `source=flag`.
A terms dict written before this commit prints `source=unknown`, NOT `flag`:
absence cannot testify, and guessing the flag would be the same error as
reading an absent `pids` field as an empty one ([22-fix5b], four commits ago).

BOTH ARE PRINT-ONLY. Neither moves an arm. `xchg_bounce_prov` stops at
`choose` and never enters `price` -- a term only the printer needs must not be
threaded through the pricing path, where a later reader would have to prove it
does not move a number. A test asserts it is absent from `price`'s signature.

MEASURED, serving form, form key 24eb56724d73, quiet box (cards 4/4/4):
  ARM S=1 M=2400 S_D=4 (sd_share=0.4000 source=flag): anchors=9.49 rings=12.83
  overhead=0.89 xchg_bounce=2.86 bounce_depth=2 bounce_slots=3
  bounce_inject=shadow host_weights=46.40 ratchet_per_flip=8.70 ...
2.86 on the same invocation that printed 2.16 before -- which is how the
misattribution surfaced at all.

TESTS (7, red-first on c73c361: 5 failed / 2 passed). The load-bearing one
is `test_two_states_with_the_SAME_price_are_distinguishable`: two differently
priced states with an equal term must produce different lines. That is the
property whose absence produced the wrong attribution, asserted directly rather
than via the fields that happen to implement it today.
ruff clean.

(cherry picked from commit 20ddcde)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…mpare BEFORE the overwrite

`_derive_d_l2_budget` read, in straight-line code with no branch between:

    share = float(ns.d_cap_rank_share)
    if rec_share is not None:
        share = rec_share                       # the overwrite
    if rec_share is not None and rec_share > share + 1e-9:
        raise Weg2L2ShareBelowInstalled(...)    # compares y against y

After the overwrite `share == rec_share`, so `rec_share > share + 1e-9` is
false on every input. W89x could not fire. The refusal existed in the source,
in the W-code census and in the comments, and was dead.

That is worse than no refusal. A named guard is read downstream as proof the
case is covered -- by this seat twice in one day. Same family as a reader
nobody calls and a comment promising a property the code lacks, except that
here the condition is killed by its own precedent rather than by a missing
consumer.

TWO HALVES OF ONE DEFECT. The boot seat reported `S_D=1 pinned` while the ARM
line said `S_D=2`, because the sizing record silently overrides
`--d-cap-rank-share`. The ONE thing that would have told anybody is this
refusal -- the one that cannot fire. [23b] closed the visibility half
(`source=record|flag|unknown` on the ARM line) before the reachability half
existed; this closes the reachability half. They belong in one framing.

THE TEXT WAS ALSO WRONG, and fixing only the reachability would have shipped an
unreadable message: it says "max(v)/sum(v) = {rec_share}, above
--d-cap-rank-share {share}" while `share` had already become `rec_share` -- it
would print a number against itself. The flag value is now captured as
`_flag_share` before anything overwrites it, and the message names that.
(Independently reached by the train seat on its own read of :4735-4751.)

Behaviour for every input that is NOT refused is unchanged: the record still
wins as the share source (#1317n -- a measured share is a reading, the flag is
a margin), it just no longer wins BEFORE the guard has looked.

TESTS (4, red-first on c73c361 for the case that could never fire):
  * a record share above the flag is refused by name, and the message names
    the FLAG it compared against;
  * the ordinary case still passes -- weg2sn6p's measured 0.3750 against the
    shipped default 0.4, the configuration every boot on this rig has run;
  * no record -> the flag stands and the terms say `source=flag`;
  * THE SHAPE, pinned in source: the W89x comparison must appear BEFORE
    `share = rec_share`. A behavioural test alone goes green again the day
    someone re-orders the lines, because the refusal would simply stop firing
    on inputs no test happens to supply. The order IS the property.

THE SHAPE TEST TRIPPED OVER ITS OWN SUBJECT FIRST, and the fix is worth
recording: it searched the raw source and matched `share = rec_share` inside
the comment that EXPLAINS the defect. That is sgl-project#1362 [22-fix3] again -- an
instrument that cannot tell its subject from a description of its subject
reports on the description. It now strips comment lines before searching.

SIBLING GREP for the same shape (`x = y` then a comparison of `y` against `x`)
across host_ledger.py and launcher.py: two hits, and only one is a defect.
launcher.py:4739 is this one. host_ledger.py:2575 (`floor = cg_nonreclaim_gib`
followed by `if cg_nonreclaim_gib >= floor`) is vacuously true by the same
mechanism, but its branch INTENDS to return the launch reading and does, so the
outcome is correct and the comparison is merely redundant. Named here rather
than changed: a true-by-construction test that yields the intended result is
not the same defect as a false-by-construction guard that yields none.
ruff clean.

(cherry picked from commit cdf3bd4)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…urces

Train-seat addendum to [23c], and the half it caught that the
reachability fix alone would have left broken.

[23c] made W89x able to fire and pinned the flag value as `_flag_share`
so the message no longer compares a number against itself. It still
named only ONE source. The record overrides the flag a few lines below
the guard, so a refusal naming one value leaves the reader unable to
tell which of the two actually sized the arm -- which is precisely the
gap that let the boot seat report S_D=1 while the ARM line said S_D=2.

The refusal now reads:

  max(v)/sum(v) = 0.5000 (source=record), above --d-cap-rank-share
  0.4000 (source=flag). BOTH NUMBERS AND BOTH SOURCES are named because
  the record SILENTLY OVERRIDES the flag a few lines below this guard ...

and says WHY the pair is there, so the next reader does not have to
rediscover the precedence from the source. Two assertions added to the
red-first case. No behaviour change beyond the text: the guard fires on
exactly the same inputs as in [23c]. ruff clean.

(cherry picked from commit 7ea0d00)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
… not latched after it

W98 fired 4 seconds before boot weg2xsn25's first OOM kill and prevented
nothing. The reason is structural, not a tuning failure: the STOP stops
ADMISSION, and the bytes that spent the cushion were D's own sleep leg, already
3.3 s into a 5.6 s RPC when the latch fired. You cannot recall bytes being
written by refusing new requests.

    07:00:50..07:01:09  cushion FLAT at 2.697 GiB, PSI 0.00
    ~07:01:07.6         the sleep leg starts (/release_memory_occupation)
    07:01:10.0 -> .5    cushion 2.591 -> 0.548 in ONE 0.5 s tick, shmem +2.26
    07:01:10.870        W98 latches, WEG2 STOP
    07:01:13.188        the sleep RPC RETURNS (ms=5572)
    07:01:14.6..24.8    first rank killed, global host OOM

WIDENING THE FLOOR IS NOT THE LEVER, and that was measured rather than assumed:
floors 1.0, 1.5, 2.0, 2.5, 2.60 and 2.69 GiB ALL latch on the SAME sample with
the SAME 4.1 s lead, because the cushion is flat for a minute and then vertical
inside one 0.5 s tick. Only 3.0 moves it one tick; 5.0 buys 46 s while firing 8
times on the SURVIVING boot weg2xsn24.

So the lever belongs where the arithmetic is still ordinary: 2.697 GiB of
cushion against a 4.32 GiB write, knowable ~3 s before the first byte.

THE GATE. `host_ledger.refuse_sleep_leg_deficit(cushion, need, margin, source,
group)` raises W100 Weg2SleepLegCushionDeficit, naming `cushion_gib=`,
`need_gib=`, `margin=` and `source=`. It is a `Weg2HostLedgerRefused`, so the
teardown funnel catches it like every other ledger refusal (the sgl-project#1294 lesson).

NO TUNABLE NUMBER IS INTRODUCED. It compares two MEASURED quantities and
refuses when one does not cover the other; `margin_gib` is supplied by the
caller and printed, never chosen here.

BOTH TERMS COME FROM READINGS THAT ALREADY EXIST AT THE CALL SITE. The cushion
is `file - shmem` from `read_cgroup_pressure` -- the SAME call the rate latch
is fed, so gate and latch can never disagree about the moment they describe.
The write size is the sidecar's own `shmem_delta_gib` for this group: the
measured growth of shmem across that group's last sleep leg, which is the
plan's own number for the quantity, and the only one available BEFORE the leg
runs. It is read from `self.measured_record` -- the same path this front
appends its own samples to, not a second spelling of it.

EITHER TERM UNREADABLE -> NO VERDICT, on both sides. `None` is not zero: an
unreadable cushion is not "no cushion left" and an unknown write size is not
"writes nothing". Both would turn a blind gate into a boot killer at the one
moment where a wrong refusal costs the whole window. A front with no sidecar
proceeds exactly as before this ticket.

WIRED AT THE REAL CALL SITE, and the tests execute it rather than reading it.
`_sleep_leg_gate(S)` runs inside `_drain_and_flip`'s gathered-leg block,
immediately before the `asyncio.gather` that issues
`/release_memory_occupation`. That placement is asserted two ways: the gate
must appear BEFORE the gather in source, and within 1200 characters of it, so
it cannot drift away from the leg it guards. Two further tests CALL
`_sleep_leg_gate` with a real sidecar file and a patched cgroup reading and
require it to raise on xsn25's numbers and stay silent on xsn26's. That is
deliberate: this week produced four defects where a built reader had no caller,
and the xsn26 class specifically -- a leg that died on a refusal whose unit
tests were all green because the D path never passed the terms through.

TESTS (8, red-first on c73c361: 8 failed / 0 passed):
  red on the xsn25 numbers (2.697 vs 4.32) with every field named;
  GREEN on weg2xsn26 (cushion 8.11 GiB; that boot came through its sleep leg,
    peak non-reclaimable 84.28 GiB over n=964, riegel never fired, oom_kill
    5 -> 5) -- the negative control, and the half that decides whether this is
    a gate or a boot killer;
  neither term guessed when missing; the class is a ledger refusal;
  plus the four call-site tests above.

NAMED, NOT CHANGED: `host_ledger.py:2575` (`floor = cg_nonreclaim_gib` followed
by `if cg_nonreclaim_gib >= floor`) is vacuously true by the same mechanism as
the dead W89x guard fixed in [23c] -- but its branch INTENDS to return the
launch reading and does, so the outcome is correct and the comparison is merely
redundant. A true-by-construction test with the intended result is not the same
defect as a false-by-construction guard with none, and touching it would put a
working path at risk for a cosmetic gain.
ruff clean.

(cherry picked from commit f71126a)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…t each other on one line

B4n found it on the env publication, not this seat on its own field.

`assemble_slots(depth)` with `comparing=None` asks
`weight_exchange.inject_mode()`, which reads INJECT_ENV. The launcher
NEVER sets that for itself: `prepare_xchg_env` puts it only into the
dict handed to the ranks (launcher.py:3594), while the launcher sets
WEIGHT_SOURCE_ENV for its own process (:9631) and not this one.

So on a boot armed `authoritative`, [23a] printed

    bounce_slots=3        <- computed as if shadow, from the default
    bounce_inject=authoritative   <- from the argv, correct

on the SAME line. Two fields disagreeing about the same arm, and the
one that was wrong about what the ranks would do is the one nobody
would have checked -- a provenance field that misreports provenance is
worse than no field, because it is read as the answer.

`comparing` is now passed explicitly from the argv value, so both
fields describe the arm the ranks actually get: shadow -> 3 slots,
authoritative -> 2.

That [23a] shipped this at all is the days own lesson turned on its
author: I added the field to make a wrong attribution findable, and
the field itself carried one. The instrument found it -- printing the
state beside the number is what let B4n see the contradiction from
another file.

NOT FIXED HERE, and it belongs to whoever owns the launchers env
publication: a launcher-side `inject_mode()` still answers `shadow` by
default regardless of the boots arm. [23a]/[23e] no longer depend on
it, but any future reader of that function in the launcher process
has the same trap waiting.

Tests: 2 added (9 total in the file, all green). One pins that
`comparing=` is passed rather than defaulted; one pins that the two
spellings produce 3 and 2 slots. ruff clean.

(cherry picked from commit f1f8710)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
… as a flag with one source

weg2xsn27 died in `shm,pinned`, and the sgl-project#1358 reader attributed the WHOLE
10.565 GiB of that region to FIVE slot holders x 2.113 GiB from ONE emit site
(weight_exchange_bounce.py:427). The buffer is
`widest x assemble_slots(depth)` and `slots = depth + 1` under shadow, so one
step of depth is one widest layer per holder:

    depth=2   slots=3   2.113 GiB/holder   10.566 GiB over 5 holders
    depth=1   slots=2   1.409 GiB/holder    7.044 GiB over 5 holders
    saving                                  3.52 GiB

at the sleep leg, in the region the boot died in. gdncov INT8's widest layer is
756323776 B = 721.3 MiB; the holder count is measured, not assumed.

DEFAULT 2 IS BYTE-IDENTICAL -- the flag exposes the constant, it does not move
it. Every boot so far reproduces exactly.

ONE SOURCE, and that is the load-bearing half rather than the flag itself.
`--xchg-bounce-depth` reaches `xchg_bounce_terms_for_arm(..., bounce_depth)`
and `choose_host_ledger(..., bounce_depth=...)`, so the HOST-LEDGER TERM and
`assemble_slots` price the same number, and the value travels to the ranks
inside the published bounce terms -- P and D read it back through
`read_published_terms`, never through a second path. A second spelling of this
depth is precisely how `2.16 GiB` came to have three indistinguishable causes
(sgl-project#1361 [23a]), and that is the defect this wiring exists to not repeat.
No call site derives a depth from the constant behind the flag's back any
more, and a test asserts that ABSENCE rather than a particular spelling.

THE COST IS NOT PRICED HERE, deliberately: depth=1 leaves one pipeline stage
fewer, and nothing on this rig has measured what that does to flip duration.
Operator order 2026-09-13: measured at the metal, never estimated. This commit
claims a memory number and nothing about throughput.

TESTS (7, red-first on 5dc356a):
  depth=1 -> 2 slots, depth=2 -> 3;
  the ledger term falls 10.566 -> 7.044 GiB, saving 3.52, as NUMBERS;
  the default is still 2 and the flag parses;
  the arm helper takes the depth instead of reading the constant;
  EXECUTION SMOKE of the publication path: `publish_terms` ->
    `read_published_terms` round-trips the depth AND the buffer bytes for both
    1 and 2, because if the depth does not survive that round trip the ranks
    price a different buffer than the ledger did.

ONE DEPENDENCY, NAMED RATHER THAN ASSERTED: the ARM line's `bounce_depth=`
field comes from sgl-project#1361 [23a] (20ddcde), which this base has NOT picked. So
this file does not assert the printed field -- it asserts the absence that must
hold either way. When the five-chain lands, `_bounce_prov["depth"]` reads
`bounce_depth` and the printed field follows the flag for free. A test that
asserted the field here would have gone red for the base rather than for a
defect.

The +1.18 GiB forecast gap stays NAMED-UNATTRIBUTED: xsn27's ratchet was
charged at full size (`ratchet_charged=8.70 source=SERIES`, binding weg2xsn25
8.697) for the one flip it ran, so it cannot be the term, and no second ratchet
is introduced on a size coincidence.

(cherry picked from commit b20880c)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
… that says so

TWO HALVES OF ONE DEFECT, both measured on this rig, in ONE commit because
fixing either alone leaves the other able to produce the same wrong line.

(1) THE LAUNCHER AND THE RANKS READ DIFFERENT SOURCES. `prepare_xchg_env`
    publishes INJECT_ENV into the dict handed to the RANKS (launcher.py:3594)
    and never into the launcher's OWN environment, so every launcher-process
    caller of `inject_mode()` got the `shadow` default regardless of what the
    boot was armed with. S6 fix E fixed the IMPORT-TIME half of this and left
    the publication half standing.

    Measured consequence, sgl-project#1361 [23a]: a boot armed `authoritative` printed
    `bounce_slots=3` (computed as if shadow) beside `bounce_inject=authoritative`
    (from the argv) on the SAME line. Two fields contradicting each other about
    one arm, and the wrong one was the one describing what the ranks would do.

    `inject_mode(explicit=None)` is the one source: a caller that HAS the argv
    value passes it and gets an answer about the BOOT; the environment stays
    the source for the ranks, which have no argv. `inject_authoritative`
    threads it through. An `explicit` that is not one of the two real modes is
    IGNORED, not trusted -- a typo must never silently claim `authoritative`,
    which is exactly the direction INJECT_MODE_UNSET exists to guard: claiming
    ownership of 27 GiB of weights on evidence that did not parse.

(2) AN ABSENT MODE WAS READ AS A SHADOW FINDING. The bounce emitter's
    `inject=` field was a two-way branch on `== INJECT_AUTHORITATIVE`, so a
    record with NO mode fell into the `NOTHING-COMPARED` arm -- a claim that a
    SHADOW leg had graded nothing, invented out of missing evidence. The
    `mode=` field one column to its left already printed `unset`. Two fields on
    one line contradicting each other about the same absence.

    The branch is now three-way: `NOTHING-COMPARED` is reached only for a mode
    that IS shadow, and an absent mode prints `inject=unset`.

PRIOR ART, found by the gate BEFORE the first edit and the reason this commit
is small: `INJECT_MODE_UNSET` was ALREADY defined for this ticket in
`weight_exchange.py`, with a docstring that names this exact hazard and its
direction, and it was ALREADY used by the emitter's `mode=` field
(weight_exchange_bounce.py:677). Only the `inject=` field never learned it.
This finishes a constant that was built and half-wired rather than adding one --
the present-but-unwired family, this time as a consumer that skipped one of two
sibling fields.

TESTS (5, red-first on c73c361: 4 failed / 1 passed -- red in BOTH
directions as ordered):
  an authoritative boot must not read shadow (INJECT_ENV popped, which is the
    launcher's real state, not a contrived one);
  a typo is ignored rather than trusted, in both `inject_mode` and
    `inject_authoritative`;
  the ranks still read the environment -- the unchanged path stays unchanged;
  an absent mode prints `unset`, and NOTHING-COMPARED is reachable only from a
    mode that IS shadow;
  both fields name the same absence (the constant appears twice, once per
    field), so the two can no longer disagree.

Import smoke: all six weg2 modules import. ruff clean. The two reds in
test_weg2_xchg_bounce_1332 (`test_the_bound_is_the_widest_layer_never_the_mean`,
`test_this_rigs_instance_of_the_expression`) are PRE-EXISTING on the tip and
present in the base column's 11 -- they belong to the sgl-project#1335 slot change, not
to this commit.

(cherry picked from commit b1cb6bd)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…s the ledger's count

MEASURED THREE WAYS on boot weg2xsn28, all 7.044 GiB of assemble buffer while
the ARM line charged 2.160:

  filesystem, 0 holders at teardown
      /dev/shm/weg2-xchg-<epoch>/bounce.bin.{c0,c1,p1,p2,p4} = 5 x 1.409 GiB
  cgroup sampler, d_shmem across the source leg        +7.043 GiB
  the lane's OWN HOST-SLOT lines                 4.226 + 2.818 = 7.044 GiB

COUNTER-PROOF that the instrument is sound, same method same boot: the host
ring summed to 46.40 GiB against `host_weights=46.40` -- exact. The ledger
priced the ring right and the bounce wrong, so this is not a tmpfs or
sparse-file artefact. ALL FIVE ARE CONCURRENT (the two legs overlap 115 s of
120 s), so it is a sum and not a peak; reducing the count is a lane change, not
an accounting one.

THE TERM IS NOT MERELY UNDER-MEASURED -- IT CONTRADICTS ITS OWN BOOT. The lane
printed 7.044 GiB in the same log, two minutes before the ledger priced 2.16.
Second bookkeeping against its own publication, in my file.

(1) `BounceTerms.n_lanes`, and `total_bytes = buffer_bytes * n_lanes +
    staging_bytes`. Default 1 is byte-identical to every pre-sgl-project#1358 caller.
    NO LITERAL: `n_lanes` rides with the term's INPUTS through
    `_TERM_FIELDS`/`publish_terms`, so a rank RECOMPUTES the total instead of
    holding one it cannot check -- the rule that tuple already existed for
    ("two 384 MiB staging figures from different factorisations").
    Replay: 5 lanes -> buffer 7.044 GiB, 6 lanes -> 8.453. Asserted as numbers.

(2) THE LANE CHECKS THE LEDGER. `group_descs_by_pair(descs)` IS the lane
    enumeration -- it is what produces the `p<pair>` / `c<card>` keys that name
    the files. The leg driver now compares the priced `n_lanes` against
    `len()` of it and refuses W68 BEFORE the first allocation, naming both
    counts, the per-lane buffer size and the unpriced byte total. An
    under-priced bounce does not fail at the leg; it fails later as a cushion
    nobody can account for, which is exactly how weg2xsn28 died.

(3) THE CUSHION BECOMES A RESERVED TERM, not only a prediction.
    `cushion_floor_reserve_gib(bounce_total_gib)` = the floor plus what sits in
    shmem at serving. THE FLOOR IS IMPORTED, never restated:
    `RATE_LATCH_CUSHION_FLOOR_GIB`, the same 1.50 the [21b] guard reads at
    runtime. Two spellings of one threshold is how an arm funds a boot the
    guard then tears down -- sgl-project#1361 [23a]'s lesson in the other direction, and a
    test asserts both sides read the one constant.

WHY BOTH HALVES IN ONE COMMIT: weg2xsn28 armed at run_peak 86.79 against reap
95.90 -- 9.11 GiB of room, W97=0, the first xsn2x arm that funded itself -- and
then latched W98 NINE SECONDS after `state=serving`, before any flip, cushion
0.99 against floor 1.50, short 0.51 GiB. An arm cannot lose at the run moment
what it never counted at the launch moment. Pricing alone would make the
refusal honest; reserving alone would guard a number still computed wrong.

WITH THE HONEST TERM, xsn28's own arm reads 86.79 + 4.88 = 91.67 against 95.90
-- still funding, 4.2 GiB of room. The correction costs that boot nothing; it
only stops the latch being a surprise.

TESTS (11 + 3 subtests, red-first on 992ba41: 9 failed / 2 passed).
Includes: one lane byte-identical; the two replay numbers; no literal lane
count in `bounce_terms`; the count round-trips through the publication for 1/5/6
with the totals equal; the leg driver compares against its own enumeration and
does so BEFORE `run_bounce_leg`; the floor is imported and a negative bounce
cannot shrink it.
Neighbouring suites (1332, depth flag, arm provenance, death sample): 39 green.
ruff: unchanged from the base.

NEXT, NAMED NOT BUILT: the launcher still passes no `n_lanes`, so it prices 1
and the new W68 would refuse a real five-lane leg. The count must come from the
same plan the leg builds its descs from -- and it now has a guarded consumer,
which is the right order to build it in: the guard exists before the producer,
so a wrong producer is caught rather than believed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…s the ledger's count

MEASURED THREE WAYS on boot weg2xsn28, all 7.044 GiB of assemble buffer while
the ARM line charged 2.160:

  filesystem, 0 holders at teardown
      /dev/shm/weg2-xchg-<epoch>/bounce.bin.{c0,c1,p1,p2,p4} = 5 x 1.409 GiB
  cgroup sampler, d_shmem across the source leg        +7.043 GiB
  the lane's OWN HOST-SLOT lines                 4.226 + 2.818 = 7.044 GiB

COUNTER-PROOF that the instrument is sound, same method same boot: the host
ring summed to 46.40 GiB against `host_weights=46.40` -- exact. The ledger
priced the ring right and the bounce wrong, so this is not a tmpfs or
sparse-file artefact. ALL FIVE ARE CONCURRENT (the two legs overlap 115 s of
120 s), so it is a sum and not a peak; reducing the count is a lane change, not
an accounting one.

THE TERM IS NOT MERELY UNDER-MEASURED -- IT CONTRADICTS ITS OWN BOOT. The lane
printed 7.044 GiB in the same log, two minutes before the ledger priced 2.16.
Second bookkeeping against its own publication, in my file.

(1) `BounceTerms.n_lanes`, and `total_bytes = buffer_bytes * n_lanes +
    staging_bytes`. Default 1 is byte-identical to every pre-sgl-project#1358 caller.
    NO LITERAL: `n_lanes` rides with the term's INPUTS through
    `_TERM_FIELDS`/`publish_terms`, so a rank RECOMPUTES the total instead of
    holding one it cannot check -- the rule that tuple already existed for
    ("two 384 MiB staging figures from different factorisations").
    Replay: 5 lanes -> buffer 7.044 GiB, 6 lanes -> 8.453. Asserted as numbers.

(2) THE LANE CHECKS THE LEDGER. `group_descs_by_pair(descs)` IS the lane
    enumeration -- it is what produces the `p<pair>` / `c<card>` keys that name
    the files. The leg driver now compares the priced `n_lanes` against
    `len()` of it and refuses W68 BEFORE the first allocation, naming both
    counts, the per-lane buffer size and the unpriced byte total. An
    under-priced bounce does not fail at the leg; it fails later as a cushion
    nobody can account for, which is exactly how weg2xsn28 died.

(3) THE CUSHION BECOMES A RESERVED TERM, not only a prediction.
    `cushion_floor_reserve_gib(bounce_total_gib)` = the floor plus what sits in
    shmem at serving. THE FLOOR IS IMPORTED, never restated:
    `RATE_LATCH_CUSHION_FLOOR_GIB`, the same 1.50 the [21b] guard reads at
    runtime. Two spellings of one threshold is how an arm funds a boot the
    guard then tears down -- sgl-project#1361 [23a]'s lesson in the other direction, and a
    test asserts both sides read the one constant.

WHY BOTH HALVES IN ONE COMMIT: weg2xsn28 armed at run_peak 86.79 against reap
95.90 -- 9.11 GiB of room, W97=0, the first xsn2x arm that funded itself -- and
then latched W98 NINE SECONDS after `state=serving`, before any flip, cushion
0.99 against floor 1.50, short 0.51 GiB. An arm cannot lose at the run moment
what it never counted at the launch moment. Pricing alone would make the
refusal honest; reserving alone would guard a number still computed wrong.

WITH THE HONEST TERM, xsn28's own arm reads 86.79 + 4.88 = 91.67 against 95.90
-- still funding, 4.2 GiB of room. The correction costs that boot nothing; it
only stops the latch being a surprise.

TESTS (11 + 3 subtests, red-first on 992ba41: 9 failed / 2 passed).
Includes: one lane byte-identical; the two replay numbers; no literal lane
count in `bounce_terms`; the count round-trips through the publication for 1/5/6
with the totals equal; the leg driver compares against its own enumeration and
does so BEFORE `run_bounce_leg`; the floor is imported and a negative bounce
cannot shrink it.
Neighbouring suites (1332, depth flag, arm provenance, death sample): 39 green.
ruff: unchanged from the base.

NEXT, NAMED NOT BUILT: the launcher still passes no `n_lanes`, so it prices 1
and the new W68 would refuse a real five-lane leg. The count must come from the
same plan the leg builds its descs from -- and it now has a guarded consumer,
which is the right order to build it in: the guard exists before the producer,
so a wrong producer is caught rather than believed.

(cherry picked from commit 38713c6)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…and W102 gets the raise site its comment already claimed

Two halves of one defect class: a refusal that names its verdict and hides its
cause, and an intention written as a state.

(1) W97 Weg2HostDeviationRefused printed only `predicted 98.67 vs 95.90`
    (train dry run, arm_def.log:112). True and unreadable: nothing says WHICH
    term carried the peak, so an honest arm and a mispriced one look the same
    and the reader re-derives the ladder by hand. New `arm_terms_line(arm)` is
    the ONE producer of the ARM line's term fields; the refusal appends them
    under TERMS (S/M/S_D), so refusal and arm compare field by field. An
    unpriced term prints n/a, never 0.00 -- absent and zero are not the same
    state.

(2) Weg2XchgLanesUnmeasured (W102, host_ledger.py:1689) had NO raise site
    anywhere in the tree at 19c7502 -- `git grep` returned the class and one
    test reference -- while the comment at :1755 claimed the leg driver refused
    with it. The leg driver did refuse: with W68 Weg2XchgPlanDisagree, the code
    for a wrong phase or lane KEY, not for a lane COUNT priced too low. A
    W-code census reads such a comment as covered. The leg driver now raises
    W102 when the recorded cut contradicts what the leg itself enumerates, and
    the comment states it instead of intending it. The guard sits after the
    #1350e interleaved check and is documented as a NECESSARY, not sufficient,
    condition: the leg sees one rank, the ledger priced boot-wide.

Red-first: 7 of 8 red at 19c7502 in a detached worktree; the one green is
the pre-existing subclass invariant. The W97 half is an execution test on the
real refusal (reusing the sgl-project#1360 watermark specimen), not a source pin.
Neighbouring suites green (sgl-project#1358 per-lane, sgl-project#1360 deviation, lane-cut, arm
provenance, share guard: 49 passed). ruff unchanged: the same 7 pre-existing
findings at base and at tip, none added.

(cherry picked from commit 2f1db00)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
Three red tests (test_the_sn6s_record_no_longer_exceeds_the_boot_bound,
test_a_quiet_launch_still_charges_the_measured_floor,
test_the_arm_line_carries_both_currencies) all share one root cause, none of
it a shmem/anon currency mixup: `_sample()`'s synthetic fixture (line 67)
tripped two LATER, unrelated `run_origin_gib` filters that did not exist when
sgl-project#1325 was written, both correct in their own right.

1. `interleaved=True` (hardcoded). `dormant_image_sample`'s own docstring
   defines it as "sampled during a flip, the destination group RESUMING while
   this one sleeps" -- host_ledger.py's `run_origin_gib` `_mid` check (added
   by commit 5c70c2a, "[#1350e] the two measurably double-booked terms,
   corrected", 2026-09-12) excludes every such record from ever winning its
   max(): a mid-flip sample may already contain the flip ratchet's charged
   step, and using it AND charging the ratchet separately would double-count.
   The REAL sn6s record (SN6S_P_ENTRY, copied verbatim from the sidecar,
   lower in this same file) carries no `interleaved` key at all and its own
   tests (test_the_reader_reprices_the_record_already_on_disk and siblings)
   already passed -- proving `False` was always the accurate value for what
   this file's scenarios model (the launcher's un-interleaved first sleep of
   P), not a value #1350e invalidated.

2. `pids=[]` (also hardcoded). Commit 8679091 ("[sgl-project#1361 22-fix5b] absence
   of evidence is not evidence of death: the pids key must be PRESENT") taught
   `run_origin_gib` that a `pids` key PRESENT but reading 0 alive is a
   DEATH-SAMPLE -- correct for a genuinely dead line, but `[]` here was never
   claiming that; it stood in for "this test does not care about the
   RSS-based image measurement" (the fixture supplies `cg_current_bytes`
   directly for the residual calc). Fixed with a REAL, definitely-alive pid
   (this test process's own, `os.getpid()`) -- `rss_shmem_bytes` reads
   `/proc/<pid>/status`'s own `RssShmem` line, which every real process has,
   so it always answers and is never a death signal, hermetically (no
   subprocess, no /proc fixture needed).

Both commits are named in the fixture's own comment rather than adjusting the
expected values silently. host_ledger.py is UNTOUCHED by this fix -- both
`run_origin_gib` filters are independently correct and well-documented
(5c70c2a guards against double-charging the flip ratchet; 8679091 guards
against reading an omitted `pids` key as a death sample), and the defect was
entirely in the test's own two-line fixture predating both.

All 21 tests in the file green (was 18 passed / 3 failed). No mutant required
-- this is a stale-expectation fix, not a code-bug fix (the coordinator's own
decision rule for that case: fix forward with the commit named, never a
silent value adjustment).

Verified via git worktree against the pristine pre-fix tip (d6c3d19, no
edits from this branch) that the file's failures are reproducible there too,
independent of anything on feat/1378-cushion-gate-stage2 or sgl-project#1390's changes
in this same branch.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
Three red tests (test_the_sn6s_record_no_longer_exceeds_the_boot_bound,
test_a_quiet_launch_still_charges_the_measured_floor,
test_the_arm_line_carries_both_currencies) all share one root cause, none of
it a shmem/anon currency mixup: `_sample()`'s synthetic fixture (line 67)
tripped two LATER, unrelated `run_origin_gib` filters that did not exist when
sgl-project#1325 was written, both correct in their own right.

1. `interleaved=True` (hardcoded). `dormant_image_sample`'s own docstring
   defines it as "sampled during a flip, the destination group RESUMING while
   this one sleeps" -- host_ledger.py's `run_origin_gib` `_mid` check (added
   by commit 5c70c2a, "[#1350e] the two measurably double-booked terms,
   corrected", 2026-09-12) excludes every such record from ever winning its
   max(): a mid-flip sample may already contain the flip ratchet's charged
   step, and using it AND charging the ratchet separately would double-count.
   The REAL sn6s record (SN6S_P_ENTRY, copied verbatim from the sidecar,
   lower in this same file) carries no `interleaved` key at all and its own
   tests (test_the_reader_reprices_the_record_already_on_disk and siblings)
   already passed -- proving `False` was always the accurate value for what
   this file's scenarios model (the launcher's un-interleaved first sleep of
   P), not a value #1350e invalidated.

2. `pids=[]` (also hardcoded). Commit 8679091 ("[sgl-project#1361 22-fix5b] absence
   of evidence is not evidence of death: the pids key must be PRESENT") taught
   `run_origin_gib` that a `pids` key PRESENT but reading 0 alive is a
   DEATH-SAMPLE -- correct for a genuinely dead line, but `[]` here was never
   claiming that; it stood in for "this test does not care about the
   RSS-based image measurement" (the fixture supplies `cg_current_bytes`
   directly for the residual calc). Fixed with a REAL, definitely-alive pid
   (this test process's own, `os.getpid()`) -- `rss_shmem_bytes` reads
   `/proc/<pid>/status`'s own `RssShmem` line, which every real process has,
   so it always answers and is never a death signal, hermetically (no
   subprocess, no /proc fixture needed).

Both commits are named in the fixture's own comment rather than adjusting the
expected values silently. host_ledger.py is UNTOUCHED by this fix -- both
`run_origin_gib` filters are independently correct and well-documented
(5c70c2a guards against double-charging the flip ratchet; 8679091 guards
against reading an omitted `pids` key as a death sample), and the defect was
entirely in the test's own two-line fixture predating both.

All 21 tests in the file green (was 18 passed / 3 failed). No mutant required
-- this is a stale-expectation fix, not a code-bug fix (the coordinator's own
decision rule for that case: fix forward with the commit named, never a
silent value adjustment).

Verified via git worktree against the pristine pre-fix tip (d6c3d19, no
edits from this branch) that the file's failures are reproducible there too,
independent of anything on feat/1378-cushion-gate-stage2 or sgl-project#1390's changes
in this same branch.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…gl-project#1391)

TRAIN2's census against the MERGED tree (independently confirmed here by
manual grep across weg2/managers/mem_ledger/planner/model_executor/scripts
on train tip bb70894): W100 was double-assigned. host_ledger.py's
Weg2SleepLegCushionDeficit (8799c7f, sgl-project#1361 fix6) held it first;
Weg2XchgLaneNeverDrainedRefused (weg2_memory_saver.py / weight_updater.py,
picked tonight for sgl-project#1391) is the later arrival and moves, per the
"census keys on the exception name, never the digit" rule. W106
(this branch's own Weg2XchgWakeSourceGapRefused, sgl-project#1369) is unaffected --
it was free against the merged tree from the start. W108 verified free by
the same manual grep, both against the merged tree and this branch.

Two call sites renumbered (weg2_memory_saver.py's VramCredit.wait_for,
weight_updater.py's _weg2_xchg_inject_from_peer), both raise-message
f-strings only -- no behavioural change, this is a label fix. The one
consumer that pinned the digit, test_weg2_undrained_lane_refusal_1391.py
(two `assert "W100" in msg`), now pins `Weg2XchgLaneNeverDrainedRefused`
by name instead, which is the actual fix against the next collision
(sgl-project#1265/sgl-project#1306 precedent, named explicitly by the coordinator): a class-name
pin survives a future renumber, a digit pin does not. Narrative
W100-mentions elsewhere in that file's own docstring and in
test_weg2_1394_1369_wake_source_gap.py's docstring updated to record the
renumber rather than silently going stale.

Not touched: test_weg2_sleep_leg_gate_1361.py's own "W100" pin (that IS
Weg2SleepLegCushionDeficit, the ORIGINAL, unchanged holder -- host_ledger.py,
outside this desk's file boundary and not part of this collision) and
test_weg2_xchg_lanes_concurrent_1385.py's W100 mention (a sibling-code
citation for the same unchanged host_ledger.py class).

Regression: 141 passed / 10 subtests across the W106/sgl-project#1394 suite, the
gate-axis tests, sgl-project#1391's own suite (renumbered), inject-wiring, the wcode
census, and both the sleep-leg-gate and lanes-concurrent tests that cite
the OTHER W100 (confirming they are genuinely unaffected).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…gl-project#1391)

TRAIN2's census against the MERGED tree (independently confirmed here by
manual grep across weg2/managers/mem_ledger/planner/model_executor/scripts
on train tip bb70894): W100 was double-assigned. host_ledger.py's
Weg2SleepLegCushionDeficit (8799c7f, sgl-project#1361 fix6) held it first;
Weg2XchgLaneNeverDrainedRefused (weg2_memory_saver.py / weight_updater.py,
picked tonight for sgl-project#1391) is the later arrival and moves, per the
"census keys on the exception name, never the digit" rule. W106
(this branch's own Weg2XchgWakeSourceGapRefused, sgl-project#1369) is unaffected --
it was free against the merged tree from the start. W108 verified free by
the same manual grep, both against the merged tree and this branch.

Two call sites renumbered (weg2_memory_saver.py's VramCredit.wait_for,
weight_updater.py's _weg2_xchg_inject_from_peer), both raise-message
f-strings only -- no behavioural change, this is a label fix. The one
consumer that pinned the digit, test_weg2_undrained_lane_refusal_1391.py
(two `assert "W100" in msg`), now pins `Weg2XchgLaneNeverDrainedRefused`
by name instead, which is the actual fix against the next collision
(sgl-project#1265/sgl-project#1306 precedent, named explicitly by the coordinator): a class-name
pin survives a future renumber, a digit pin does not. Narrative
W100-mentions elsewhere in that file's own docstring and in
test_weg2_1394_1369_wake_source_gap.py's docstring updated to record the
renumber rather than silently going stale.

Not touched: test_weg2_sleep_leg_gate_1361.py's own "W100" pin (that IS
Weg2SleepLegCushionDeficit, the ORIGINAL, unchanged holder -- host_ledger.py,
outside this desk's file boundary and not part of this collision) and
test_weg2_xchg_lanes_concurrent_1385.py's W100 mention (a sibling-code
citation for the same unchanged host_ledger.py class).

Regression: 141 passed / 10 subtests across the W106/sgl-project#1394 suite, the
gate-axis tests, sgl-project#1391's own suite (renumbered), inject-wiring, the wcode
census, and both the sleep-leg-gate and lanes-concurrent tests that cite
the OTHER W100 (confirming they are genuinely unaffected).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…her.main(), not just choose()

Prior-art gate first, per the order: sgl-project#1392 itself was already built and on
the train (commit 5a1c3f0 / rebased to de7f875's ancestor chain,
"the dry run says WHICH box state it funded against") -- the ARM line
already carries memavail/anon/shmem plus provenance, the PROVISIONAL text
above FOREIGN_LOAD_PROVISIONAL_THRESHOLD_GIB already exists with the
directional-asymmetry reasoning the order restates almost verbatim, and no
second refusal gate was ever added. This is NOT a rebuild of that feature.

THE ONE GAP the order actually named: "Nutze die Ruhig-Box-Fixture und
_HermeticMainBase aus sgl-project#1390... Prior-Art-Gate zuerst darauf, kein Zweitbau."
The existing test file's `TheLauncherThreadsTheThreeReadingsThrough` class
only inspects `launcher.choose_host_ledger`'s SOURCE TEXT (string/AST
checks) and calls `host_ledger.choose()` directly -- never `launcher.main()`
end to end, and never through sgl-project#1390's own `_HermeticMainBase` /
`_fake_quiet_host` fixture, which exist for exactly this seam.

Closes it by importing (not reimplementing) `_HermeticMainBase`,
`_fake_quiet_host`'s pinned readings, `_main_argv` and `_NEEDS_CHECKPOINT`
from test_weg2_hicache_disabled_1386.py, the same cross-test-file reuse
convention test_weg2_band_credit_1397.py already uses for its own sibling
fixture:

1. TheRealDryRunLineOnAQuietBox: `launcher.main(['--dry-run', ...])`, the
   REAL wiring, on the pinned quiet-box reading -- the printed line says
   "not stale-suspect", never PROVISIONAL, and carries memavail=/anon=/
   shmem=.
2. A new `_fake_loaded_host` (the quiet fixture's numbers, `memory.current`
   pushed exactly QUIET_BASELINE + THRESHOLD + 1 GiB) and a matching
   `_HermeticMainBaseLoaded` harness (own setUp/tearDown -- not a subclass
   of `_HermeticMainBase` overriding setUp, which would leave two live
   mock.patch layers active): TheRealDryRunLineOnALoadedBox proves the SAME
   real `main()` run, ONLY the host reading changed, now prints PROVISIONAL
   and a real foreign_load_now figure.
3. THE REQUIRED DANGER-DIRECTION MUTANT, against the real file, not a
   planted fixture (mirroring how sgl-project#1395's mutant ran against the real
   reader): `mock.patch.object(hl, "FOREIGN_LOAD_PROVISIONAL_THRESHOLD_GIB",
   float("inf"))` around a live `main()` run on the LOADED host -- the line
   still prints a real, honest `foreign_load_now=` figure (the box IS
   loaded) but PROVISIONAL never fires, because the axis that would have
   said so was neutralised. `test_the_real_printed_line_says_PROVISIONAL`
   (a DIFFERENT, non-mutant-specific test) independently catches the same
   defect when the axis is instead removed at the SOURCE (see below),
   which is the broader, more convincing proof.

MUTANT APPLIED LIVE TO host_ledger.py ITSELF AND REVERTED (diff empty
after), exactly as ordered ("fahr ihn gegen die echte Datei"): the
`_fl_now > FOREIGN_LOAD_PROVISIONAL_THRESHOLD_GIB` condition replaced with
`False` (the foreign-load axis silently removed from the line's effect,
never from its printed number). Re-ran TheRealDryRunLineOnALoadedBox: the
loaded box's `main()` run still completes, the line still claims a verdict,
`foreign_load_now=3.50 GiB` (real, above threshold) still prints, but
"PROVISIONAL" is gone -- `test_the_real_printed_line_says_PROVISIONAL`
(the plain, non-mutant test) goes red on its own, which is the strongest
form of this proof: the feature's OWN direct test catches the mutation
without needing a dedicated mutant assertion. Reverted, diff empty,
19/19 green again.

No second launch-time guard: sgl-project#1360/sgl-project#1361's own re-read at LAUNCH is
untouched, and nothing here duplicates it -- this is dry-run-time honesty
about the reading a verdict was measured against, not a second gate.

Regression: test_weg2_dry_run_box_state_1392.py (19/19),
test_weg2_hicache_disabled_1386.py + test_weg2_dry_run_order_probe_1378.py +
test_weg2_cushion_headroom_gate_1378_stage2.py (48/48, 2 subtests) all
green. pyright: host_ledger.py untouched net (mutant reverted); the new
test file's import-resolution noise is the same reportMissingImports class
already present for every sglang.* import in this desk-venv, not a real
type error.

File boundary: host_ledger.py (touched only transiently for the live
mutant, reverted) + launcher.py (untouched this round) + own test file, as
ordered.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
Tests on 34892e3 (incg, one file each): memo test 11 passed, sgl-project#1361 8 passed, line_identity 10 passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
…es itself; W100 by name behind a switch

xsn421 (b1f9b55, clean box, record cache 34892e3 in the tree): the
ORDER -> gathered-legs window was 1 ms at epochs 4-6 (memo hit) but 26-57 ms
again from epoch 7 on, with the sidecar unchanged since 14:53:27. The
'gathered-legs' mark of WEG2-FLIP-TIMELINE sits within 1 ms of 'WEG2-RPC
ISSUED' on every flip, so the window is the synchronous gate, not the loop.

Cause: the flip calls the gate with S = self.groups[src], the Group
DATACLASS, not its name. str(group) is its repr and carries `served` and
`outstanding`; it changed between two sleeps of a group once that group
served requests (epoch 7 on), so the memo keyed on it missed and every flip
parsed the 2.9 MB sidecar again.

Fixed by keying the memo on the group's name. The record LOOKUP is left as it
was, and that exposes the second finding: the record's keys are "P", "D",
"FLIP", and "Group(name='P', ...)" matches none of them -- on the live flip
path the sgl-project#1361 W100 sleep-leg gate has always answered (None, "absent") and
has never been able to refuse. Default unchanged (byte-identical answer);
SGLANG_WEG2_SLEEP_GATE_BY_NAME=1 looks up by the name and makes the gate live
(an operator decision: W100 can then stop a boot).

Instrument, one line per flip: WEG2-SLEEP-GATE-TIME group= total_ms=
cgroup_ms= record_ms= memo=hit|miss(first|changed:...|no-stat)[+torn|+unreadable]
need= src= -- src=absent on the live path is the dead gate in the log.

Tests (test27b.sh, CPU, files one by one):
- test_weg2_sleep_leg_memo_27b.py: 18 passed (new: the memo survives a
  serving Group object, one read; the live answer for a Group object is
  (None, "absent") as before; the switch finds the record and W100 refuses
  on the xsn25 numbers; the timing line names group, memo state and src).
- test_weg2_sleep_leg_gate_1361.py: 8 passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
…name (8604d13)

Tests on 8604d13 (affected files only): memo 18, sgl-project#1361 8 -- green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant