Repository navigation
refactor(drivercontrol): keep the hold test seams out of the API - #2021
Conversation
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. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: hannesb90 <[email protected]>
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a1bd51dba
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // lock: the hold is then changing, and the caller should treat the driver as | ||
| // held and look again on its next tick rather than send anything. | ||
| func (h *Holds) TryActive(name string) (hold *Hold, known bool) { | ||
| state, locked := h.tryLockExisting(name) |
There was a problem hiding this comment.
Make the map lookup nonblocking in TryActive
When one command holds a driver's state lock and a second Send for that driver enters lock, the second request holds h.mu while waiting for state.mu. TryActive then blocks in tryLockExisting at h.mu.Lock(), even when querying a different driver, rather than returning known=false. The new accessor therefore violates its non-waiting contract under overlapping requests; the added test only covers an uncontended map mutex. Use a nonblocking map-lock acquisition as well, returning an unknown result when it cannot be acquired.
Useful? React with 👍 / 👎.
frahlg
left a comment
There was a problem hiding this comment.
Reviewed. This is the drivercontrol commit from #2013, which a Sonnet agent reviewed at 6730139. Seams() checks testing.Testing() and panics outside a test binary, and nothing outside tests calls it. The API still calls Send and SendDefault, now without hook arguments, and their behaviour is unchanged. TryActive takes h.mu and then TryLock, which keeps the lock order. make verify is clean on 8a1bd51, and go test -race on drivercontrol and the API's hold tests passed.
Split out of #2013 so it can merge on its own. The commit is hannesb90's, unchanged. It answers the three low notes from the review of #1997.
Holds.Seams(). These are the hook arguments onSendandSendDefault,State.Lock/Unlock,ArmLocked,Expire,Peek,LenandState.Seams()panics outside a test binary (testing.Testing()). The API's hold-race tests still reach the seams, which anexport_test.gowould not allow.TryActivereads a hold without waiting, for the control tick. Nothing calls it yet.No behaviour change, so there is no changeset.
Evidence
make verifyon this branch: clean.go test -raceondrivercontroland the API's hold tests: clean. This ran during the review of feat(heatplan): propose a zone's heat from prices and the site's plan #2013.🤖 Generated with Claude Code