EV-20 rig round 1: stuck check armed on the reading before the send; no amp ping-pong; ha_signed meter age
infra-pin / fresh (pull_request) Successful in 4s
checks / unit (pull_request) Failing after 1h11m9s

The stuck check's baseline is the signature of the latest reading taken
before the send (kept at begin_write), never one that arrived while the write
waited; a refused write's first post-send sample is its baseline (EV-36).
After a step down, a step back up needs UP_HYST_W past the boundary. Solar's
15 s meter-age gate applies only where the age measures arrival; on
ha_signed it is the source's meter_max_age_s. Rows in test_ev20_rig.py;
harness modes for the rig's interleave and an on-change meter.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
Claude
2026-11-23 14:28:21 +01:00
parent cc8c0dc2ae
commit 711c5f3627
6 changed files with 342 additions and 13 deletions
+15 -2
View File
@@ -430,6 +430,10 @@ SOLAR_WRITE_S = 30.0 # at most one current change per this ...
SOLAR_STEP_A = 1.0 # ... and only on a change of this or more
UP_W, UP_S = 4500.0, 180.0 # auto phases: to 3 at this for this long
DOWN_W, DOWN_S = 4000.0, 300.0 # ... back to 1 under this for this long
# Rig round 1: after a step down, a step back up needs this much more than the
# amp boundary, so a spare that dithers on a boundary is one change, not 10 /
# 9 / 10 every 30 s (N5's intent).
UP_HYST_W = 100.0
ONE_PHASE_S = 10.0 # one phase drawing while 3 are allowed this long
ONE_PHASE_MIN_W = 500.0 # ... with the car drawing at least this
# D3: at shutdown the 0 A is tried this many times, this far apart, each
@@ -522,6 +526,7 @@ class SolarPlan:
self.target_w = None
self._before = None # the state before a phase change
self.ext_at = None # C6: Manual's latest non-zero write
self.last_dir = 0 # the latest change: +1 up, -1 down
def pause(self, why="paused"):
self.a = 0.0
@@ -541,6 +546,7 @@ class SolarPlan:
self.why)
self.n, self.switch = n, True
self.a, self.set_at, self.why = float(a), now, "running"
self.last_dir = 0
self.ok_since = self.low_since = None
self.up_since = self.down_since = None
@@ -607,7 +613,7 @@ class SolarPlan:
if hi < CH.MIN_A:
self.pause()
return
self.a, self.set_at = float(hi), now
self.a, self.set_at, self.last_dir = float(hi), now, -1
if auto and not self.switch: # auto phases, by dwells
if self.n == 1:
self.down_since = None
@@ -640,7 +646,13 @@ class SolarPlan:
if want is not None and want >= CH.MIN_A:
self.low_since = None
self.why = "running"
if want > self.a and self.last_dir < 0:
# Up again after a step down: only past the boundary plus
# `UP_HYST_W` (no ping-pong on an amp boundary).
up = amps_for(target_w - UP_HYST_W, self.n, clamp) or 0.0
want = max(self.a, up)
if abs(want - self.a) >= SOLAR_STEP_A and self._gate(now):
self.last_dir = 1 if want > self.a else -1
self.a, self.set_at = want, now
return
if auto and self.n == 3 and target_w >= DOWN_W and not self.switch:
@@ -649,6 +661,7 @@ class SolarPlan:
self.low_since = None
self.why = "running"
if self.a != CH.MIN_A and self._gate(now):
self.last_dir = 1 if CH.MIN_A > self.a else -1
self.a, self.set_at = CH.MIN_A, now
return
if self.low_since is None:
@@ -658,7 +671,7 @@ class SolarPlan:
self.pause()
return
if self.a != CH.MIN_A and self._gate(now):
self.a, self.set_at = CH.MIN_A, now
self.a, self.set_at, self.last_dir = CH.MIN_A, now, -1
class SolarWriter(ManualWriter):
+24 -3
View File
@@ -715,6 +715,10 @@ class CarTracker:
_prev: tuple | None = None
# EV-04: our own writes, and the stuck-reading rule (SAFETY-37's shape)
mute_until: float = 0.0
# EV-20 rig round 1: the signature of the latest reading taken BEFORE our
# write went out, kept at `begin_write` (the arming baseline). The empty
# tuple means "no write begun", and `note_write` then uses `sig`.
pre_sig: tuple = ()
armed_at: float | None = None
armed_sig: tuple | None = None
sig: tuple | None = None
@@ -782,8 +786,15 @@ class CarTracker:
def begin_write(self) -> None:
"""EV-12: a write of ours is in flight. Its read-back can reach the
tracker before `note_write` runs (the write waits for it), so the mute
is open until `end_write`."""
is open until `end_write`.
EV-20 (rig round 1, EV-32): the stuck check's baseline is taken HERE,
before the send. The write waits for its read-back and the cycle reads
the charger meanwhile, so by `note_write` `sig` can already be the
reading AFTER the write; armed on that, a car that then stays paused
(constant power and read-back) was called stuck 60 s later."""
self.mute_until = float("inf")
self.pre_sig = (self.sig,)
def end_write(self, now: float) -> None:
"""EV-12: the write returned (or failed). The mute runs
@@ -805,6 +816,10 @@ class CarTracker:
plainly alive is not a stuck reading. `polls` are the samples the
write itself saw while it waited, `[(time, ChargerReading)]`."""
self.mute_until = now + OWN_WRITE_MUTE_S
# The baseline: the reading before the send (`begin_write`), never one
# that arrived while the write waited.
base = self.pre_sig[0] if self.pre_sig else self.sig
self.pre_sig = ()
try:
moved = was_a is None or abs(float(to_a) - float(was_a)) \
>= STUCK_MIN_A
@@ -816,13 +831,13 @@ class CarTracker:
return
if ok:
self._pend = None
self.armed_at, self.armed_sig = now, self.sig
self.armed_at, self.armed_sig = now, base
return
if self._pend is not None:
return # an earlier refusal's window
before = [x for x in self._ring if x[0] <= now]
pre = [max(before, key=lambda x: x[0])[1]] if before else []
self._pend = {"t": now, "pre": pre, "sig": self.sig}
self._pend = {"t": now, "pre": pre, "sig": base, "post0": False}
later = [(t, _life_vals(r)) for t, r in polls]
later += [(t, v) for t, v in self._ring if t > now]
for t, v in sorted(later, key=lambda x: x[0]):
@@ -844,6 +859,12 @@ class CarTracker:
return
if t <= p["t"]:
p["pre"] = (p["pre"] + [vals])[-8:] # taken before the send
elif not p.get("post0", True):
# EV-36 (SPIKE-05 C4): the first sample after the send may carry a
# value newer than the cycle's last read but frozen since; it is
# the baseline, and life must show in a sample after it.
p["post0"] = True
p["pre"] = (p["pre"] + [vals])[-8:]
elif t <= p["t"] + TOOK_S and _alive(vals, p["pre"]):
self._pend = None # life: nothing to arm
return
+8 -1
View File
@@ -423,8 +423,15 @@ class CarMixin:
if self.p1_enabled:
# The meter's own bound (`meter_max_age_s`) may be longer than
# `stale_input_s`; a car write never comes from an older reading.
# Rig round 1: only where the age measures ARRIVAL. On `ha_signed`
# it measures the time since the value CHANGED (p1.py, Home
# Assistant emits changes only), so a healthy meter under a flat
# load would read as stale and pause the car; there the source's
# own `meter_max_age_s` (the cycle's `inputs_ok`) is the bound.
age = self.p1.age_s()
if age is None or age > stale:
src = str(self.o.get("meter_source") or "")
bound = None if src == "ha_signed" else stale
if age is None or (bound is not None and age > bound):
return None
r = self.car.reading
if r is None or not r.available or not self.car.fresh(mono):