EV-60: Solar never passes the cut cap of 3 refused tries per quarter key
checks / unit (pull_request) Successful in 57m13s
infra-pin / fresh (pull_request) Successful in 2s

Solar's phase change 0 A and its capped close are cut tries. They now pass
the same gates as `_put`: none at cut_fails >= MAX_TRIES, none within RETRY_S
of the last refused cut try (the sequence's first cut close waits at 0 A, the
rest keep the 5 s spacing). A gated 0 A waits for the next quarter key and
never gives up; a capped close with no tries left ends the change at 0 A
(end_switch(False), reapply, no write). Solar's close end adds no extra
_failed (EV-56 F1 on the cut path, EV-59 finding 2 on the non-cut path), so
a press during the close retries gives the value MAX_TRIES tries.

Solar only (override in SolarWriter); Manual is byte for byte as before.
Edited tests as ruled (Q3, Q4): test_ev59 T25/T14, T25 press, T14c and the
N11 digest list; test_ev56 T19b [a]/[b], T12 and golden "T20 T12 [R]".

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2026-12-02 05:48:20 +01:00
parent 2e09622fe1
commit 5bd2b1ec97
4 changed files with 969 additions and 23 deletions
+46 -4
View File
@@ -901,6 +901,7 @@ class SolarWriter(ManualWriter):
self.cut_warned = False # ... and its one CHARGER_REFUSED was given
self.sent_cut = False # `sent_a` went out as a cut try
self.refused_cut = None # a cut value the charger did not take
self._cap_end = False # EV-60: a capped close ended the change
def owe_start(self) -> None:
"""C1: the add-on starts in Off while an exit 0 A of its own was still
@@ -1084,7 +1085,40 @@ class SolarWriter(ManualWriter):
return "peak cut" if q.get("cut") else "Solar"
def _close_end(self, now) -> None:
self._failed(now) # EV-59: Solar stays as it was (EV-60)
"""EV-60: no extra `_failed`. Each refused close was counted when it
went (`_write`), a cut try in `cut_fails` too, so the sequence's end
adds nothing (Manual's `_close_end` is EV-59's, unchanged)."""
def _cut_gate(self, now) -> bool:
"""EV-60 (Q1): the quarter key's cut tries are used up, or the last
refused one is less than RETRY_S old (`_put`'s two gates)."""
return self.cut_fails >= MAX_TRIES or (
self.cut_fail_at is not None and now - self.cut_fail_at < RETRY_S)
async def _advance(self, drv, r, cur, now, tracker, want_a, clamp, rev):
"""EV-60: Solar's capped close is a cut try, so it passes the cut's
gates. Tries used up: the change ends at its 0 A, nothing written
(`_cap_end`: `step` then leaves the plan as `end_switch(False)` put
it). The sequence's first cut close waits at 0 A until RETRY_S after
the last refused cut try (counts nothing, ends nothing); after a cut
close of the sequence went, the 5 s spacing of `_advance` rules."""
q = self.seq
if q["stage"] == "settle" and now - q["t1"] >= SETTLE_S \
and callable(want_a):
hi = CH.ENTITY_MAX_A if clamp is None else float(clamp)
a = min(max(float(want_a(q)), CH.MIN_A), hi)
if self._cut_try(a):
if self.cut_fails >= MAX_TRIES:
self.seq, self.last_a, self.reapply = None, None, True
self.rev_applied = None
self.plan.end_switch(False)
self._cap_end = True
return
if not q.get("cut_went") and self.cut_fail_at is not None \
and now - self.cut_fail_at < RETRY_S:
return
q["cut_went"] = True
await super()._advance(drv, r, cur, now, tracker, want_a, clamp, rev)
def _failed(self, now) -> None:
if self.sent_cut:
@@ -1321,10 +1355,15 @@ class SolarWriter(ManualWriter):
async def _begin_solar(self, drv, r, cur, n, now, tracker) -> None:
"""Step 1 of the safe sequence: 0 A (kept when it already stands).
A 0 A the charger does not take ends the change; tried again later
by the plan's own dwell."""
by the plan's own dwell. EV-60: under a cap that 0 A is a cut try and
passes the cut's gates; stopped by them the change waits (nothing
written or counted, never a give-up) for the next quarter key."""
owed = not (cur is not None and cur <= TOL_A and self.sent_a == 0.0
and self.taken)
if owed and self._cut_try(0.0) and self._cut_gate(now):
return
self.phase_done_at = None
if not (cur is not None and cur <= TOL_A and self.sent_a == 0.0
and self.taken):
if owed:
if not await self._write(drv, 0.0, cur, now, tracker):
self.plan.end_switch(False)
return
@@ -1569,6 +1608,9 @@ class SolarWriter(ManualWriter):
clamp, None)
if any(x[0] == "phases" for x in self.log[n_log:]):
q["sel"] = True # a select went out, taken or not
if self.seq is None and self._cap_end:
self._cap_end = False # EV-60: ended at 0 A, plan as it was
return
if self.seq is None:
# Back on the old phases only when no select went out; after
# one the plan keeps the current it wrote (the lower one) and