EV-54 review r1: no stale fails block after the charger returns; peak cut reason
checks / unit (pull_request) Successful in 45m27s
infra-pin / fresh (pull_request) Successful in 2s

The fails >= MAX_TRIES block on non-cut writes applies only while the refused cut value is still owed, so Solar resumes after the charger came back under a capped quarter (it froze before). The quarter's cut count is untouched and D2's 0 A stays held while capped. A new cut value under the read-back above a refused one logs 'peak cut'. New rows T36 (away while capped, 0 A and 6 A), T37 (F6), T38 (Off after 3 tries), T39 (reason replay).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ems-agent
2026-11-30 04:51:54 +01:00
co-authored by Claude
parent cf07f6f99b
commit 095f773921
3 changed files with 104 additions and 5 deletions
@@ -40,10 +40,18 @@ QC (brief v6); the formal check is reports/EV-54-formal-report.md.
## Choices the rulings left open
- Refused cut tries still count in `fails` (without `gave_up`), and outside the
cut `fails >= MAX_TRIES` stops a write as `gave_up` did. So Off's way-out 0 A
after refused cut tries is written exactly as before (N10). When the cut
cut `fails >= MAX_TRIES` stops a write as `gave_up` did, but only while the
refused value is still owed. So Off's way-out 0 A after refused cut tries is
written exactly as before (N10). Once that value is gone (the charger came
back, another value was written), nothing blocks Solar's normal writes
(review round 1: a gate on `fails` alone froze Solar after the charger came
back under a capped quarter). The gate is scoped rather than `fails` reset,
so one rule covers every way the value goes, and the quarter's cut count
(`cut_fails`) is never touched by it. When the cut
stops standing in Solar and the value cannot be dropped yet (stuck), that
value becomes Solar's own: reason Solar, a fresh `fails` count (QC).
- At a new quarter's wait the cut tick holds the read-back the writer is about
to take, not the refused value, so the wait never re-sends it (G1).
- No drop over another writer's value (a hold or a difference being watched).
- A new cut value under the read-back is logged "peak cut", also when it lies
above a refused value.
+13 -3
View File
@@ -1080,8 +1080,13 @@ class SolarWriter(ManualWriter):
if want > TOL_A and self.nz_block:
return # C17/C18: 0 A only, no retry or raise
# EV-54: refused cut tries count in `fails` without `gave_up`; outside
# the cut they stop a write as `gave_up` did before.
stopped = self.gave_up or self.fails >= MAX_TRIES
# the cut they stop a write as `gave_up` did before, but only while
# that refused value is still owed. Once it is gone (the charger's
# return, another write) no stale count blocks Solar (review r1).
# The quarter's cut count (`cut_fails`) is not touched.
stopped = self.gave_up or (self.fails >= MAX_TRIES
and self.refused_cut is not None
and not self.taken)
cut_try = self._cut_try(want)
if cut_try and self.cut_fails >= MAX_TRIES:
return # EV-54 (Q1): this quarter's tries used
@@ -1119,8 +1124,13 @@ class SolarWriter(ManualWriter):
elif (stopped and not cut_try) or (
self.fail_at is not None and now - self.fail_at < RETRY_S):
return
# EV-54 (review r1): a new cut value under the read-back is a peak cut,
# also when it lies above the refused one (`cut` compares with
# `sent_a`, which is that refused value).
peak = cut or (cut_try and self.refused_cut is not None
and cur is not None and want < cur - TOL_A)
await self._write(drv, want, cur, now, tracker,
why="peak cut" if cut else None)
why="peak cut" if peak else None)
def _own_readback(self, cur) -> bool:
"""C9: does the read-back show a current of Solar's own (sent,
+81
View File
@@ -35,6 +35,7 @@ GOLDEN = {
'T35 (b)': [],
'T35 (c)': ([(1020.0, 0.0, True)],
['Car: set from 10 A to 0 A on 3 phases (peak cut).']),
'T38': [],
}
@@ -523,6 +524,86 @@ want = golden("T35 (c)", (wc, lc))
check(f"T35 (c): Off at 1000 while the cut stands: writes {wc} and lines "
f"{lc} as bdfd3e6's ({want})", (wc, lc) == want and bool(wc))
# =========================================================================== #
print("\n7. REVIEW ROUND 1: AWAY WHILE CAPPED (T36), F6 (T37), OFF (T38), "
"THE REASON (T39)")
# =========================================================================== #
# T36 (review r1, Major): the charger is away 1100-1200 and comes back while
# the cap stands with the quarter's 3 tries used up; then the lift. D2's 0 A
# is a cut try and stays held (ruling 3); the return does not give the
# quarter new tries; after the lift Solar's control resumes.
for tag, h, s in (("0 A", 3000.0, 0.0), ("6 A", 900.0, 1900.0)):
ev = window({1100: lambda p, c: p.ch.go_unavailable(),
1200: lambda p, c: p.ch.go_unavailable(False)}, 959, 1300)
r = run(house_c((1250, 900.0), h=h), sun_c((1250, 9000.0), s=s),
dur=2700, events=ev)
tr = refused(r, 900, 1100)
tl = t_lift(r, 1200, 1800)
held_w = [(t, a) for t, a, _ok, _w in writes(r, 1081, tl or 1e9)]
cf = sorted({x["cut_fails"] for x in rows(r, 1081, tl or 1e9)}, key=str)
nz = [(t, a, ok, why) for t, a, ok, why in writes(r, tl or 1e9,
(tl or 1e9) + 61)
if a > 0.0]
check(f"T36 [{tag}] (review r1): 3 refused tries ({tr}); the charger away "
f"1100-1200 and back while capped: no D2 0 A or other write until "
f"the lift at {tl} ({held_w}); the quarter's cut count stays 3 "
f"across the return ({cf}); after the lift a Solar write within "
f"60 s ({nz[:1]})",
len(tr) == 3 and present(tl) and tl is not None and not held_w
and cf == [3] and bool(nz) and nz[0][2] and nz[0][3] == "Solar")
never54(f"T36 [{tag}]", r)
# T37 (review r1, F6): episode 1 is lifted by the start rule (60 s) after
# 2 refused tries (960, 1020); episode 2 is due at 1040, within 60 s of the
# last refusal, with one try left: that try waits to 1080.
r = run(house_c(), sun_c((961, 9000.0), (1040, 0.0)), dur=1300,
opts={"ev_start_min": 1}, events=window({}, 959, 1800))
tl = t_lift(r, 961, 1040)
due2 = first(x["t"] for x in rows(r, (tl or 1e9) + 1, 1100)
if x["cap"] is not None or x["wait"] is not None)
tr = [t for t, _a in refused(r, 900, 1300)]
early = [t for t, _a, _ok, _w in writes(r, due2 or 1e9, 1080)]
check(f"T37 (review r1, F6): episode 1 lifted at {tl} after tries {tr[:2]}; "
f"episode 2 due at {due2}: no try before 60 s after the last refusal "
f"({early}), then try 3 at {nth(tr, 2)} (>= 1080); none after",
present(tl) and tl is not None and present(due2) and due2 is not None
and due2 < 1080 and tr[:2] == [960.0, 1020.0] and not early
and len(tr) == 3 and tr[2] >= 1080 if len(tr) >= 2 else False)
never54("T37", r)
# T38 (review r1, the fails gate): Off after the quarter's 3 refused tries,
# the refused 0 A still owed: no way-out try, as bdfd3e6 (gave_up there).
r = run(house_c(), sun_c(), dur=1300,
events=window({1100: act("car_mode", "off")}, 959, None))
w38 = [(t, a, ok) for t, a, ok, _w in writes(r, 1081)]
want = golden("T38", w38)
check(f"T38 (review r1): Off at 1100 after 3 refused cut tries: Off's "
f"way-out writes {w38} as bdfd3e6's ({want})", w38 == want)
async def reason_replay():
"""T39: a refused 6 A cut, then the next quarter sizes 7 A (above the
refused value, under the 10 A read-back)."""
w = carmode.SolarWriter()
w.engaged, w.sent_a, w.taken, w.last_a = True, 10.0, True, 10.0
drv, trk = Drv(), Trk()
w.cut_quarter("q1")
w.cut_a, w.cut_on = 6.0, True
await w._put(drv, 6.0, 10.0, 1000.0, trk)
w.cut_quarter("q2")
w.cut_a = 7.0
await w._put(drv, 7.0, 10.0, 1070.0, trk)
return list(drv.calls), w.sent_why
try:
t39 = asyncio.run(reason_replay())
except Exception as e: # noqa: BLE001
t39 = (["raised " + repr(e)], None)
check(f"T39 (review r1): a new cut value above the refused one, under the "
f"read-back, goes out as 'peak cut' ({t39})",
t39[0] == [6.0, 7.0] and t39[1] == "peak cut")
tb_all = LOG.tracebacks(n_log0)
check(f"N13: no traceback in this file's runs ({tb_all[:1]})", not tb_all)
if TAKE: