Repository navigation
fix(api): cap history and series points at 2000 - #2055
Merged
Merged
Conversation
GET /api/history and GET /api/series took any points value. A huge one reached the store, which refused it, so the caller got a 500; values up to the store's 10000-bucket limit built replies five times the size of the energy history's 2000-bucket budget. /api/series also read a negative or non-numeric value as 0, which returns every stored row, and /api/history quietly used 200. Both routes now share parseHistoryPoints: omitted keeps each route's default (200 rows for history, stored rows for series), a value above 2000 is clamped to 2000 so older clients still get an answer, and a value that is not a whole number, or is below 0, gets a 400. points=0 keeps its meaning on both routes. The agent route hints name the cap. For #1136. Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis 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. |
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.
For #1136. Fredrik asked for this in today's Core beta (21 November 2026).
Problem
GET /api/historyandGET /api/seriestook anypointsvalue:handleHistoryused anyn > 0and quietly fell back to 200 for anything else, includingabcand-5.handleSeriesused any value that parsed, negatives included, and readabcas 0. A negative or 0 means "every stored row".Since the issue was filed, the store has gained its own guards (
maxSeriesBuckets= 10000 andmaxRawSeriesPoints= 200000 ingo/internal/state/series_archive.go). So memory is bounded, but:?points=1000000000reaches the store, which refuses it, and the caller gets a 500./api/energy/historyuses (energyHistoryMaxBuckets)./api/historyis a public read; it is not inprotectedReadPath.pointson/api/seriesturns a bucketed read into a full stored-rows read.Change
Clamp, not refuse, for large values. A whole number above 2000 is cut to 2000, so an older client or agent that asks for more still gets an answer, at a coarser step. No client in Core's web UI asks for more than 800 today (dashboard 360 and 288, heating 120–800, car SoC 180). The native apps do not call these routes.
Refuse values that are not numbers. A value that is not a whole number, is below 0, or overflows
intnow gets a 400 (points must be a whole number, 0 or more), as the issue asks and assinceis handled.Defaults are unchanged:
/api/history: omitted orpoints=0→ 200 rows, the dashboard default./api/series: omitted orpoints=0→ stored rows. The store's 200000-row guard still applies, as before.Files:
go/internal/api/api.go: newhistoryMaxPoints(=energyHistoryMaxBuckets, 2000) andparseHistoryPoints, used byhandleHistoryandhandleSeries. The doc comments name the cap.go/internal/api/api_agent_catalog.go: the agent route hints say "up to 2000" forpointson both routes.go/internal/api/api_history_points_test.go(new)..changeset/history-points-cap.md:"ftw": patch.Scope and safety
This changes the API handlers only. The store and
store_ts.gostay as they are (#1129, which the issue mentions, has merged). A 400 replaces what was a silent fallback, but only for values no Core client sends.Overlap: open PRs #2041, #2016 and #1789 also edit
go/internal/api/api.go, in other hunks (imports,Deps,New, route table,handleSetPeakLimit). #2041 also editsapi_agent_catalog.gonear line 28; this change is at lines 37, 43 and 112. Neither toucheshandleHistoryorhandleSeries.Not in scope:
/api/seriestakes a comma-separatedmetriclist, and each metric is read with its ownpointsbudget, so a long or repeated list multiplies the reply./api/seriesis a protected read (protectedReadPath). A cap on the list would be a separate change.Evidence
New tests in
go/internal/api/api_history_points_test.go. Each stores 3000 history rows and 3000meter_wsamples one second apart:TestHistoryAndSeriesClampLargePoints:points=5000andpoints=1000000000give 200 with 1..2000 rows on both routes.TestHistoryAndSeriesRefuseBadPoints:-1,-5000,abc,1.5and99999999999999999999give 400 on both routes.TestHistoryPointsZeroAndOmittedKeepDashboardDefault: history withpointsomitted or 0 gives at most 200 rows;points=360gives more than 200 and at most 360.TestSeriesPointsZeroAndOmittedReturnStoredRows: series withpointsomitted or 0 gives all 3000 stored rows.Results:
api.go, with a one-line test shim for the constant): the clamp test fails (points=5000: 3000 rows, want 1..2000;points=1000000000: status 500) and the refuse test fails (all ten cases give 200). The two default tests pass; they hold existing behaviour.go test ./internal/api/ -count=1: ok (61 s).make verify, first run: failed only ininternal/ocppTestLaterRunsAfterTheSlotIsFree, the known flake Flaky test: ocpp TestLaterRunsAfterTheSlotIsFree under -race #1943. This PR does not touchinternal/ocpp, and that test passed 20 of 20 runs alone.make verify, second run:verify: vet + test + build clean.Checklist
🤖 Generated with Claude Code