Repository navigation
Optimizer: hourly slots beyond 48h also for a self-hosted optimizer - #34833
Merged
Merged
Conversation
Coarsen the horizon for every optimizer, not only the hosted one. A self-hosted optimizer can move the boundary with OPTIMIZER_COARSEN_AFTER (a Go duration, 0 keeps quarter hour slots for the full horizon).
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="core/site_optimizer.go" line_range="1388" />
<code_context>
+// coarseSlotsAfter returns where the request switches to clock hour slots. A self-hosted optimizer
+// may move it with OPTIMIZER_COARSEN_AFTER, 0 keeps quarter hour slots for the full horizon.
+func coarseSlotsAfter(hosted bool) (time.Duration, error) {
+ v := os.Getenv("OPTIMIZER_COARSEN_AFTER")
+ if hosted || v == "" {
+ return defaultCoarseSlotsAfter, nil
</code_context>
<issue_to_address>
**Self-hosted users cannot discover override**
When a self-hosted user relies on the optimizer documentation to configure options, the optimizer documentation omits `OPTIMIZER_COARSEN_AFTER`, so users cannot learn how to set it to `0` to preserve quarter-hour slots or move the boundary, and requests retain hourly slots beyond 48 hours unintentionally.
Document `OPTIMIZER_COARSEN_AFTER`, including that `0` preserves quarter-hour slots for the full horizon and how to move the boundary.
</issue_to_address>
### Comment 2
<location path="core/site_optimizer_test.go" line_range="238-239" />
<code_context>
after := before
- coarsenHorizon(&short, &after)
+ coarsenHorizon(&short, &after, defaultCoarseSlotsAfter)
assert.Equal(t, 4*47, len(short.TimeSeries.Dt))
assert.Equal(t, before, after)
+
+ // an earlier boundary coarsens the same request
</code_context>
<issue_to_address>
**Short-horizon mutations go undetected**
When the coarsener changes slot durations in place without changing the slot count, when the coarsener changes `short.TimeSeries.Dt` values without changing its length, `TestCoarsenHorizon` line 238 still passes and line 239 never compares `Dt`; the test passes despite a short-horizon mutation.
Snapshot and compare `short.TimeSeries.Dt` before and after coarsening.
</issue_to_address>| // coarseSlotsAfter returns where the request switches to clock hour slots. A self-hosted optimizer | ||
| // may move it with OPTIMIZER_COARSEN_AFTER, 0 keeps quarter hour slots for the full horizon. | ||
| func coarseSlotsAfter(hosted bool) (time.Duration, error) { | ||
| v := os.Getenv("OPTIMIZER_COARSEN_AFTER") |
Contributor
There was a problem hiding this comment.
🟡 Medium · Self-hosted users cannot discover override
When a self-hosted user relies on the optimizer documentation to configure options, the optimizer documentation omits OPTIMIZER_COARSEN_AFTER, so users cannot learn how to set it to 0 to preserve quarter-hour slots or move the boundary, and requests retain hourly slots beyond 48 hours unintentionally.
Document OPTIMIZER_COARSEN_AFTER, including that 0 preserves quarter-hour slots for the full horizon and how to move the boundary.
Prompt for AI agents
In `core/site_optimizer.go` at line 1388:
**Self-hosted users cannot discover override**
When a self-hosted user relies on the optimizer documentation to configure options, the optimizer documentation omits `OPTIMIZER_COARSEN_AFTER`, so users cannot learn how to set it to `0` to preserve quarter-hour slots or move the boundary, and requests retain hourly slots beyond 48 hours unintentionally.
Document `OPTIMIZER_COARSEN_AFTER`, including that `0` preserves quarter-hour slots for the full horizon and how to move the boundary.
andig
reviewed
Oct 15, 2026
Co-Authored-By: Claude Opus 5.5 <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.
fixes #34820, follows #34738
As agreed in the issue, the horizon beyond 48h is now merged into clock hour slots for every optimizer, not only the hosted one. Local installs can opt out or move the boundary with an environment variable.
coarsenHorizonruns for hosted and self-hosted optimizers, default boundary 48hOPTIMIZER_COARSEN_AFTER(whole hours, e.g.72), only honoured by a self-hosted optimizer;0keeps quarter hour slots for the full horizonOPTIMIZER_COARSEN_AFTER=0TODO
OPTIMIZER_COARSEN_AFTERnext toOPTIMIZER_URIin the docs: Optimizer: document OPTIMIZER_COARSEN_AFTER docs#1221🤖 Generated with Claude Code