EV-20 SPIKE-06: stuck start cap backs off instead of holding
checks / unit (pull_request) Successful in 44m16s
infra-pin / fresh (pull_request) Successful in 2s

Under one stuck verdict Solar still makes at most MAX_TRIES starts and gives
one CHARGER_REFUSED; then one more start after 15 min and one every 30 min
(each by the start rule and the write clock), so a fault that clears is
found again. The episode ends when the reading follows a start, on a press
of Solar, Off, Manual, shadow or a stop. Rows: cap, backoff times,
recovery, press, episode end; T28 (b) no flapping. DOCS and DECISIONS.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
Claude
2026-11-23 19:01:36 +01:00
parent b99f8c7e52
commit d17f15b33c
5 changed files with 135 additions and 47 deletions
+36 -12
View File
@@ -64,6 +64,8 @@ PHASE_GAP_S = 600.0 # at most one phase switch per this
WRITER_S = 30.0 # a differing read-back this long is another writer
RETRY_S = 60.0 # a write the charger did not take, tried again after
MAX_TRIES = 3 # ... this many times, then it waits for the user
STUCK_BACKOFF_FIRST_S = 900.0 # Solar under a stuck verdict, its starts used
STUCK_BACKOFF_S = 1800.0 # up: one more after 15 min, then every 30 min
TOL_A = CH.TOOK_TOL_A
@@ -717,6 +719,8 @@ class SolarWriter(ManualWriter):
self.other_at = None # C6: Manual's latest non-zero write
self.on_owed = None # C1: told when an own 0 A is out / back
self.stuck_starts = 0 # SPIKE-06 C12: starts under one stuck verdict
self.stuck_wait = None # ... used up: the next start not before
self.stuck_warned = False # ... and its one CHARGER_REFUSED was given
def owe_start(self) -> None:
"""C1: the add-on starts in Off while an exit 0 A of its own was still
@@ -724,6 +728,15 @@ class SolarWriter(ManualWriter):
so the 0 A is owed (once it may write), retried by the exit rule."""
self.start_owed = self.engaged = True
def _stuck_end(self) -> None:
"""SPIKE-06: a stuck episode ends (the reading followed a start, a
press of Solar, Off, Manual or shadow): starts counted afresh, and
its CHARGER_REFUSED is cleared."""
if self.stuck_warned:
self.gave_up = False
self.stuck_starts, self.stuck_wait = 0, None
self.stuck_warned = False
def _owed(self, pending: bool) -> None:
if self.on_owed is not None:
self.on_owed(pending)
@@ -758,7 +771,7 @@ class SolarWriter(ManualWriter):
held = self.hold or self.mismatch_since is not None
super().user_changed()
self.gave_up, self.fails, self.fail_at = False, 0, None
self.stuck_starts = 0
self._stuck_end()
if held:
self.last_a = None
self.sent_a, self.taken = None, True
@@ -772,6 +785,8 @@ class SolarWriter(ManualWriter):
zero = float(a) <= TOL_A
if not zero and tracker is not None and tracker.stuck(now):
self.stuck_starts += 1 # C12: a start under a stuck verdict
if self.stuck_wait is not None:
self.stuck_wait = now + STUCK_BACKOFF_S # a backoff try
if zero:
self.zero_at = self.zero_sent_at = now
self._owed(True) # C1: kept with the mode until back
@@ -1007,6 +1022,7 @@ class SolarWriter(ManualWriter):
self._adopt(cur) # round 9: a late read-back
self._mark(r, now)
if mode != SOLAR:
self._stuck_end()
self.would = None
if mode == OFF and self.start_owed:
if not writing:
@@ -1026,6 +1042,7 @@ class SolarWriter(ManualWriter):
else self.plan.n
n_now = 1 if self.single else n_real
if not writing:
self._stuck_end()
# Shadow, Stop, a safety stop, stopping: the way-out 0 A while
# owed, then nothing. The watch goes on (another writer is held
# for every reader) and so does the plan, for the card.
@@ -1041,24 +1058,31 @@ class SolarWriter(ManualWriter):
fault = ("error" if (r.error or r.state in ("E", "F")) else
"stuck" if stuck else None)
if not stuck:
if self.stuck_starts >= MAX_TRIES and self.gave_up:
self.gave_up = False # the reading moved: start afresh
self.stuck_starts = 0
self._stuck_end() # the reading moved: start afresh
if fault == "stuck" and not self.live:
# SPIKE-06 C12/C14 (option 2): no current of Solar's own may stand
# (its own 0 A stands, or Solar was just chosen), so a stuck
# verdict no longer holds the car: Solar's normal step writes its
# 0 A first over a current that is not its own, then the start
# rule. A start moves the reading (the verdict clears) or is not
# taken: then the 0 A again, and after MAX_TRIES such starts under
# one verdict, CHARGER_REFUSED and the 0 A stands (EV-04's rule).
# rule. A start moves the reading (the episode ends) or is not
# taken: then the 0 A again. After MAX_TRIES such starts, one
# CHARGER_REFUSED, then one more start after 15 min and one every
# 30 min (PM decision): a fault that clears is found again.
if self.stuck_starts < MAX_TRIES:
fault = None
elif not self.gave_up:
self.gave_up = True
_LOG.warning("The charger did not take the current, so the "
"add-on stops asking until you press Solar: "
"CHARGER_REFUSED.")
else:
if self.stuck_wait is None:
self.stuck_wait = now + STUCK_BACKOFF_FIRST_S
if not self.stuck_warned:
self.stuck_warned = True
_LOG.warning("The charger did not take the current, so "
"the add-on tries again in 15 min, then "
"every 30 min: CHARGER_REFUSED.")
if now >= self.stuck_wait:
self.gave_up = False
fault = None
else:
self.gave_up = True
if fault is not None:
# 0 A while owed, then no write until it clears; then the start
# rule. A stuck reading cannot confirm the 0 A.