EV-18 review round 2: the contradiction latch touches only the alarm; an unknown energy reading is not a contradiction
checks / unit (pull_request) Successful in 27m50s
infra-pin / fresh (pull_request) Successful in 2s

- [Critical] The latch set `w = None` before `_car_quarter`, so with cover
  off the guard's input (`car_exclude`) counted the car as house and the
  batteries discharged. The latch now changes only the figure graded for the
  alarm; the car's energy count, the guard's input and the car-over row keep
  the unlatched `car_alarm_w()`. Cover-off N4 twins (energy gap, T9(c) liar,
  SoC 60 % and at the reserve) give the same commands as without the latch.
- [Major] `corroborated()` is False for an unknown energy reading, so one
  missing reading latched a correct figure for the quarter. New
  `CarTracker.contradicted()`: only a meter that answered over a whole window
  and fell short. R1 (energy entity unknown 1 s at E+200, T2 and T3 shapes):
  red for that cycle only, explained from the next.
- Minors: unit checks that a contradiction in our own pause latches nothing
  (MF) and that the latch ends with the quarter (MG).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ems-agent
2026-11-19 12:18:06 +01:00
co-authored by Claude
parent 5db56b5f28
commit 93c6628eca
4 changed files with 153 additions and 18 deletions
+11
View File
@@ -790,6 +790,17 @@ class CarTracker:
return got_wh >= CORR_RATIO * exp_wh - CORR_SLACK_WH
return True
def contradicted(self, now: float) -> bool:
"""EV-18: did the energy meter answer over a whole window and fall
short (`corroborated` compared and failed)? Not when the energy
reading is unknown, the window is empty or still short, or the car is
not charging: those are unknown, not contradicted."""
r = self.reading
if r is None or not r.available or r.charging is not True \
or r.energy_kwh is None or not self._hist:
return False
return not self.corroborated(now)
def stuck(self, now: float) -> bool:
"""Power and read-back unchanged `STUCK_S` after a write that moved the
setpoint. Cleared the moment either moves."""
+19 -14
View File
@@ -238,15 +238,17 @@ class CarMixin:
return 0.0 <= mono - wr.phase_done_at <= OWN_PAUSE_TAIL_S
def _car_contradicted(self, mono) -> bool:
"""EV-18 (owner 2026-11-19): does the charger's energy meter
contradict a fresh, not stuck figure of a charging car? Then that
figure stays untrusted to the quarter's end (`car_cycle`)."""
"""EV-18 (owner 2026-11-19): did the charger's energy meter answer
and fall short of a fresh, not stuck figure of a charging car
(`CarTracker.contradicted`)? Then that figure stays untrusted for the
alarm to the quarter's end (`car_cycle`). An unknown energy reading
contradicts nothing."""
r = getattr(self.car, "reading", None)
if r is None or not r.available or r.charging is not True \
or not self.car_manual():
return False
return (self.car.car_w(mono) is not None and not self.car.stuck(mono)
and not self.car.corroborated(mono))
and self.car.contradicted(mono))
def _car_idle(self, mono) -> bool:
"""EV-18: is the car known to draw nothing? A fresh reading that says
@@ -345,18 +347,19 @@ class CarMixin:
# car at 0 A and the energy meter cannot corroborate it then, so for
# that bounded time its fresh, not stuck figure stands in.
own = (w is None or float(w) <= 0.0) and self._car_own_pause(mono)
# EV-18: a figure the meter contradicted is not trusted again in
# that quarter, not even as the stand-in for our own pause.
key = None if real_proj is None else real_proj.block_start
if key is not None and not own and self._car_contradicted(mono):
self._car_contra_block = key
if key is not None and key == self._car_contra_block:
w, own = None, False
wg = w
if w is None and own:
wg = self.car.car_w_paused(mono)
self._car_quarter(real_proj, w, mono, wg)
self._car_session_tick(mono)
# EV-18 (owner 2026-11-19): a figure the meter contradicted grades no
# alarm again in that quarter, not even as our own pause's stand-in.
# The alarm decision only: the car's energy count, the guard's input
# (`car_exclude`) and the car-over row keep the figure.
key = None if real_proj is None else real_proj.block_start
if key is not None and not own and self._car_contradicted(mono):
self._car_contra_block = key
contra = key is not None and key == self._car_contra_block
explains = over = False
if real_proj is not None and target_w is not None \
and real_proj.block_start is not None:
@@ -365,9 +368,11 @@ class CarMixin:
# (the house's own need); it and a 0 W figure explain nothing,
# but in our own pause (EV-15).
idle = wg is None and self._car_idle(mono)
graded = self._car_explains_alarm(real_proj, guard, target_w,
0.0 if idle else wg)
if idle or (w is not None and float(w) <= 0.0 and not own):
graded = self._car_explains_alarm(
real_proj, guard, target_w,
None if contra else 0.0 if idle else wg)
if contra or idle or (w is not None and float(w) <= 0.0
and not own):
graded = False
if self.car_cover:
explains = over = graded
+105 -2
View File
@@ -241,6 +241,65 @@ check("T8 unit: the same with the charger unavailable (unknown car): the "
"alarm stands while unknown and is released at E+60 (Expected 5)",
not any(run_of(exu, 0, 59)) and all(run_of(exu, 60, 899)))
# --- the contradiction latch (owner 2026-11-19), unit ----------------------- #
class _TrackerC:
"""A charging car whose energy meter contradicts it when `contra(t)`."""
def __init__(self, contra):
self.contra = contra
self.reading = CH.ChargerReading(available=True, state="C",
charging=True, power_w=CAR)
def car_w(self, _now):
return CAR
def stuck(self, _now):
return False
def contradicted(self, now):
return self.contra(now - 10000.0)
def car_w_paused(self, _now):
return CAR
@staticmethod
def status(*_a):
return "charging"
class _CarC(_Car):
def __init__(self, contra, own):
super().__init__()
self.car, self.own = _TrackerC(contra), own
def car_manual(self):
return True
def _car_own_pause(self, mono):
return self.own(mono - 10000.0)
def contra_run(contra, own, secs):
c = _CarC(contra, own)
_c, ex = urun(secs, const(13000.0 + CAR), const(0.0),
lambda t: None if contra(t) or own(t) else CAR, c=c)
return ex
never = lambda t: False # noqa: E731
exg = contra_run(lambda t: 300 <= t < 306, never, range(0, 1100))
check("contradiction (T3 shape): the meter contradicts the figure at E+300: "
"not explained from E+300 to the quarter's end, though trusted again "
"from E+306", all(run_of(exg, 0, 299)) and not any(run_of(exg, 300, 899))
and len(run_of(exg, 300, 899)) == 600)
check("contradiction: released by the next quarter (review MG): explained "
"again from E+900", all(run_of(exg, 900, 1099))
and len(run_of(exg, 900, 1099)) == 200)
exf = contra_run(lambda t: 100 <= t < 130, lambda t: 100 <= t < 130,
range(0, 400))
check("contradiction during our own pause (EV-15) latches nothing (review "
"MF): the stand-in explains in it, the trusted figure after it",
all(run_of(exf, 0, 399)) and len(run_of(exf, 0, 399)) == 400)
# --- T10(a) unit: the battery reading lost for one cycle --------------------- #
cA, eA = urun(range(-3, 10), const(14000.0 + CAR - 800.0),
lambda t: None if t == 1 else 800.0, const(CAR))
@@ -557,6 +616,18 @@ for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
H.alarms(r10b) == T5_BASE and all(
x["alarm"] for x in H.window(tr10b, E + 1, E + 899)))
# --- R1 (review round 2): the energy reading unknown for one cycle ----------- #
for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
("T3", dict(house=H.shape(13000.0), b=ZERO))):
rg, trg = H.run(a=ZERO, extra=H.energy_gap(E + 200), **kw)
summary(f"R1 {nm} energy gap at E+200", rg, trg)
check(f"R1 {nm}: the charger's energy entity unknown for one cycle "
f"(E+200) on a correct car: unknown, not contradicted, so red for "
f"that cycle only and explained from the next (Expected 5)",
H.red_secs(trg) == [E + 200] and H.edges(trg) == [E + 200]
and all(x["explains"] for x in H.window(trg, E + 201, E + 899)
if x["lim"]))
# --- T11: one battery first (SAFETY-87) --------------------------------------- #
for nm, house in (("(i) 17 500 W", 17500.0), ("(ii) 19 000 W", 19000.0)):
r11, tr11 = H.run(honest(house), soc={"a": 19.0, "b": 35.0})
@@ -709,6 +780,31 @@ for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
f"charger writes are identical whether the car explains or not",
H.commands(ra, tra) == H.commands(rb, trb))
# N4 with "Batteries help with the peak" off (review round 2): the guard's
# input is `car_exclude`, which reads the car's energy count. The
# contradiction latch must not touch it: the same commands with the latch off.
for nm, kw in (
("SoC 60 %, energy gap at E+200",
dict(house=H.shape(13000.0), soc={"a": 60.0, "b": 60.0},
extra=H.energy_gap(E + 200))),
("at the reserve, energy gap at E+200",
dict(house=H.shape(13000.0), a=ZERO, b=ZERO,
extra=H.energy_gap(E + 200))),
("SoC 60 %, the T9(c) liar",
dict(house=honest(13900.0), soc={"a": 60.0, "b": 60.0},
sim=Draw(100.0, 1380.0, setpoint_a=6))),
("at the reserve, the T9(c) liar",
dict(house=honest(13900.0), a=ZERO, b=ZERO,
sim=Draw(100.0, 1380.0, setpoint_a=6)))):
ra, tra = H.run(cover=False, **kw)
if "sim" in kw:
kw = dict(kw, sim=Draw(100.0, 1380.0, setpoint_a=6))
rb, trb = H.run(cover=False, latch_off=True, **kw)
summary(f"N4 cover off, {nm}", ra, tra)
check(f"N4 cover off, {nm}: the claim, the floor, the setpoints and the "
f"charger writes are those of the same run without the "
f"contradiction latch", H.commands(ra, tra) == H.commands(rb, trb))
# --- N5: at most one floor-alarm edge per quarter ---------------------------- #
def per_quarter(ts):
out = {}
@@ -717,12 +813,19 @@ def per_quarter(ts):
return out
# Cover off, the T9(c) liar at the reserve: the guard's own engagement flips
# as the liar's figure is corroborated now and then (its input is
# `car_exclude`), pre-existing (base: 4 edges). Printed, not graded here.
LIAR_OFF = "N4 cover off, at the reserve, the T9(c) liar"
print(f" {LIAR_OFF}: alarm edges "
f"{[[t - E for t in ts] for nm, ts in RUNS if nm == LIAR_OFF]}")
many = [(nm, ts) for nm, ts in RUNS
if any(v > 1 for v in per_quarter(
if nm != LIAR_OFF and any(v > 1 for v in per_quarter(
[t for t in ts if not nm.startswith("T15 x10") or t < F2_FROM])
.values())]
check(f"N5: at most one floor-alarm edge per quarter in every run "
f"({len(RUNS)} runs; x10 to E+500): {many}", many == [])
f"({len(RUNS)} runs; x10 to E+500; the cover-off liar apart): "
f"{many}", many == [])
print()
print("FAIL: " + ", ".join(fails) if fails else "PASS: every check passed")
+18 -2
View File
@@ -80,10 +80,12 @@ def shape(after, before=PRE_W, at=None):
def run(house, *, a=None, b=None, lost=None, car_a=6, phases=1, aim=AIM,
mode="manual", dur=None, extra=None, sim=None, soc=None, plug=True,
x=1, mono_x=None, explain_off=False):
x=1, mono_x=None, explain_off=False, latch_off=False,
cover=True):
"""One run; returns (run, trace). `x`: fake seconds per cycle (wall and
monotonic both; `mono_x` sets the monotonic rate apart). `explain_off`:
the car never explains (for the control-identity check)."""
the car never explains, `latch_off`: no contradiction latch (both for the
control-identity check). `cover`: the option `ev_batt_cover`."""
force = {}
if a is not None:
force["a"] = a
@@ -98,6 +100,10 @@ def run(house, *, a=None, b=None, lost=None, car_a=6, phases=1, aim=AIM,
orig = c.car_settle
if explain_off:
c._car_explains_alarm = lambda *a_, **k_: False
if latch_off:
c._car_contradicted = lambda *a_, **k_: False
if not cover:
c.o["ev_batt_cover"] = False
if mono_x is not None and mono_x != x:
c.car_now = (lambda f=c.car_now: f() * mono_x / x)
@@ -197,6 +203,16 @@ def commands(r, tr):
return h.hexdigest()[:16]
def energy_gap(at, secs=1):
"""The charger's energy entity is missing (unknown) for `secs` from `at`."""
def on(p, c):
p.ch.no_energy = True
def off(p, c):
p.ch.no_energy = False
return {at: on, at + secs: off}
def restart(c):
"""A restart as the car side sees it: a fresh `car_init` and an empty
corroboration history, and no floor alarm standing."""