OPT-15 review: bound unmeasured charge stops, test the hold's rules and M15
checks / unit (pull_request) Failing after 3s
infra-pin / fresh (pull_request) Successful in 1s

- A second unmeasured-headroom stop in a quarter latches the charge: a
  headroom missing every other cycle flipped it 1799 times in 30 min.
- Unit test of the run-edge hold's end conditions and of a small step.
- Outside its probe a refuser does not make the others rest (M15 red).
- DECISIONS: one review line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude review
2026-09-29 22:31:52 +02:00
parent fae6681e19
commit c38dd1e969
3 changed files with 94 additions and 7 deletions
+12 -7
View File
@@ -944,6 +944,7 @@ class Controller:
self._run_done = {}
self._mode_trade_was = False
self._charge_blocked_q = None
self._charge_gap_q = None # OPT-15: an unmeasured stop's quarter
self._ref_cheap = None
# OPT-15: a run edge the loop holds at E: (E, step sign, until, the
# last battery reading).
@@ -2174,13 +2175,17 @@ class Controller:
blocked=self._charge_blocked_q == quarter,
done_charge=done_c, done_sell=done_s)
# A charge the guard or the headroom stopped stays off this period.
# OPT-15: only a MEASURED stop latches; an unmeasured headroom (None)
# stops this tick only, so a gap cannot cost the whole quarter.
if was and self.mode_tick.action != modetrade.CHARGE and (
self.mode_tick.why == "peak"
or (self.mode_tick.why == "headroom"
and self.arb_headroom_w is not None)):
self._charge_blocked_q = quarter
# OPT-15: only a MEASURED stop latches; the first unmeasured headroom
# (None) in a quarter stops this tick only, so a gap cannot cost the
# whole quarter. A second one latches, so gaps cannot flip the charge.
if was and self.mode_tick.action != modetrade.CHARGE:
why = self.mode_tick.why
gap = why == "headroom" and self.arb_headroom_w is None
if why == "peak" or (why == "headroom" and not gap) or (
gap and self._charge_gap_q == quarter):
self._charge_blocked_q = quarter
elif gap:
self._charge_gap_q = quarter
return self.mode_tick
def _run_mark(self, kind, run, packs, out) -> set: