Skip to content

fix(mpc): reject ambiguous EV deadlines - #902

Merged
frahlg merged 1 commit into
masterfrom
agent/ev-target-deadline
Aug 11, 2026
Merged

frahlg merged 1 commit into
masterfrom
agent/ev-target-deadline

Conversation

@frahlg

@frahlg frahlg commented Aug 11, 2026

Copy link
Copy Markdown
Member

What changed

  • Reject an active EV SoC target when its deadline slot is negative.
  • Document that slot 0 is the first real deadline and that only a zero target disables the deadline.
  • Cover zero-target, first-slot, past-horizon, invalid-slot and fail-closed service cases.

Why

Core sent the same invalid input to two planners with different results. With TargetSoCPct=40 and TargetSlotIdx=-1, Go-DP treated the target as having no deadline and planned 0 W in slot 0. Python/HiGHS clamped -1 to slot 0 and planned 2500 W.

The service physics gate now rejects that input before either planner runs. It keeps the last accepted plan and does not allocate a new decision ID or diagnostic.

Compatibility stays explicit:

  • TargetSoCPct == 0: no target; the slot value is ignored.
  • TargetSlotIdx == 0: target due at the end of the first slot.
  • A deadline past the horizon remains valid; both planners clamp it to the last slot.

This advances #885. It does not touch external_optimizer.go, which is owned by open stacked work.

Validation

  • Exact old-base tests fail for the expected reasons: the invalid target reaches the solver and replaces the prior plan.
  • Focused tests passed 100 times.
  • Focused race tests passed 25 times.
  • Full go test ./internal/mpc, full MPC race suite and go vet ./internal/mpc passed.
  • Four Python flex/deadline parity tests passed in independent review.
  • make verify-all passed, including 134 Python tests, all Go packages, Core to Optimizer contracts, full stack, Compose migration, vet/build, and Linux arm64/amd64 plus Windows amd64 cross-builds.
  • Two independent read-only reviews found no P0-P3 issues.
  • The final live overlap check covered all 22 open PRs and found no file or review-thread conflict.

@frahlg
frahlg merged commit e45cc62 into master Aug 11, 2026
14 checks passed

@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: a605222896

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

Comment on lines +367 to +368
if loadpoint.TargetSoCPct > 0 && loadpoint.TargetSlotIdx < 0 {
return fmt.Errorf("%s.target_slot_idx must be non-negative when target_soc_pct is set", field)

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 Do not reject deadlines that expire during probe construction

When a real deadline passes between the future-time gate in go/cmd/ftw/main.go:1236-1238 and the later time.Until calculation at main.go:1277-1282, the probe emits a positive target with TargetSlotIdx == -1. This new check then rejects the entire replan and retains the previous whole-site plan, even though the input was a normal deadline rather than malformed caller data. Use one captured timestamp throughout probe construction or omit the loadpoint when the deadline has elapsed before applying this validation.

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