EV-20 review round 2: one write clock for every non-zero current (C6, N5)
checks / unit (pull_request) Successful in 30m56s
infra-pin / fresh (pull_request) Successful in 2s

ManualWriter._write, the one write_current call, stamps every non-zero
current either writer sends; Solar's 30 s gate reads that stamp (its own and
Manual's), so the step back up after a phase change's closing write waits 30
s on every path. The closing current is fixed once per sequence, retries too.
Rows: every select shape (refused, ignored, late; settle refused three times;
T7 1 -> 3 and T22 3 -> 1) with nevers().

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
Claude
2026-11-23 01:25:06 +01:00
parent 9c82bc816a
commit cd8c393161
3 changed files with 81 additions and 8 deletions
+22 -5
View File
@@ -139,6 +139,7 @@ class ManualWriter:
self.undone = 0 # sequences undone before the select
self.phase_done_at = None # EV-15: our phase change ended well then
self.zero_sent_at = None # EV-15: our 0 A write is out, not yet back
self.nonzero_at = None # EV-20 C6: the latest non-zero write sent
# ------------------------------------------------------------------ user
def user_changed(self) -> None:
@@ -263,6 +264,11 @@ class ManualWriter:
async def _write(self, drv, a, was, now, tracker, **kw) -> bool:
tracker.begin_write() # EV-12: the read-back is ours
if float(a) > TOL_A:
# EV-20 C6, THE ONE WRITE CLOCK: every non-zero current either
# writer sends, whatever path it comes from, is stamped here (the
# one write_current call). Solar's 30 s gate reads this stamp.
self.nonzero_at = now
try:
# EV-20: `kw` is only Solar's shorter read-back wait at shutdown.
ok = await drv.write_current(a, **kw)
@@ -874,7 +880,9 @@ class SolarWriter(ManualWriter):
>= PHASE_GAP_S
def _plan_step(self, sun, now, clamp, n_now, gap_ok) -> None:
self.plan.ext_at = self.other_at
# C6: the write clock, Solar's own latest non-zero write and Manual's.
self.plan.ext_at = max((t for t in (self.nonzero_at, self.other_at)
if t is not None), default=None)
self.plan.step(
now, target_w=sun.target_w, hold=sun.hold, n_now=n_now,
auto=sun.auto and not self.single and not self.phases_gave_up,
@@ -902,6 +910,14 @@ class SolarWriter(ManualWriter):
new phases and for the phases the charger reports, so nothing meant
for 1 phase is ever written on 3 (review round 1, Major 1)."""
def want(q):
if "close_a" in q:
return q["close_a"] # one value per sequence, its retries too
q["close_a"] = a = self._close_a(q, clamp, n_reported)
return a
return want
def _close_a(self, q, clamp, n_reported):
if True:
before = self.plan._before
if q.get("failed") and not q.get("sel") and before is not None:
return before[0] if before[0] >= CH.MIN_A else CH.MIN_A
@@ -912,7 +928,6 @@ class SolarWriter(ManualWriter):
if b is not None:
a = min(a, max(b, CH.MIN_A))
return a
return want
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).
@@ -1079,10 +1094,12 @@ class SolarWriter(ManualWriter):
# one the plan keeps the current it wrote (the lower one) and
# takes the phases the charger reports from the next cycle.
done = not q.get("failed") or bool(q.get("sel"))
if done and q.get("sel") and self.sent_a is not None \
and self.sent_a >= CH.MIN_A:
self.plan.a = min(self.plan.a, self.sent_a)
self.plan.end_switch(done)
close = q.get("close_a")
if close is not None and close >= CH.MIN_A:
# The sequence ended on this current: the plan's current
# now (its 30 s count is the write clock's, `_write`).
self.plan.a = float(close)
return
self._plan_step(sun, now, clamp, n_now, gap)
want = self.amps_out(clamp)