Skip to content

fix(control): stop the dispatch holdoff from skipping every other tick - #1877

Merged
frahlg merged 1 commit into
masterfrom
a2-holdoff-tolerance
Oct 27, 2026
Merged

frahlg merged 1 commit into
masterfrom
a2-holdoff-tolerance

Conversation

@frahlg

@frahlg frahlg commented Oct 27, 2026

Copy link
Copy Markdown
Member

Item A2 of the stable plan.

Problem

The holdoff in ComputeDispatch skips a dispatch when less than min_dispatch_interval_s has passed since the last one. Both that setting and control_interval_s default 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 calls ComputeDispatch (SQL writes, charger commands), and LastDispatch is 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.ControlIntervalS carries site.control_interval_s. It is set at boot and on config reload.
  • No holdoff when MinDispatchIntervalS <= ControlIntervalS.
  • A longer holdoff allows 0.25 s of jitter (elapsed < min - 0.25).
  • The comment at config.example.yaml:15 now says what the setting does.

Tests

  • go/internal/control/holdoff_cadence_test.go holds 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.
  • With dispatch.go from master, the first three fail (5 of 10 ticks skipped). With this change, all pass.
  • go test -race ./internal/control/... ./internal/configreload/... ./internal/config/... ./cmd/ftw/...: ok.
  • go vet ./... and go 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

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T13:04:21.619511Z 6d75616 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg merged commit edaf041 into master Oct 27, 2026
23 checks passed
@frahlg
frahlg deleted the a2-holdoff-tolerance branch November 11, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant