Skip to content

[codex] harden fuse safety guards - #342

Merged
frahlg merged 1 commit into
masterfrom
codex/bug-hunt-20260526-173825
May 27, 2026
Merged

frahlg merged 1 commit into
masterfrom
codex/bug-hunt-20260526-173825

Conversation

@frahlg

@frahlg frahlg commented May 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Reject invalid fuse.phases and fuse.voltage values during config validation.
  • Fix applyFuseGuard prediction to subtract only the batteries that are actually controlled in the current dispatch target set.
  • Route manual ModeCharge targets through the same fuse guard and reactive fuse-saver as normal dispatch paths.
  • Add regression coverage for stale/offline battery readings already included in the site meter, plus manual charge under high import.

Root cause

The fuse-guard prediction summed every battery reading in telemetry, including stale/offline batteries that were not receiving a replacement target. Because those stale readings are already reflected in the live grid meter, subtracting them again could under-predict fuse pressure and miss an overage.

A second audit finding showed ModeCharge returned chargeAll(...) directly before the safety post-processing path, so a manual fill command could push import past the configured fuse.

Validation

  • cd go && go test ./internal/control
  • make test

@frahlg
frahlg force-pushed the codex/bug-hunt-20260526-173825 branch from 2feb38c to 888ec20 Compare May 27, 2026 04:15
@frahlg
frahlg marked this pull request as ready for review May 27, 2026 04:15
@frahlg
frahlg merged commit 654675e into master May 27, 2026
1 check passed
@frahlg
frahlg deleted the codex/bug-hunt-20260526-173825 branch May 27, 2026 04:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 888ec204f1

ℹ️ 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".

targets = applyFuseGuard(targets, store, state, fuseMaxW)
targets = forceFuseDischarge(targets, store, state, driverCapacities, fuseMaxW)
now := time.Now()
state.LastDispatch = &now

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid holding off after manual charge

When an operator exits ModeCharge into a normal mode within MinDispatchIntervalS (default 5s), this new timestamp makes the holdoff branch run before the normal dispatch path, so ComputeDispatch returns only fuseSaverFromZero (usually nil) instead of issuing the new self-consumption target. Because drivers keep following the last charge command until a replacement is sent, leaving manual charge can continue charging for an extra tick; either skip updating LastDispatch here or have mode changes/manual overrides bypass/reset the holdoff.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant