SAFETY-32 fix round: grade the reduction on packs whose floors DIFFER
checks / unit (pull_request) Successful in 4m47s

AC 6 was not met for the reduction main.py actually hands decide(). The
reviewer removed the per-pack grading twice and the 19-file suite stayed green
both times. No shipped behaviour changes here - app/ is untouched. What changes
is what observes it.

WHY BOTH SURVIVED, and it is this repository's recurring defect landing on this
card's own Decision 2: under any rule-8-valid config every pack's
pack_floor_pct() equals peak_soc_floor, so `floors` is a list of IDENTICAL
numbers and max/min/first/last are four spellings of one answer. The only check
using a cut-out ABOVE the EMS floor - 12c's `_n1_deep` - ran on a roster of ONE,
where every reduction agrees. So no check ever evaluated binding_soc_floor() on
two packs whose floors differ. And the degeneracy is not a defence: this PR's own
argument ("unreachable is a claim about today's rule ordering, and
validate_startup_config() is also sim/inject.py's entry point") justifies writing
the reduction and equally obliges grading it.

  * test_peakguard.py part 12c2 - NEW. binding_soc_floor() on a roster whose
    per-pack floors ALL DIFFER: four SIMULATED cut-outs 30/25/40/35 %, each
    strictly above peak_soc_floor, so max (40), min (25), first (30), last (35)
    and the mean (32.5) are five different numbers and the extremes sit at
    INTERIOR roster positions. Two packs structurally cannot separate those -
    there max==last and min==first - and neither can three; four is the smallest
    roster that can. Precondition is its own check (habit 1); the counterfactual
    raises ONE pack - the last, neither extreme - past the old maximum and the
    answer follows (habit 7); peak_soc_floor is then lifted above every cut-out
    to grade the other side of the conjunction.
  * test_peakguard.py part 12g - REWRITTEN as behaviour (habit 4). The old
    assertion was `"self.packs" in <the unparsed call site>`, which `self.packs[:1]`
    still satisfies. It now drives REAL Controller.cycle()s on a two-pack roster,
    both packs at the same SoC, and reads PeakDecision.soc_floor - the argument,
    echoed back by the shipped decide(). The cut-outs are the only thing varied,
    and the SAME PAIR is carried in BOTH ORDERS.
  * ⚠️ TWO MORE SURVIVORS, found by this round's own battery and recorded rather
    than quietly repaired. (a) The first cut of 12g varied only pack B's cut-out,
    so `self.packs[-1:]` (+5 bytes) agreed with the roster on both runs and stayed
    green across all 19 files; the swapped pair closes it, and between the two
    directions no single-position slice passes all three runs. (b)
    binding_soc_floor()'s EMPTY-roster branch rewritten to `return None`
    (-43 bytes) was green too - a defensive branch nothing in the suite reached.
    Both directions of it are pinned now.
  * wired_over_limit() gained a prepare(ctl) hook, inside its retry loop so every
    attempt grades the same site.
  * In-process mutation rows 22, 22b and 23 record all four survivors.

Nine further source mutations went through the harness on the fixed tree
(binding_soc_floor -> floors[0] / floors[-1], pack_floor_pct conjoining with
min, pack_permissions grading against packs[0], `any` -> `all` on the unknown
floor, Controller.packs reversed, decide(soc=) taking inverters[0].soc, and the
two survivors above). Seven were red on first run; the two survivors are now red
as well. Three of the nine have a ZERO byte delta and still went red, which is
the direction stale bytecode cannot fabricate - and the harness purged anyway.

MANDATORY PROOF, all in the CI image over a tree rsynced to a plain path and
bind-mounted :ro, bytecode entry count printed before and after the purge:
each of the four mutations now takes test_peakguard.py RED, and the unmutated
tree is 19/19 green (twice, plus test_peakguard.py five times in isolation -
card CI-06's flake did not reappear). The zero-byte one was proved to have RUN rather than
assumed: dis.get_instructions LOAD_GLOBALs were [float, pack_floor_pct, any,
min] and binding_soc_floor() returned 25.0 on the 12c2 roster where the shipped
code returns 40.0.

No measurement of inverter B appears anywhere. It does not physically exist.
Every second-pack and fourth-pack figure added here is SIMULATED and labelled at
its definition; only inverter A's 10 % is read off hardware. No hardware was
touched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BwRLw7eKYj2byVdwB6kbjU
This commit is contained in:
glenn schrooyen
2026-09-04 17:09:58 +02:00
co-authored by Claude Opus 5
parent d9388c81b0
commit 8501e055f2
3 changed files with 493 additions and 10 deletions
@@ -81,6 +81,116 @@ grading each pack separately would be. The converse is not true and is not
claimed — a site can be refused while every pack individually has headroom, which
costs a shave.
### 3a. ⚠️ FIX ROUND — the reduction was written and argued, and NOT GRADED
PR #48 was rejected because the argument in §4 below justified *writing* the
reduction and was then not carried into a check. Neither of the two mutations
below appears anywhere in §6's twelve-row battery: it graded *"the reduction
dropped"* and *"the bare option handed over"*, and never asked what happens when
the reduction is the **wrong one**, or when the roster handed to it is
**sliced**. Both were applied to `app/` by the reviewer and **all 19 files
stayed green**:
| mutation | Δ | why it survived |
|---|---|---|
| `binding_soc_floor()`: `max(floors)` → `min(floors)` | **0 bytes** | every roster in the suite was rule-8-valid or one pack long, so `floors` held **identical numbers** and `max`/`min`/first/last were four spellings of one answer |
| the `decide()` call site: `self.packs` → `self.packs[:1]` | **+4 bytes** | part 12g asserted `"self.packs" in <the unparsed expression>` — and `self.packs[:1]` **contains that substring** |
The zero-byte one was proved to have actually run rather than assumed:
`dis.get_instructions` showed the `LOAD_GLOBAL`s as `[float, pack_floor_pct,
any, min]`, and `binding_soc_floor([Pack("a",50,10), Pack("b",50,35)], 20.0)`
returned `20.0` where the shipped code returns `35.0`.
**The common cause is this repository's recurring defect** — a check whose DATA
cannot reach the failure it names. The one check that used a cut-out **above**
the EMS floor (12c's `_n1_deep`) ran on a roster of **ONE**, where every possible
reduction agrees. So no check in the suite ever evaluated
`binding_soc_floor()` on two packs whose floors **differ**.
**And the rule-8 degeneracy is not a defence, by §4's own words.** If
"unreachable is a claim about today's rule ordering, not a property of this
function, and `validate_startup_config()` is also `sim/inject.py`'s entry point"
is enough to *write* the reduction, it is enough to *grade* it. Through
`sim/inject.py`, which does not run rule 8 at all, `min(floors)` lets the guard
command a forced discharge to 20 % on a pack whose BMS cuts out at 35 %.
**What was added — no shipped behaviour changed, only what observes it:**
* **`test_peakguard.py` part 12c2** evaluates `binding_soc_floor()` on a roster
whose per-pack floors **all differ**. Four **simulated** cut-outs —
`30, 25, 40, 35` %, every one strictly above `peak_soc_floor: 20`, so
`pack_floor_pct()` selects the cut-out for each and `floors` *is* that tuple in
that order. The four candidate reductions are then four different numbers:
max = 40 <- the shipped answer
min = 25
first = 30 <- "grade the site against pack A", inside the function
last = 35
mean = 32.5
The extremes sit at **interior** roster positions (index 2 is the max, index 1
the min). A two-pack roster structurally cannot separate these — there `max`
and `last` coincide and so do `min` and `first` — and neither can three. Four
is the smallest roster that separates all four. The precondition is its own
check (habit 1), one pack is then raised past the old maximum (habit 7: the
**last** pack, which was neither extreme, so the line can only move if the
reduction read it), and `peak_soc_floor` is lifted above every cut-out to grade
the other side of the conjunction.
* **Part 12g is behaviour now, not source text** (MUTATION.md habit 4). Real
`Controller.cycle()`s on a two-pack roster, both packs held at the same SoC and
everything else identical, with the packs' own cut-outs as the only thing
varied:
cut-outs A 10 / B 18 % -> decide() got soc_floor=20 %, floor_limited=False
cut-outs A 10 / B 35 % -> decide() got soc_floor=35 %, floor_limited=True
The observable is `PeakDecision.soc_floor` — the argument, echoed back by the
shipped `decide()` — so the whole path from `Controller.inverters` to the
guard's argument is under test, and the site's **verdict flips** as well as the
number. `self.packs[:1]` answers 20 % both times. **Which** option key the floor
comes from stays pinned on the source in part 4, because that claim genuinely
is about the code's shape; that the option still governs is now graded
behaviourally too.
* ⚠️ **A THIRD SURVIVOR, FOUND WHILE FIXING THE FIRST TWO, AND RECORDED RATHER
THAN QUIETLY REPAIRED.** The first cut of part 12g varied only **pack B's**
cut-out — so `self.packs[-1:]`, grade the site against the **last** pack,
agreed with the full roster on both runs and stayed green across all 19 files
(+5 bytes). A two-run fixture that only ever moves the second pack pins `[:1]`
and not `[-1:]`; it is the same defect one step along, and it was in the fix
for this defect. Part 12g now runs the **same pair of cut-outs in both
orders**:
cut-outs A 10 / B 18 % -> soc_floor=20 %, floor_limited=False
cut-outs A 10 / B 35 % -> soc_floor=35 %, floor_limited=True
...the SAME PAIR SWAPPED, A 35 / B 18 % -> soc_floor=35 %, floor_limited=True
`[:1]` answers 20 % on the second run, `[-1:]` answers 20 % on the third, and
the roster answers 35 % on both. No single-position slice passes all three.
This is the mirror `12h` already ran on the SoC axis, which is where the shape
was borrowed from.
* ⚠️ **AND A FOURTH, from the same battery: the EMPTY-roster branch.** Rewriting
`binding_soc_floor([])`'s `float(soc_floor)` to `return None` (−43 bytes) was
green across all 19 files. It is defensive code — `Controller.inverters` is
never empty on a started controller, and `inputs_ok` refuses the cycle before
the guard is reached if it were — so nothing in the suite went near it. It is
**pinned rather than argued**, in both directions (the option when there is
one, `None` when there is not), because a branch with no check is a branch
that can be rewritten under a green suite. The check also records why it
cannot permit anything either way: `pack_floor_soc` is `None` at an empty
roster, and `discharge_permitted()` refuses on a `None` SoC whatever the floor
is.
* **`wired_over_limit()` gained a `prepare(ctl)` hook**, inside its retry loop so
every attempt grades the same site, which is the only window in which a second
inverter can join the roster before the telegrams are fed.
* **In-process mutation rows 22, 22b and 23** record all four survivors, so a
later edit that re-degenerates any of these fixtures goes red on a row rather
than on nothing.
## 4. ⚠️ THE HONEST LIMITATION, and it is the reason this record exists
**Under any configuration rule 8 accepts, `binding_soc_floor()` answers