Repository navigation
fix(control): stop the dispatch holdoff from skipping every other tick - #1877
Merged
Merged
Conversation
The holdoff compared elapsed time with `< min_dispatch_interval_s` on a fixed 2 s ticker. Work before each dispatch varies, so elapsed often lands just under 2 s and the battery got a command only every 4 s. Skip the holdoff when it is not longer than the control interval, and otherwise allow 0.25 s of jitter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis 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.
Item A2 of the stable plan.
Problem
The holdoff in
ComputeDispatchskips a dispatch when less thanmin_dispatch_interval_shas passed since the last one. Both that setting andcontrol_interval_sdefault to 2 s, and the ticker in main.go is fixed at 2 s. But each tick does a varying amount of work before it callsComputeDispatch(SQL writes, charger commands), andLastDispatchis stamped near the end of the previous call. So elapsed time often lands just under 2 s, for example 1.98 s. That tick takes the holdoff exit, sends no battery command, and the next tick sees about 4 s. The battery gets a command about every 4 s instead of every 2 s. The audit repro (caa-39) skipped 5 of 10 ticks with constant work and 5 of 10 with jitter.Tests missed it because most control tests set
MinDispatchIntervalS = 0, and the sim harness steps exactly 2.000 s.Change
State.ControlIntervalScarriessite.control_interval_s. It is set at boot and on config reload.MinDispatchIntervalS <= ControlIntervalS.elapsed < min - 0.25).Tests
go/internal/control/holdoff_cadence_test.goholds the caa-39 repro tests, plus two new cases: large jitter (up to 1 s) with min == control interval skips no tick, and a 5 s holdoff on 2 s ticks still holds 6 of 10 ticks.go test -race ./internal/control/... ./internal/configreload/... ./internal/config/... ./cmd/ftw/...: ok.go vet ./...andgo build ./...: ok.Risk
Low. The battery now gets a command on every 2 s tick at default settings, which is what the defaults were meant to do. The slew limit is per dispatch, so the ramp per second can be up to twice as fast as before, when half the ticks were skipped. Fuse protection is unchanged; it ran on every tick before too. Sites with a holdoff longer than the tick keep it, less 0.25 s.
🤖 Generated with Claude Code