Repository navigation
fix(mpc): fit each worker call's time limit to its own deadline - #1968
Merged
Merged
Conversation
Core fixed time_limit_s from the budget at the frozen execution start. With forecast caution, the caution call follows the point call and its deadline counts from the time left in the slot now. After a point call that used its whole limit, the caution call could ask for 1.5 s with about 950 ms left before its deadline, so a worker that uses its full time limit answered after Core had given up, and Core published the point plan. Each call's time_limit_s now fits the time before that call's deadline, minus Core's reply margin, after request preparation. A call with its full budget left keeps it. Below Core's no-call threshold the worker is not started. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fredrik Ahlgren <[email protected]>
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. |
6 tasks done
frahlg
added a commit
that referenced
this pull request
Nov 6, 2026
Bundle the worker from srcfl/energyplan 847936a (0.7.0, tag v0.7.0-beta.1) for linux-arm64 and linux-amd64. The macOS worker is no longer bundled; #1977 lets verify.py check such a bundle and skip execution on a Mac. The worker lists demand_elapsed_hours, so Core (#1966) sends it the demand hour in progress and the day's completed peak in that day's group, and the native demand test now requires the feature. The contract describes the feature and the demand-charge fields, each call's time limit since #1968, the batteries' total recovery rule and optional reply diagnostics, and it stays identical to Energyplan's copy. The worker version pins and the README follow. Licenses and forecast schemas are unchanged; the notices list two more microlp modifications. Protocol v1 is unchanged. Signed-off-by: Fredrik Ahlgren <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When Core plans with forecast caution late in a slot, it makes a point call
and then a caution call to the worker. Both requests take
time_limit_sfromenergyplanBudget, which counts from the frozen execution start: for example1.5 s with an active car. The caution call's own deadline comes from the time
left now (
planWithForecastMargin: slot end minus the 50 ms publish margin).After a point call that used its whole limit, the caution call can have about
950 ms before its deadline and still ask for 1.5 s. A worker that uses its full
time limit then answers after Core has given up on the call, so the call times
out and Core publishes the point plan instead of the caution plan. Under
optimizer protocol v1 a worker cannot learn Core's deadline, so Core has to
cap the limit.
Change
energyplanSolveTime(toDeadline)moves the existing reply margin(max(5 %, 30 ms)) and the existing no-call threshold (500 ms left in the
slot, which is 450 ms before a call deadline) out of
energyplanBudget.energyplanBudgetreturns the same values as before.ExternalOptimizer.Optimizecapstime_limit_sfor a worker whose timeCore budgets. The cap runs after request preparation, so it also covers the
handshake and any budget reset there, and limits
time_limit_stoenergyplanSolveTime(time until the call's deadline). A call that still hasits full budget keeps it unchanged. If less than the no-call threshold is
left, Core does not start the worker and fails the call fast, as the
frozen-start check already does. Core never sends a non-positive limit.
Overlap: #1966 also changes
external_optimizer.go(buildRequest) andresets
time_limit_sinprepareEnergyplanRequest. The two branches mergewithout conflicts, and because this cap runs after preparation it also bounds
that reset.
Tests
TestEnergyplanLateCautionCallLimitFitsItsDeadline: point call, then a latecaution call through
planWithForecastMargin. The point call keeps 1.5 s.The caution call must be ≤ remaining − margin. On master it fails with
caution time_limit_s=1.5, want in (0, 0.9025]: the call has 950ms before its deadline.TestEnergyplanLateCallLimitFollowsNoCallThreshold: with 300 ms left theworker is not started. With 600 ms left the limit is positive and fits the
deadline. Both cases fail on master.
TestEnergyplanCallWithTimeLeftKeepsItsBudget: with no deadline, a frozenstart near the slot end, or a 2 s caller deadline, the call keeps exactly
the unchanged budget.
TestEnergyplanCapsWorkerBudgetAndWaitToRemainingnow checks a rangeinstead of exact equality. Its call loses a few microseconds between setting
the deadline and sending, so the limit is now between the solve time left at
sending and the frozen budget.
go test ./internal/mpc/... ./cmd/ftw/...:ok internal/mpc,ok cmd/ftw,no failures.
go vet ./internal/mpc/...is clean. The new tests also passwith
-race -count=5.🤖 Generated with Claude Code