MAINT-28 fix-forward round 4: the paused pack's cap is its own part of the guard's floor, the largest of the period, per unit
checks / unit (pull_request) Successful in 27m27s
infra-pin / fresh (pull_request) Successful in 2s

Owner 2026-11-13 ("ok max", relayed by the manager): while the pause holds,
the pack in maintenance CHARGE gives at most the largest floor the guard
claimed in the quarter. The cap is now that pack's own part of the floor
(the floor less what the other units are placed at, split without the cap),
the largest in the 15-minute period, kept per unit (`_m28_hi`). 0 W while
the guard holds it at its reserve. test_maint28b: SoC check stated against
the owner-accepted give (0.70 point, measured 0.64); both-packs-able tests
(B on Cheap hours, B on Solar first); per-unit state and the one-slot
arbitrate. test_maint28 unchanged (5925 W). Pins: test_safety84
n2_charge_banked, test_packshare's one-resolve AST pin (a second call with
the same weights).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
glenn schrooyen
2026-11-13 23:42:23 +01:00
co-authored by Claude
parent fb4a449591
commit 07d23d2eed
7 changed files with 173 additions and 34 deletions
+12 -14
View File
@@ -29,7 +29,7 @@ from . import shadow
from .price import Uncertainty
from .tariff import next_quarter
from .watchdog import loop_is_following
from .ctl_trade import pack_energy_of
from .ctl_trade import M28_REASON, pack_energy_of
from .rows import why_key, why_raised
_LOG = logging.getLogger("goodwe")
@@ -589,25 +589,20 @@ class CycleMixin:
"suspended so the peak claim is not "
"contradicted",
hint=messages.hint("maint_paused"))
# MAINT-28: while held this pack gives at most the most the
# guard claimed this period (0 W under its reserve: the
# guard places its claim on the other packs).
# MAINT-28: while held this pack gives at most the most of
# the guard's floor placed on it this period
# (`_m28_share()`).
# DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md
_q = int(now.timestamp() // 900)
if self._m28_q != _q:
self._m28_q, self._m28_hi = _q, 0.0
if self.peak_guard is None or \
inv.name not in self.peak_guard.held:
self._m28_hi = max(self._m28_hi, max(
(c.lo for c in claims
if c.source == peakguard.SOURCE), default=0.0))
shape = ((0.0 if self.peak_guard is not None
and inv.name in self.peak_guard.held
else self._m28_hi, "peak hold")
else max([c.lo for c in claims
if c.source == peakguard.SOURCE]
+ [self._m28_was(self.actuator_of(
"maintenance", inv), now)],
default=0.0), M28_REASON)
if _m28 else None)
else:
self._maint_shape_suspended = False
self._m28_hi = 0.0
hi = 0.0
reason = "charge-only"
if self.cheap:
@@ -875,6 +870,9 @@ class CycleMixin:
self.loop_clamp_facts = ()
self._loop_decision = None
# MAINT-28: a paused pack gives at most its largest part of the floor
# in this period.
self._m28_share(claims, now)
# SAFETY-28. A new resolution is a new tick, and the previous record is
# stale from this line onwards. Incremented BEFORE resolve() so that the
# record resolve() builds is stamped with the tick it is for.
+39 -1
View File
@@ -10,7 +10,7 @@ from datetime import datetime, timedelta, timezone
from . import arbitrage
from .arbiter import (
ACTUATOR_SITE, Claim, P_MAINTENANCE, P_MAINT_SHAPE, P_PEAK, SET,
pre_resolve,
pre_resolve, resolve,
)
from . import allocator
from . import dayplan
@@ -53,6 +53,8 @@ HOUSE_PROFILE_KEY = "house_profile"
# MAINT-28: a step of a battery's command, in W, after which its reading is not
# current until a changed one arrives (`Controller._batts_settled()`).
MAINT_STEP_W = 100.0
# MAINT-28: the reason on a paused pack's cap (`Controller._m28_share()`).
M28_REASON = "peak hold"
# OPT-34: the level of a night grid charge that has started, so it does not
@@ -740,6 +742,42 @@ class TradeMixin:
ok = False
return ok
def _m28_share(self, claims, now) -> None:
"""MAINT-28: each paused pack's cap (0 W if the guard holds it at its
reserve) set to the largest part of the guard's floor left to it in
this 15-minute period: the floor less what the other units are placed
at in this cycle's split without the cap. Kept per unit in `_m28_hi`,
dropped while the unit is not paused or is held.
DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md"""
floor = max((c.lo for c in claims if c.source == peakguard.SOURCE),
default=0.0)
g = self.peak_guard
held = {self.actuator_of("maintenance", inv) for inv in self.inverters
if g is not None and inv.name in g.held}
q, seen = int(now.timestamp() // 900), set()
for i, c in enumerate(claims):
if c.source != "maintenance" or c.reason != M28_REASON \
or c.actuator == ACTUATOR_SITE or c.actuator in held:
continue
seen.add(c.actuator)
shares = resolve(claims[:i] + claims[i + 1:], units=self.units,
live=self.live_units(), weights=self.pack_weights,
reserve=self._held_back()).shares
part = max(0.0, floor - sum(float(w) for u, w in shares.items()
if u != c.actuator))
hi = max(part, self._m28_was(c.actuator, now))
self._m28_hi[c.actuator] = (q, hi)
claims[i] = dataclasses.replace(c, hi=hi)
# A unit not paused (or held at its reserve) starts again from 0 W.
for u in set(self._m28_hi) - seen:
del self._m28_hi[u]
def _m28_was(self, u, now) -> float:
"""MAINT-28: unit `u`'s cap so far in this 15-minute period, 0 W in
a new one (`_m28_share()`)."""
q, hi = self._m28_hi.get(u, (None, 0.0))
return hi if q == int(now.timestamp() // 900) else 0.0
def _reseed_drop(self, live) -> None:
"""SAFETY-96, N>=2: a battery that drops out of the split (stale link)
leaves the loop's start point, so the others take over at one slew step
+1 -1
View File
@@ -506,8 +506,8 @@ class Controller(InputsMixin, WritesMixin, TradeMixin, CycleMixin, AlarmsMixin,
self._peak_needed = False
self._maint_shape_suspended = False
self._maint_peak_hold = False # MAINT-28
self._m28_q, self._m28_hi = None, 0.0 # MAINT-28: period, its most guard claim
self._m28_step = {} # MAINT-28: unit -> (command, step at)
self._m28_hi = {} # MAINT-28: unit -> (period, cap)
# OPT-11: battery modes, off by default (SAFETY-10 section 1). Each
# battery's mode and on/off switch live in the store, not in options,
# so a change applies at once (`pack_use`, `pack_mode`).