Files
goodwe-addon/goodwe_controller/DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md
T
glenn schrooyenandClaude de06a2c6f5
checks / unit (pull_request) Failing after 38m55s
infra-pin / fresh (pull_request) Successful in 1s
MAINT-28 fix round 5: while the pause holds, the batteries give only what the guard needs
H-1: one site limit while the pause holds (the period's largest floor, never under this cycle's), so the other pack no longer gives for the house. New live-try test (A 11 %, B 25 %, 90 min at 6.5 kW) red on 07d23d2. M-1: a 45-min rig-shape test that goes red when the settled check is forced True. M-2/L-2: DECISIONS. CHANGELOG line. test_safety84 n2_charge_banked re-pinned (quarters 3349 and 3950 W, aim 3950 W).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-14 16:40:54 +01:00

11 KiB

MAINT-28 - during a real peak the maintenance charge stays paused

Status: fix-forward after the rig FAIL (TEST-23, f3f9483). Tests: test_maint28.py, test_maint28b.py. No option added; the peak aim, the month peak and the MAINT-13 numbers are unchanged. MAINT-24 follow-up (rig test finding F-1, reports/MAINT-24-test-report.md).

What happened (rig x10, house 6.5 kW, month aim 5.95 kW, A in maintenance CHARGE)

peakguard.shaping_suspended() pauses the charge while the forecast is over the aim or the guard is engaged. MAINT-24 moved the aim from 3450 W to the month aim (SAFETY-80), so the pause no longer lasts the whole peak: the guard gives, its projection drops under 5950 W and it idles ("heading for 5 6xx W, under this month's peak"), the pause ends, the floor charges A 150-460 W, the grid goes to 6.3-6.9 kW, the guard trips again. A flipped charge/give 468 times in 45 min (base 02eac3b 11). The quarters stayed at the aim; the cost was a battery working against itself and a grid that swung 5.4-6.9 kW.

The change

peakguard.shaping_held(suspended, held, forecast, aim, house): suspended is the old shaping_suspended(), and once it was true the pause stays until the house (grid + battery power, the load without our own charge) is MAINT_RESUME_UNDER_W = 300 W under the aim. A guard that is engaged or a forecast over the aim still pauses at once. House unread: the forecast stands in; neither read: no pause (SAFETY-63). ctl_cycle.py keeps the flag in _maint_peak_hold. The hold is for N=2 and up, and only where MAINT-24 moved the aim (a banked month peak above peak_cap_w, so the aim is above cap minus margin). Elsewhere the old rule stays, byte for byte: SAFETY-87's N=1 digests (n1_charge_low) and SAFETY-119's N=2 charge at 5050 W over a 5000 W cap with no banked peak are pinned, and 1b5f7c9 behaves as 02eac3b there (a chase that was not a MAINT-24 regression).

Why the house and not the forecast: while A gives, the forecast sits just under the aim by design, so no forecast margin is both safe and reachable. The house is the meter reading plus the batteries' power (grid + site_batt_w): the net demand the meter would see with no battery at work. Solar is already in it, and that is right: the aim is a limit on what the meter takes, so a sunny hour that lowers the net demand is real room, and a cloud that raises it brings the hold back at once. It is not the gross load, and it would be wrong to add PV back (that would hold the pause on room the meter really has). It does not stay put when a battery steps: see "Fix-forward" below.

Why 300 W: the house wanders +-50 W; once the charge resumes it settles at (aim - house) / 2, so 300 W gives at least 150 W, three times the noise, and charging less than that is not worth a restart.

The flag lives only while the charge-only branch is taken: every cycle that reaches the maintenance loop starts it at False, so a maintenance that ended, a mode change or a missing aim cannot carry a stale True into the next charge (test_maint28.py part 1b). cycle() has two returns before that loop, and the flag is kept through them on purpose: "inputs missing" and "readings late" (SAFETY-128) are holds of under stale_after seconds that write nothing and decide nothing, so the next full cycle sees the same charge and the same peak. A missed poll must not end a peak pause; a reset there would restart the charge on it (_maint_shape_suspended is kept through them the same way).

It only ever keeps the maintenance charge off. No cut-back is delayed or weakened: the guard's claim is filed as before. While the pause is held, the pack in CHARGE gives only its share of the guard's floor (0 W if the guard holds it at its reserve), and the batteries together give only what the guard needs (see Fix-forward, F-2 and H-1). The first version let A give for the house; it was dropped.

Numbers (sim, real cycle(), A rated 2500 W)

House 3000 -> 6500 W for 45 min -> 3000 W, +-50 W every 5 s, banked month peak 6000 W (aim 5950 W), forecast = quarter average so far plus the rest at the present grid (scratch/MAINT-28/dev/m28_repro.py; test_maint28.py runs the same shape for 15 min to keep the suite short).

45 min load base 02eac3b 1b5f7c9 MAINT-28 (f3f9483, without the lag)
A charge/give reversals 0 52 1 (the first trip)
A charging seconds in the load (of 2700) 0 367 301 (before the first trip)
quarter averages (W) 5959 5950 5950 5438 5502 5356 5923 5924 5041 4479 5356 4012 4000 4226 4476
A out / in (kWh) 0.65 / 0 0.45 / 0.51 1.67 / 0.56
charge back after the load - 3 s 3 s

Rig (MAINT-24 test report, F-1): 468 reversals in 45 min on 1b5f7c9, 11 on 02eac3b. Live shape (house 3000 W): no pause, A 1475 W, as MAINT-24.

Tests and mutants

test_maint28.py: part 1 the real peak, 1b the stale hold, 2 shaping_held() edges, 3 the unchanged cases (digests equal 1b5f7c9). On 1b5f7c9 itself (hold stubbed out) part 1 and 1b fail. Mutants, each red: M1 hold state not kept (held always False: the 1b5f7c9 behaviour); M2 resume line - to +; M3 house not passed; M4 the per-cycle reset removed; M5 the N=1 gate removed (digest n1_peak: N=1, banked peak, house 6500 W); M6 the aim gate removed (digest n2_nobank).

Not changed

MAINT-24's rate and its tests, N=1, the drain, modes off (digests of 1b5f7c9). The pause for a late or missing forecast.

Fix-forward (rig FAIL F-1, F-2; reports/MAINT-28-test-report.md)

The sim had no battery-reading lag, and the first version said the 300 W line is far larger than the lag moves the estimate. That was wrong. The rig publishes a battery's power every 10 s; the meter is newer. After each guard step charge -> give (+500-1000 W) the next meter reading shows the give and the battery reading still shows the charge, so grid + site_batt_w drops by the step, under the 5650 W line: 69/69, 132/133, 215/215, 51/51 releases at a median 5430 W with the house at 6450 W or more. Test: test_maint28b.py, sim Lag.batt_period_s.

F-1: the pause ends only on a settled estimate. Controller._batts_settled() is False from a step UP of a unit's command (MAINT_STEP_W = 100 W more give or less charge, the SAFETY-128 pending size) until its reading changed PLANT_SETTLE_S (6 s) after the step, or BATT_OBLIGED_S (17 s) have passed. peakguard.shaping_held(..., settled) then keeps the pause. A step down makes the estimate err high, which only holds the pause, so it waits for nothing. Measured in the 45 min sim, pause on: settled, the estimate was at most 146 W under the real house (0 cycles over 300 W); not settled, up to 1933 W under (725 of 1611 cycles over 300 W). Sim, 45 min, house 6500 W: 83 of 83 releases on a stale estimate (f3f9483) -> 0; flips 148 -> 1 (1b5f7c9 210). Charge is back 4 s after the load (12 s in test_maint28b), not 0: the first settled estimate. No cut-back is touched.

F-2 and the cap. Owner 2026-11-13 ("1" = cap): while the pause holds, the pack in maintenance CHARGE gives only what the guard claims for the peak, at any SoC; other packs unchanged (replaced by H-1 below). Owner 2026-11-13 ("ok max", relayed by the manager): accepted "while the hold is on, the pack in maintenance CHARGE gives at most the largest floor the peak guard claimed in the current quarter" (about 0.37 kWh per 45-min peak in the sim; quarters at or under the aim).

H-1 (review 2026-11-14, owner decision 2026-11-14): the batteries together give only what the guard needs. With the cap on A alone, the loop gave for the whole house with B (Cheap hours): in the live-try shape (A 11 % in CHARGE, B 25 %, house 6.5 kW for 90 min) B gave 4.6 kW, went from 25 to 10 % in 43 min, and two quarters were 6502 and 6499 W against the month peak 6000 W. So while the pause holds, _m28_share() also files one site limit (source charge, P_MAINT_SHAPE, per-site _m28_site): hi = the largest floor of the period, never under this cycle's floor. The guard's claim is not cut: hi is at least the floor, P_PEAK outranks P_MAINT_SHAPE, and _peak_on_able still places the whole floor. Outside the hold nothing is filed. Live try, same shape (test_maint28b): quarters 5357 to 5911 W (aim 5950), B 0.86 kWh and ends at 20.6 % (1b5f7c9: 1.0 kWh, 19.8 %), B switches give/idle once, A never. The re-pinned n2_charge_banked quarters are 3349 and 3950 W (aim 3950).

The rule as built (Controller._m28_share()): while the pause holds (N>=2, month aim above the cap) the pack gets a unit limit hi = the largest part of the guard's floor placed on it in this 15-minute period. Its part in a cycle is the floor less what the other units are placed at in this cycle's split without that limit, so a part the guard's split puts on the other pack is not this pack's. A pack the guard holds at its reserve (peak_guard.held) gets 0 W and its part starts again from 0 W. The largest part is kept per unit (_m28_hi, keyed by the unit) and dropped in a new period or when the pause ends; only one pack can be in maintenance CHARGE anyway (maintenance.arbitrate(), one slot per site).

Why the largest of the period and not the present part: the guard alone lands the quarter 9.5-10 W over its aim in the sim (SAFETY-126: its own projection ends on 5950.0 W but the meter reading it counts lags the true grid), and with the present part only, test_maint28 part 1 ends at 5960.1 W; the largest of the period lets the loop keep A up and it ends at 5925 W. Why not hi = 0 W: with the other pack under its reserve the guard needs this one (test_maint28b, house 12 kW, B at 18 %: A gives 1.07 kWh for the guard).

Tests (test_maint28b, 13-min load, A 5 kW): A at 49 %: SoC drop 0.64 point (the owner's 0.37 kWh per 45 min is 0.70 point here; the check is <= 0.70). Both packs able, B on Cheap hours: B is placed nothing, A's limit is the period's largest floor (3087 W) and A gives 3081 W. B on Solar first (it gives for the house): A's limit stays under the period's largest floor by 500 W or more in 740 of 744 paused cycles, and the quarters stay under the aim.

Sim, rig shape, 45 min, house 6500 W (load from minute 10), A in CHARGE at 49 %, B 30 % on Cheap hours: A gives 0.17 kWh (f3f9483 0.44), SoC 50.5 -> 49.0 %, charge/give flips 1, give/idle switches 1, quarters 5358 5897 5911 5176 4477 W, charge back 4 s after the load; B gives 0.23 kWh (before H-1 3.04, f3f9483 0.32). test_safety84 n2_charge_banked: banked quarters 3349 and 3950 W against the aim 3950 W.

Mutants, each red: the freshness check dropped (always settled); the cap dropped; the other units' placement dropped (part = the whole floor); one cap for the site instead of per unit; the 0 W for a held pack dropped (all in test_maint28b.py); the period's largest dropped (present part only: test_maint28.py part 1 quarter 5960 W); _batts_settled() replaced by True at the hold in ctl_cycle.py (the 45-min rig shape in test_maint28b.py, one stale release); the site limit dropped (the live try in test_maint28b.py: quarters 6502 and 6499 W, B 2.91 kWh to 10.0 %).