fix(mpc): score remaining slot time in rain-check and Energyplan budget - #1172
Conversation
The load rain-check still integrated the first price slot as LenMin after #1130 trimmed it to remaining time. Energyplan's worker budget was model-size only, so a late-in-slot fleet replan could spend 5s on a result that firstSlotExpired then discarded. Use DurationHours() for rain-check energy. Cap TimeLimitS and the process wait by remaining first-slot time minus a short publish margin, and fail fast when remaining time is below the small-model budget. Closes #1144 Closes #1148 Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.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. |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_3a768bcc-202a-40ca-baa1-03377283b658) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3ad316bb81
ℹ️ 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 len(slots) == 0 { | ||
| return 0 | ||
| } | ||
| rem := slots[0].StartMs + int64(slots[0].LenMin)*60000 - slots[0].ExecutionStart() |
There was a problem hiding this comment.
Base the solve deadline on the current wall clock
When input construction or a scheduler pause takes more than the 50 ms margin after trimFirstExecutionSlot captures ExecutionStartMs, this computes the original modeled duration rather than the time remaining when the worker actually starts. Consequently, both the fail-fast check and context.WithTimeout are stale by that delay, so a late fleet solve can run past the slot boundary, be discarded by firstSlotExpired, and trigger the retry this change is intended to avoid. Subtract the current time from the slot end at admission/deadline creation rather than subtracting the captured execution start.
Useful? React with 👍 / 👎.
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_14dbf8bc-5aa6-400b-992d-728384e50b33) |
#1130 plans only the remaining time in the current price slot. Two leftovers still used the full interval.
#1144 rain-check energy
forecastLoadWhmultipliedLoadWbyLenMin. AftertrimFirstExecutionSlot, first-slotLoadWis a remaining-interval average, so rain-check integrated it as a full 15 minutes.It now uses
DurationHours(), same asValidatePlan. Test: first slot 10 minutes in,LenMin=15— rain-check energy is 5 minutes of load, not 15.#1148 Energyplan wall-clock budget
energyplanTimeBudgetwas model-size only (500ms vs 5s). A late-in-slot fleet replan could burn the full 5s, getslot_elapsed, and retry.Cap
TimeLimitSand the process wait by remaining first-slot time minus a 50ms publish margin. If remaining time is below the small-model budget, fail fast instead of solving a result that cannot be published.Test: now = slot end − 200ms, fleet size that would get 5s — worker is not started, budget is 0, no
slot_elapsedretry.Scope
go/internal/mpc/load_bounds.go,energyplan.go,execution_time.go, testsmpc.go(fix(mpc): cost every challenger with Core's own model #1036) or DuckDB /prices.goCloses #1144
Closes #1148
Note
Medium Risk
Changes replan timing and load forecast scaling in MPC; wrong remaining-time math could skew rain-check lifts or skip/cut solves near slot boundaries.
Overview
Aligns two MPC paths with partial first-slot planning (#1130): load rain-check energy and Energyplan solve time now use remaining slot wall-clock, not the full interval.
Load rain-check:
forecastLoadWhintegratesLoadWwithDurationHours()(matchingValidatePlan) instead ofLenMin, so a trimmed first slot is not counted as a full 15 minutes when comparing/scaling the day’s forecast.Energyplan: Adds
remainingFirstSlotand refactorsenergyplanTimeBudgetto keep the existing 500ms / 5s model-size budget but cap it by remaining first-slot time minus a 50ms publish margin; returns 0 when less than the small budget remains.Optimizefails fast without starting the worker, and tightens the process context timeout to the same remaining window so late fleet replans do not burn a full 5s solve that would hitslot_elapsedand retry.Tests cover budget math, worker
TimeLimitS/deadline, fail-fast, rain-check Wh, and a late replan integration case that keeps the previous plan.Reviewed by Cursor Bugbot for commit 862e411. Bugbot is set up for automated code reviews on this repo. Configure here.