feat: report an unproved schedule as Feasible rather than Optimal - #124
Merged
Conversation
The API documents `Optimal` as "Problem solved to optimality" and returns it for solves that were never proved. pulp sets LpStatusOptimal whenever CBC came back with any feasible solution, including one it stopped on at the time limit, so a schedule truncated by OPTIMIZER_TIME_LIMIT is presented to callers as the proved optimum. Measured on one captured request, a 2 s run and a 30 s run both reported Optimal, with objective values of -682466848 and 59714881. pulp does carry the distinction, in sol_status, and this folds it into the status the response already has rather than adding a field beside it. Callers branch on that field today, and the bug is that one of its values claims more than it can back. `Feasible` is a usable answer, not an error: the response carries the same complete schedule an Optimal one does, so the result payload is built for both and only the label differs. Clients that treat anything other than Optimal as a failure will start discarding roughly a percent of schedules they use today, so the consumer side wants updating before this ships. The test simulates the truncation instead of provoking it with a small time limit, because CBC's -sec is only tested between branch and bound nodes: every stored case proves itself at a limit of 0.01 s, and 020-weird-charging-at-night takes 0.98 s regardless. Both gotchas are now in AGENTS.md. client/client.gen.go regenerated from openapi.yaml with `make build`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
The API documents
Optimalas "Problem solved to optimality" and returns it for solves that were never proved.pulpsetsLpStatusOptimalwhenever CBC came back with any feasible solution, including one it stopped on at the time limit. So a schedule truncated byOPTIMIZER_TIME_LIMITreaches callers labelled as the proved optimum. Measured on one captured slow request, the same model at two budgets:OptimalOptimalSame model, same label, answers nowhere near each other. Around one percent of production requests hit the limit, so that is roughly one percent of responses currently overclaiming.
What this does
pulpdoes carry the distinction, insol_status, and this folds it into thestatusfield the response already has rather than adding a second field beside it. Callers branch on that field today, and the bug is that one of its values claims more than it can back:Feasibleis a usable answer, not an error. The response carries the same complete schedule anOptimalone does — same batteries, same grid series, same objective value — so the result payload is built for both and only the label differs.This is a contract change
Clients that treat anything other than
Optimalas a failure will start discarding roughly a percent of the schedules they use today, falling back to whatever plan they held. Nothing in this repo branches on the value, but the downstream consumer does, so the evcc side wants updating before this ships. If that ordering is awkward, the alternative is a separate boolean field and leavingstatusalone — say the word and I will switch it, though it leaves the documented meaning ofOptimalwrong.client/client.gen.gois regenerated fromopenapi.yamlwithmake build; the new value lands in theOptimizationResultStatusenum, so Go consumers get a compile-time constant rather than a bare string.On the test
It simulates the truncation instead of provoking it with a small time limit, because CBC's
-secis not a wall clock on the request — it is only tested between branch and bound nodes, so a model that finishes in presolve or the root relaxation ignores it entirely. Every stored case still proves itself at a limit of 0.01 s, and020-weird-charging-at-nighttakes 0.98 s regardless:So the test patches the solve to return what CBC returns on a real timeout, and asserts both the label and that the full payload survives it. Both gotchas are now recorded in AGENTS.md, since reading
problem.statusas "did it finish" is an easy trap to fall into twice.Independent of #115 and #123 — the API tells this same story on
maintoday.