Persist commitment costs on scheduling job meta - #2418
Merged
Conversation
The cost breakdown was written to rq_job.meta after the job's last save_meta() call, and RQ persists a finishing job with include_meta=False, so the costs were computed and then silently lost from Redis — for every scheduling job, since the feature's introduction in #1946. Any consumer reading job meta (e.g. the jobs API) saw a scheduler_info without them. Save the meta right where the costs are recorded. The regression test fetches a fresh Job instance from Redis, so it asserts what was actually persisted rather than the worker's in-memory object; it was additionally mutation-tested (5/5 targeted mutants killed: fix reverted, save-before-set, wrong key, empty payload, branch inverted). No changelog entry: the feature this repairs is itself unreleased (v1.0.0). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UKx19DmqHiTBS7iEeFTijs Signed-off-by: F.N. Claessen <felix@seita.nl>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a bug where make_schedule computed and attached commitment_costs to the RQ job meta but never persisted it to Redis, meaning downstream consumers (e.g. jobs API) could not read commitment cost breakdowns from stored job meta.
Changes:
- Persist
commitment_costsimmediately viarq_job.save_meta()at the point they are written torq_job.meta["scheduler_info"] - Add a regression test that runs a real scheduling job and then re-fetches the
Jobfrom Redis to assert the persisted meta contains finite, non-empty commitment costs
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| flexmeasures/data/services/scheduling.py | Persist commitment_costs into Redis by saving job meta immediately after writing the field |
| flexmeasures/data/tests/test_scheduling_jobs.py | Add regression test verifying commitment_costs are present on a freshly fetched finished job |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UKx19DmqHiTBS7iEeFTijs Signed-off-by: F.N. Claessen <felix@seita.nl>
Documentation build overview
|
Flix6x
commented
Aug 8, 2026
…tery test Context: - Review: a whole new scheduling test is not needed just to assert these; the checks belong in an existing scheduling test Change: - Moved the assertions into test_scheduling_a_battery, which already runs the same job with the same fixtures, and dropped the separate test - Still fetches a fresh Job from Redis, so only what was actually persisted is asserted (verified to fail when the fix is reverted) Signed-off-by: F.N. Claessen <felix@seita.nl>
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 bug
make_schedulerecords the scheduler's commitment cost breakdown on the job:…but this runs after the function's last
rq_job.save_meta()call, and RQ persists a finishing job withinclude_meta=False. So the costs were computed and then silently dropped: no scheduling job has ever carriedcommitment_costsin the meta actually stored in Redis. The ordering has been wrong since the feature was introduced in #1946, so this never worked. Any consumer reading job meta (e.g. the jobs API) saw ascheduler_infowithout them.Observed live: after a successful
StorageSchedulerjob,Job.fetch(...)returnsscheduler_infocontaining only{"scheduler": ...}, while the in-memory job object in the worker (e.g. seen from an RQ success callback) still holds the full cost dict.The fix
Call
rq_job.save_meta()right where the costs are recorded, with a comment explaining why the explicit save is load-bearing.The test
The assertions live in
test_scheduling_a_battery, which already runs a real battery scheduling job with these fixtures. After the job finishes it fetches a freshJobinstance from Redis and asserts the persisted meta carries a non-empty, finite cost breakdown — deliberately not inspecting the worker's in-memory object, which held the data even when the bug was live.Mutation-tested (each mutant applied to
scheduling.py, test rerun):save_meta)save_meta()before the assignment{}Pristine fix: passes. Full
test_scheduling_jobs.pymodule: 14 passed.No changelog entry: the feature this repairs is itself part of unreleased v1.0.0 (#1946).
🤖 Generated with Claude Code
https://claude.ai/code/session_01UKx19DmqHiTBS7iEeFTijs