Repository navigation
fix(control): a battery ends fuse relief only as far as the phase can take it - #1847
Conversation
… take it Field matrix relief rows (#1763's site, 25 A, a kettle on L1): the battery relieved at -3,105 W, and once the meter showed room Core ended the relief in one step while the car's order rose a step. L1 read 24.03 A against the 24 A working limit for more than 3 s: our own raise. Ending a discharge is our raise. The battery keeps the part of it that the measured room cannot take, less our raises the meter may not show yet (the battery's own for evSettle and the car's order above its lowest recent offer), never below its command bounds. What the car still wants does not hold the battery's discharge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1e7198464
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if last := latest[target.Driver]; last < 0 { | ||
| keep[i] = math.Max(0, math.Min(0, target.TargetW)-math.Max(last, lowest[target.Driver])) |
There was a problem hiding this comment.
Restore discharge only when a prior command actually exists
After startup, an idle battery with no command history can be commanded to discharge here: clampEVBatteryHeadroom substitutes the negative discharge cap for a missing command, and this loop treats that conservative reservation as discharge to preserve. For a 3×25 A site with an active EV, zero pending raises, a 5 kW battery discharge cap, measured export of 9 kW and a worst phase of 23 A, the new clamp changes a validated 0 W target to −4,310 W. An idle battery obeying that command raises export to 13,310 W, exceeding a configured 10 kW export ceiling; the export guard already ran earlier in applyDispatchSafetyPipeline. Keep the missing-history reservation for optional-charge budgeting, but require an actual prior discharge command before restoring negative power. This avoids issuing a clamp command without the quantified risk required by AGENTS.md.
AGENTS.md reference: AGENTS.md:L68-L68
Useful? React with 👍 / 👎.
Review of the relief fix: before Core's first battery order, after every start, the charge cap counts the battery as possibly discharging at its cap. keepEndingDischarge turned that pessimistic guess into a real discharge order: in the matrix battery rows the site exported -5.6 kW against a +6 kW plan for about 20 s, past MaxExportW. Only a discharge we ordered can now be kept; a battery with no order of ours keeps nothing. Plan sign-mismatch warnings in the matrix are back to master's 8, and the relief rows still pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…1918) * test(control): port #1816's battery relief reproductions to master Two reproductions from #1816, adapted to master's capBatteryCharge and clampEVBatteryHeadroom: - Pending rise: 25 A site, 1 A margin, phases 22.3/12.3/12.3 A. The battery measures -2000 W and our newer -1000 W order may not show yet. Ending the relief must keep -827 W so L1 lands on 24 A, not 25.2 A. - Shared relief: two batteries end -1000 W and -2000 W of relief. When the first cannot keep its share (SoC floor or a 300 W bound), the second keeps the missing 1827 W instead of the old 1218 W. Master's keepEndingDischarge (#1847) passes both. Dropping it, ignoring pending rises, or sharing before bounds makes them fail. Import only: master leaves the export direction to the fuse pipeline. Co-authored-by: segran2 <268038031+segran2@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(control): say which relief gaps master leaves open The header said master leaves the export case to the fuse pipeline. Nothing on master holds it. Name both no-car gaps instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: segran2 <268038031+segran2@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Cause
The field matrix's seven
own-raise reliefrows are all #1763's site: 3 × 25 A, a battery and a car capped at 8.3 kW. Each runs with Charge now or a pause, under every charger timing. They fail the same way. Traced on the easee120s pause row:capBatteryChargecounted an ending discharge against room only to cut positive charge. It never held back the discharge itself.Change
clampEVBatteryHeadroom/capBatteryCharge(go/internal/control/ev_battery_headroom.go):evSettle, as positive charge already counts them, and the car's order above its lowest recent offer.fuseTargetBounds). One at its SoC floor or without a reading keeps nothing.Deleted: the seven
own-raise reliefrows and the unusedrelieflabel intestdata/sitesim_field_known.txt. No code was deleted.Tests
TestEVBatteryEndingReliefKeepsWhatThePhaseCannotTake: L1 19.53 A, relief −3,105 W, the car 1 A upTestSiteSimRandomHouse(5 seeds)TestSiteSimScenariosOne existing test changed timing:
TestFuseOverageGetsBatteryReliefUntilEVCutShows. On master the battery let go of all its relief within 3 ticks after the car's cut showed.evSettle(20 s), because the first part still counts as on its way. It is idle 26 s after the step instead of about 8 s.go vetpasses, and so doesgo test -p 2 ./internal/control/ ./internal/loadpoint/ ./cmd/ftw/. I have not runmake verify.Independent review (Sonnet) and the fix it led to
restartrows went to −10 kW. It also ignored MaxExportW. The matrix stayed green because export is not one of its invariants. Now only a discharge we ordered can be kept.TestEVBatteryWithNoOrderOfOursKeepsNoDischargegives −2,723 W on c1e7198 and no discharge now. Plan sign-mismatch warnings in the matrix are back to master's 8.riseWis counted in the release room.clampEVBatteryHeadroomreturns early. With a slow charger still drawing, a battery charge raise is then unchecked. In a sweep with the car at 10.35–11.04 kW, the pause rows still fail own-raise on cloud chargers, on master and here.Not in this PR
clampEVBatteryHeadroomreturns early then, as on master.Hardware
Not run on real hardware. Evidence is still needed: a site where the battery relieves a phase while the car charges.
🤖 Generated with Claude Code