Skip to content

Restore the soc-min default of 0 for storage - #2884

Merged
Flix6x merged 9 commits into
mainfrom
fix/soc-min-default-zero
Dec 2, 2026
Merged

Flix6x merged 9 commits into
mainfrom
fix/soc-min-default-zero

Conversation

@Flix6x

@Flix6x Flix6x commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Description

Until v1.0.0, a storage flex-model without soc-min got a lower bound of 0 ("can't drain the storage by more than it contains").
#2221 removed ensure_soc_min_max() to make soc-max optional, and the soc-min default went with it.
Since then, a battery scheduled without soc-min has no lower bound and can be scheduled into a negative state of charge.

A community user hit this with the toy battery: flexmeasures add toy-account gives it soc-max: 450 kWh but no soc-min, so a schedule request without soc-min discharged at the full 500 kW for the whole window.

  • Default soc-min to 0 for any stock whose state of charge is known, in both single- and multi-device flex-models.
    The default lives in the new default_soc_min() in the scheduler, so add_storage_constraints() stays unit-neutral and Fix: soc min does not need to be mandatory #2221's tests of it still hold.
  • Add "soc-min": "0 kWh" to the toy battery's flex-model, so the tutorial doesn't depend on the default.
  • Update the soc-min field description (and so the OpenAPI spec).

soc-max stays optional.

Why a function, and not a schema default

#2847 plans to allow arbitrary fill-level units, such as degrees Celsius for a freezer.
0 is a physical floor for energy and percentage stocks, but not for temperatures, so default_soc_min() is where that issue can return None for non-energy units.
For now all stocks are converted to MWh, so it always returns 0.

How to test

pytest flexmeasures/data/models/planning/tests/test_solver.py -k defaults_soc_min_to_zero

The new test schedules day 2 (8 expensive hours first) with no soc-min in either the request or the asset's flex-model, and checks the state of charge bottoms out at 0.
It fails on main: the state of charge goes negative.
The planning, schema, CLI and schedule-API suites pass locally (1147 passed, 4 xfailed).

Further notes

  • The pre-commit hook also bumped the OpenAPI spec's version from 1.1.0 to 1.1.1 (its next-version guess from git describe, which gives v1.1.0-20). Drop that line if 1.2.0 is preferred.
  • Changelog entries (main and API) are in a separate commit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc

Flix6x and others added 3 commits November 19, 2026 12:33
Since #2221 (v1.0.0), a storage flex-model without soc-min had no lower bound, so a battery could be scheduled into a negative state of charge.
The default now lives in default_soc_min(), which issue #2847 can make unit-aware: 0 is a physical floor for energy stocks, but not for fill levels in, say, degrees Celsius.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc
Signed-off-by: F.N. Claessen <claessen@seita.nl>
The toy account's battery set soc-max but no soc-min, so scheduling it without a soc-min in the request let it discharge into a negative state of charge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x
Flix6x requested a review from nhoening November 19, 2026 11:38
@Flix6x Flix6x self-assigned this Nov 19, 2026
@Flix6x Flix6x added bug Something isn't working Scheduling CLI labels Nov 19, 2026
@Flix6x Flix6x added this to the 1.0.3 milestone Nov 19, 2026
The fix is to be backported to the 1.0.x branch, so list it under the oldest release that will ship it, as was done for v1.0.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x Flix6x modified the milestones: 1.0.3, 1.0.4 Nov 23, 2026

@Flix6x Flix6x left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A self-review of #2884, at its head 34adcfe and merged into today's main (4bdcf55; a local trial merge, where only the API changelog conflicts).

The fix holds on main: the test battery, scheduled from 2.5 MWh with soc-max 4.5 MWh and no soc-min anywhere, goes down to −45.5 MWh on main, and stops at 0 with #2884. An explicit soc-min (0.5 MWh) is unchanged. The new test fails on main and passes with #2884 merged; the planning tests, the scheduling schema, the schedule API and the toy-account CLI tests pass there too (821 passed, 3 xfailed).

For the changelog: flex-models without a soc-min now behave like an explicit soc-min: 0 again. That includes a soc-usage beyond what the stock holds: it used to run into a negative state of charge, and is now left out at the soc-delta-breach-price (as #2920 already does for an explicit soc-min; 2.3 MWh of 4.8 MWh in the probe), or, with relax-soc-constraints off, makes the schedule infeasible, as before v1.0.0.

Before merging, we'll push these to the branch ourselves:

  1. The conflict in documentation/api/change_log.rst: the entry is under v3.0-35 (released November 11); it moves to v3.0-38.
  2. The changelog entry opens a new "v1.0.3 | November xx" section, but v1.0.3 was released on November 23 without this fix (it would merge silently as a second v1.0.3 section). It moves to v1.0.4, the milestone, with the line on the soc-usage behaviour above.
  3. The OpenAPI version bump to 1.1.1 is moot now: main already has it, so we take main's side.
  4. The soc-min description (SOC_MIN in flexmeasures/data/schemas/scheduling/metadata.py, and the OpenAPI spec) will say the default applies to energy units only, so it doesn't over-promise once non-energy SoC units arrive (#2847): "If omitted, it defaults to 0 for storage whose state of charge is known and measured in energy units (kWh, MWh), since an energy stock cannot hold less than nothing."

For the backport: the code changes apply cleanly to 1.0.x and 1.1.x; only the changelogs and the OpenAPI spec conflict there. 1.1.x has #2920; 1.0.x doesn't, so on 1.0.4 such a soc-usage makes the schedule fail as infeasible rather than run into a negative state of charge. That is the pre-v1.0.0 behaviour, and the right one physically, but worth a line in the 1.0.4 changelog.

Flix6x and others added 4 commits December 1, 2026 20:39
…ero-followups

# Conflicts:
#	documentation/api/change_log.rst
…tion to v1.0.4

v1.0.3 was released on November 23 without this fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… beyond the stock

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
So the description does not over-promise once a state of charge may come in other units (#2847).
The OpenAPI spec is regenerated, keeping its version at 1.1.1, as on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Flix6x

Flix6x commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

As announced in the review, we pushed the follow-ups to this branch (merged with main first):

  1. API changelog: the entry moved from v3.0-35 (released) to v3.0-38, which resolves the conflict with main: f28cfa2 (the merge of main).
  2. Main changelog: the entry moved from the new, duplicate "v1.0.3 | November xx" section to a new "v1.0.4 | December xx, 2026" section (Bugfixes): 39cc028.
  3. The entry now says what happens to a soc-usage beyond what the stock holds (left out at the soc-delta-breach-price, or infeasible with relax-soc-constraints off): f1f14d3.
  4. OpenAPI version: took main's side (1.1.1) in the merge, no further bump: f28cfa2.
  5. soc-min description: the default of 0 now applies to state of charge in energy units only (OpenAPI spec regenerated), with a test that checks both: ecb6c09.

Left for the 1.0.x backport (it does not exist yet): its v1.0.4 entry should keep only the infeasible half of item 3, since 1.0.x has no #2920 (soc-delta-breach-price).

Planning tests and test_scheduling.py pass (724 passed, 3 xfailed), on an isolated database.
The DCO check fails: our four commits lack a Signed-off-by line. Adding it would rewrite pushed history, so a maintainer can set the DCO check to pass on its details page instead.

… of charge once

Signed-off-by: F.N. Claessen <claessen@seita.nl>

@Flix6x Flix6x left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at ecb6c09 after the follow-ups: tests pass and main merges in cleanly. Admin-merging once CI is green on one more commit that tightens the changelog bullet; backports to 1.1.x and 1.0.x follow.

@Flix6x
Flix6x merged commit 2429a0d into main Dec 2, 2026
10 of 11 checks passed
@Flix6x
Flix6x deleted the fix/soc-min-default-zero branch December 2, 2026 14:16
@Flix6x

Flix6x commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Follow-ups of the re-check, done after the review:

Flix6x added a commit that referenced this pull request Dec 2, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Flix6x added a commit that referenced this pull request Dec 2, 2026
* Restore the soc-min default of 0 for storage (#2884)

* fix: default soc-min to 0 for storage whose state of charge is known

Since #2221 (v1.0.0), a storage flex-model without soc-min had no lower bound, so a battery could be scheduled into a negative state of charge.
The default now lives in default_soc_min(), which issue #2847 can make unit-aware: 0 is a physical floor for energy stocks, but not for fill levels in, say, degrees Celsius.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc
Signed-off-by: F.N. Claessen <claessen@seita.nl>

* fix: give the toy battery a soc-min of 0 kWh

The toy account's battery set soc-max but no soc-min, so scheduling it without a soc-min in the request let it discharge into a negative state of charge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc
Signed-off-by: F.N. Claessen <claessen@seita.nl>

* docs: changelog entries for PR #2884

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc
Signed-off-by: F.N. Claessen <claessen@seita.nl>

* docs: move the PR #2884 changelog entry to a new v1.0.3 section

The fix is to be backported to the 1.0.x branch, so list it under the oldest release that will ship it, as was done for v1.0.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc
Signed-off-by: F.N. Claessen <claessen@seita.nl>

* docs: move the PR #2884 changelog entry from an unreleased v1.0.3 section to v1.0.4

v1.0.3 was released on November 23 without this fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say in the PR #2884 changelog entry what happens to a soc-usage beyond the stock

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say the soc-min default of 0 applies to energy units only

So the description does not over-promise once a state of charge may come in other units (#2847).
The OpenAPI spec is regenerated, keeping its version at 1.1.1, as on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say the PR #2884 changelog entry's point about a negative state of charge once

Signed-off-by: F.N. Claessen <claessen@seita.nl>

---------

Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2429a0d)
Signed-off-by: F.N. Claessen <claessen@seita.nl>

* docs: say "as before v1.0.0" once in the PR #2884 changelog entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>

---------

Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Flix6x added a commit that referenced this pull request Dec 3, 2026
…ach-price, v1.1.4 does (#2954)

The v1.0.4 entry now reads as on the 1.0.x branch (#2952), where a soc-usage beyond the stock makes the schedule infeasible. The main wording moves to a new v1.1.4 section, for the 1.1.x backport (#2951), which has #2920.

Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Flix6x added a commit that referenced this pull request Dec 3, 2026
* fix: default soc-min to 0 for storage whose state of charge is known

Since #2221 (v1.0.0), a storage flex-model without soc-min had no lower bound, so a battery could be scheduled into a negative state of charge.
The default now lives in default_soc_min(), which issue #2847 can make unit-aware: 0 is a physical floor for energy stocks, but not for fill levels in, say, degrees Celsius.


Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc


* fix: give the toy battery a soc-min of 0 kWh

The toy account's battery set soc-max but no soc-min, so scheduling it without a soc-min in the request let it discharge into a negative state of charge.


Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc


* docs: changelog entries for PR #2884


Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc


* docs: move the PR #2884 changelog entry to a new v1.0.3 section

The fix is to be backported to the 1.0.x branch, so list it under the oldest release that will ship it, as was done for v1.0.2.


Claude-Session: https://claude.ai/code/session_01DWv6v4StnVB9FyGWKK2tMc


* docs: move the PR #2884 changelog entry from an unreleased v1.0.3 section to v1.0.4

v1.0.3 was released on November 23 without this fix.



* docs: say in the PR #2884 changelog entry what happens to a soc-usage beyond the stock



* docs: say the soc-min default of 0 applies to energy units only

So the description does not over-promise once a state of charge may come in other units (#2847).
The OpenAPI spec is regenerated, keeping its version at 1.1.1, as on main.



* docs: say the PR #2884 changelog entry's point about a negative state of charge once



---------



(cherry picked from commit 2429a0d)

Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working CLI Scheduling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant