Repository navigation
fix(drivers): bound driver_init and apply fuse settings before reload - #1893
Merged
Merged
Conversation
driver_init ran with no deadline, and Reload strips the caller's cancellation, so a looping init blocked boot, Reload and every settings write. It now runs under a 30 s bound; a timeout is an init failure. Applying settings wrote the fuse, export limit, driver limits and the EV fuse clamp only after reg.Reload, which can take seconds per changed driver. configreload.Apply now writes the fuse and export limit under ctrlMu, and the applier pushes driver limits and SetSiteFuse before Reload. A driver leaving the config keeps its old limits until Reload stops it. Item B2 of the stable plan. 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 was referenced Oct 27, 2026
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 B2 of the stable plan.
Problem
driver_initruns with no deadline (lua.go,setLifecycleContext).Reload,RestartandRestartByNamedrop the caller's cancellation (replacementContext), and boot uses the process context. A driver whose init iswhile true do endblocks boot orReloadforever.Reloadruns inside the settings save, which holdsconfigWriteMu, so every later settings write blocks too.applyConfigChangecallsreg.Reloadfirst and writes the fuse,MaxExportW,DriverLimitsand the loadpointSetSiteFuseonly afterwards. One changed driver costs up to 5 s shutdown default + 5 s cleanup + init + 5 s startup default. During that time/api/configalready says 16 A while dispatch and the EV clamp still use 25 A. A hung init means the new fuse never reaches control.Change
driver_initruns undersetLuaCallContextwith a 30 s bound. A timeout is an init failure: the driver is not added, as with any other init error. A shorter caller deadline still wins.configreload.Applywrites the fuse (amps, voltage, phases, safety margin) andMaxExportWunderctrlMu, before the applier runs. The lines move out ofmain.go.DriverLimitsandlpController.SetSiteFusebeforereg.Reload. A driver that leaves the config keeps its old limits untilReloadhas stopped it, so it never runs without limits. AfterReloadthe map is set to exactly the new limits.Tests
go/internal/drivers/driver_init_deadline_test.go(from the audit repro, caa-107):TestLoopingDriverInitDoesNotBlockReloadandTestLoopingDriverInitFailsAddfail on master (blocked after 5 s) and pass here in 0.2 s.TestLoopingDriverInitHonoursCallerDeadlinepasses on both.go/internal/configreload/apply_fuse_order_test.go(caa-127):TestApplyFuseReachesControlBeforeRuntimeApplierfails on master (dispatch fuse at applier start = 25 A while committed config says 16 A) and passes here.go test -race -count=1 ./internal/drivers/... ./internal/configreload/... ./internal/api/... ./cmd/ftw/...: all ok.go vet ./...andgo build ./...: clean.The order inside
applyConfigChangehas no unit test, because it is a closure inmain.Risk
Low. A real driver whose init takes more than 30 s now fails to start instead of starting late. Bundled inits do a few Modbus reads (5 s timeout, fast backoff after a failed dial) or one HTTP call (15 s timeout), so they stay well under the bound. The myUplink token path calls the applier without
Apply, but it never changes the fuse.🤖 Generated with Claude Code