Repository navigation
fix(drivers): retry a driver that fails to start - #1890
Conversation
A driver whose Add fails (a serial node not enumerated yet, a device still booting after a power cut) was logged once and forgotten, so a missing P1 meter blocked dispatch until a restart or a settings save. The registry now retries it after 10 s, doubling to 5 min, until it starts, leaves the config, is removed, or the registry shuts down. Running drivers are never torn down, and probes are not retried. 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 264abcf04c
ℹ️ 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".
| // Stop retrying a driver that failed to start and has left the config. | ||
| for _, n := range r.pendingSpawnRetries() { | ||
| if _, ok := findDriver(active, n); !ok { | ||
| release := r.acquireLifecycle(n) |
There was a problem hiding this comment.
Keep in-flight retries visible to config reloads
If a user removes or disables a driver while its retry is constructing capabilities or running driver_init, add has already deleted its retry entry through takeSpawnRetry, but has not yet inserted it into r.rec. Consequently, Reload sees the name in neither pendingSpawnRetries() nor oldCfgs, skips its lifecycle gate, and returns without canceling it. The retry can then register and poll the removed driver, or schedule further retries if initialization fails, despite the saved configuration disabling it. Keep the in-flight attempt discoverable until registration completes, so reload can serialize with it and enforce removal.
AGENTS.md reference: AGENTS.md:L20-L21
Useful? React with 👍 / 👎.
…nAll add() deletes the retry entry before the driver reaches r.rec, so while a retry ran its name was in neither list Reload checks. A driver the user removed or disabled could then start, or schedule yet another retry. ShutdownAll could also return while the retry was still starting a driver. The retry now marks its name in flight under r.mu for the length of add. Reload sees the mark, takes the name's gate and removes what the retry left. ShutdownAll waits on the gate of each in-flight name before it lists drivers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Item B3 of the stable plan.
Problem
The boot loop calls
reg.Addonce per driver and only logs a failure (cmd/ftw/main.go:796-805). A serial open fails insideaddbefore the driver is recorded (registry.go:631-636), and so does adriver_initerror. Nothing retries it. The site meter driver stays absent,liveSiteMeterreturns false, and dispatch stays blocked until someone saves settings, calls the restart API or restarts Core.Scenario: after a power cut, the box boots before the USB P1 reader shows up as
/dev/ttyUSB0.Addfails withserial capability: open .../ttyUSB0: no such file or directory. The node appears a moment later, but on master the meter is still missing 15 s later, and stays missing.Change
The registry keeps a list of drivers whose
Addfailed and retries each one after 10 s, doubling the wait up to 5 min. This is the narrow follow-up that #1771 asked for: enabled and not running, retry add with backoff.startupDefaulton, so the recovered driver confirms its default before control resumes.Add,RestartorReloadof the same name replaces the pending retry, and a user action restarts the backoff at 10 s. A stale timer finds a different entry and does nothing.Remove, aReloadthat no longer lists the driver, andShutdownAllend the retry.addruns. AReloadthat drops or disables the driver waits on its gate and removes whatever the retry left, andShutdownAllwaits for the attempt before it returns.AddProbe) are not retried.main.gois unchanged. The diff toregistry.gois 27 lines; the rest is a new file.Tests
TestBootSpawnFailureIsRetriedWhenSerialDeviceAppears(repro from the audit, caa-75): fails on master after 15 s and passes here in 10 s.TestSpawnRetryBacksOffAndStopsWhenDriverLeavescovers backoff to the cap, a reset on userAdd, a stale timer, and the end of retries on Reload, Remove and ShutdownAll.TestProbeFailureIsNotRetriedcovers probes.TestReloadDuringInflightRetrySuccessStopsDriver,TestReloadDuringInflightRetryFailureStopsRetryingandTestShutdownAllWaitsForInflightRetryblock a retry in its serial open, then callReloadorShutdownAll. All three fail without the in-flight mark (review finding) and pass with it.go test -race -count=1 ./internal/drivers/... ./internal/api/... ./cmd/ftw/...: pass.go vet ./...andgo build ./...: clean.Risk
Low. The change only acts when
Addhas already failed.One known cost: a cloud driver whose
driver_initfails on bad credentials now logs in every 5 min, which #1771 named as a lockout risk. The plan accepts that backoff. If a vendor locks accounts at that rate, a cap for login failures can follow.No hardware run. A serial P1 site should confirm recovery after a power cut on the next beta.
🤖 Generated with Claude Code