Repository navigation
refactor(drivercontrol): move operator holds out of the API - #1997
Conversation
frahlg
left a comment
There was a problem hiding this comment.
Ready to merge in content; it needs one rebase first. #1995 is merged (squashed as 1e525ac), and this branch still carries #1995's earlier commits, so it now conflicts with master in five files (api/api_driver_control.go, api/api_driver_thermal_test.go, api/api_drivers_debug.go, drivers/catalog_thermal.go, thermal/model.go). Please rebase onto master, dropping #1995's commits, and I will merge it.
Reviewed and tested: behaviour-neutral. Compared line by line with the old api_driver_control.go: same lock order, generation and identity checks, non-blocking SendDefault from the tick, 10 s deadlines, routes, 24 h cap, 4 h default and hold JSON. The existing hold-race tests pass unchanged apart from the call target, and the full make verify passes with the stack on today's master. Removing DecideIntent and the rest of the unused thermal code follows decision 3.
Low notes for the next step:
- The test seams are part of the production API (
beforeStateLock,beforeDefaultStateLock, exportedState.Lock/Unlock). A future planned-value caller could hold the per-driver lock through them; anexport_test.gowould keep them test-only. Holds.State(name)creates an entry for any name; keep it unexported.Activetakes the per-driver lock. When #2013's dispatcher calls it from the control tick, make sure it never waits behind an operator send (asSendDefaultdoes with TryLock).
The per-driver lock, hold, expiry and default path move unchanged from internal/api into internal/drivercontrol, so a planned value can later go through the same lock and expiry as an operator's (ADR 0012). The API keeps its routes, responses and SendDriverDefault; the registry lifecycle hook now clears holds through the package. As asked on srcfl#1994, the unused thermal policy draft goes with it: DecideIntent, DecisionInput, Intent, TemperatureBand, MarginalPrice and the synthetic_price strategy. The declaration vocabulary stays. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: hannesb90 <[email protected]>
aef7ff1 to
b10ae8c
Compare
The low notes from the review of srcfl#1997, for the step that adds a planned-value caller: - The test seams were part of the production API: two hook parameters on Send and SendDefault, and exported State.Lock, State.Unlock, ArmLocked, Expire, Peek, Len and State.CurrentHold. A planned-value caller could have held the per-driver lock through them. They are now behind Holds.Seams, which panics outside a test binary. An export_test.go would not do: the API package's hold-race tests need them too. - Holds.State, which created an entry for any name, is reachable only through Seams. - Active takes the per-driver lock and so waits for a command in flight. TryActive is the same read for the control tick: it never waits, and says so when a command or a default holds the lock. The hold-race tests are unchanged apart from the call target. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: hannesb90 <[email protected]>
frahlg
left a comment
There was a problem hiding this comment.
Thanks for the rebase. At b10ae8c it is one commit and nothing from #1995 was lost: every line that leaves the API lands in drivercontrol, and the thermal removals follow decision 3. Lock order, generation and identity checks, TryLock in SendDefault, the 10 s deadlines, routes, caps and hold JSON are unchanged. Merged with today's master (#1996, #2009 and #2010 included), go build ./... and go vet are clean. go test passes for api, drivercontrol, thermal and cmd/ftw, and -race passes for the first three.
Notes for #2013, not blocking:
Activetakes the per-driver lock. Called from the control tick, it could wait up to 10 s behind an operator send, so use TryLock there asSendDefaultdoes.- The test seams (
State.Lock/Unlock,ArmLocked,Peekand the like) are still exported. Moving them toexport_test.gowould keep a future caller from taking the lock through them.
The low notes from the review of srcfl#1997, for the step that adds a planned-value caller: - The test seams were part of the production API: two hook parameters on Send and SendDefault, and exported State.Lock, State.Unlock, ArmLocked, Expire, Peek, Len and State.CurrentHold. A planned-value caller could have held the per-driver lock through them. They are now behind Holds.Seams, which panics outside a test binary. An export_test.go would not do: the API package's hold-race tests need them too. - Holds.State, which created an entry for any name, is reachable only through Seams. - Active takes the per-driver lock and so waits for a command in flight. TryActive is the same read for the control tick: it never waits, and says so when a command or a default holds the lock. The hold-race tests are unchanged apart from the call target. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: hannesb90 <[email protected]>
The low notes from the review of #1997, for the step that adds a planned-value caller: - The test seams were part of the production API: two hook parameters on Send and SendDefault, and exported State.Lock, State.Unlock, ArmLocked, Expire, Peek, Len and State.CurrentHold. A planned-value caller could have held the per-driver lock through them. They are now behind Holds.Seams, which panics outside a test binary. An export_test.go would not do: the API package's hold-race tests need them too. - Holds.State, which created an entry for any name, is reachable only through Seams. - Active takes the per-driver lock and so waits for a command in flight. TryActive is the same read for the control tick: it never waits, and says so when a command or a default holds the lock. The hold-race tests are unchanged apart from the call target. Signed-off-by: hannesb90 <[email protected]> Co-authored-by: hannesb90 <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
Problem and result
Step 2 of the proposal in #1994 (ADR 0012), toward #520. Stacked on #1995;
only the last commit is new here.
The operator hold (one bounded value per driver, sent and released under one
per-driver lock, handed back to the driver's own default when it ends) lived
inside
internal/api. A planned value will need the same lock and the sameexpiry, or an operator hold and a planned one would each expire into a default
that undoes the other. This moves that code, unchanged, into
internal/drivercontrol, and does nothing else with it yet.drivercontrol.Holdsowns the per-driver state,Send,ArmLocked,Expire,SendDefault,Active,PeekandClear. The bodies are theformer
Servermethods, with the server's registry passed in as a smallinterface.
Server.SendDriverDefault(used by the watchdog incmd/ftw). The registrylifecycle hook now calls
Holds.Clear.before.
Sendtakes adonecallback for that reason, so the status readthat explains a 404 or 409 cannot race a lifecycle change.
is removed:
DecideIntent,DecisionInput,Intent,IntentKind,TemperatureBand,MarginalPriceand thesynthetic_pricestrategy.Nothing outside the package used them. The declaration vocabulary that feat(drivers): let a control declare what it does to heat #1995
uses (
AssetKind,InfluenceStrategy,ValidAssetKind) stays.Scope and safety
No behaviour change is intended, and none is visible to a user.
hold, the non-blocking default from the control tick, and the 10-second
deadlines are all as they were.
request, a failed default on expiry, replaced timers) run unchanged apart
from calling the package instead of
Serverinternals.drivercontrolcover the package with a fake registry.api.go(feat(history): add calendar month selection #1866, fix(control): fuse protection as one function #1789, feat(history): show EV charging energy and cost for 7 and 30 days #1546) change other hunks; nooverlap. feat(drivers): let a control declare what it does to heat #1995 and feat(thermaltwin): learn each declared room's thermal twin in shadow #1996 are this series.
Verification
Run on a Raspberry Pi 4 (linux/arm64), Go 1.26.10:
With the Pi's default umask 002, seven
cmd/ftwnova key tests fail becausethe temporary key directory is group-writable. That is the environment, and
the same on
master. The race detector does not run on this Pi's 39-bit VMA;CI covers it.
Checklist
🤖 Generated with Claude Code