refactor(diagnostics): make error closer restartable (2/9) - #781
Conversation
🔐 Codex Security Review
Review SummaryOverall Risk: NONE FindingsNo security, correctness, or reliability findings were identified in the reviewed diff. NotesReviewed Generated by Codex Security Review | |
3429797 to
4386873
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4386873c75
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Refactors the diagnostics error closer so constructing the diagnostics service is side-effect free, and the closer can be explicitly started/stopped (restartable) via the shared runtimejobs.Lifecycle contract. This aligns diagnostics with the broader “explicit activation” direction for Fleet background work and preserves standalone fleetd behavior by starting the closer during boot and stopping it during shutdown.
Changes:
- Convert diagnostics closer startup from constructor side effect to explicit
Start/Stoplifecycle methods. - Update
fleetdstartup/shutdown to start diagnostics explicitly and stop it via the bounded standalone stop helper. - Adjust diagnostics consumers/tests to use the new constructor signature and add lifecycle-oriented closer tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| server/internal/handlers/errorquery/handler_test.go | Updates diagnostics service construction to match new side-effect-free constructor. |
| server/internal/domain/diagnostics/watcher_test.go | Updates diagnostics service construction in watcher tests to the new signature. |
| server/internal/domain/diagnostics/service.go | Introduces restartable lifecycle state and implements runtimejobs.Lifecycle via Start/Stop. |
| server/internal/domain/diagnostics/service_test.go | Updates test helper to construct diagnostics service without passing a context. |
| server/internal/domain/diagnostics/closer_test.go | Reworks closer tests to validate explicit start/stop and restart behavior. |
| server/cmd/fleetd/main.go | Starts diagnostics closer explicitly at boot and stops it via stopStandaloneJob during shutdown. |
- clear closer lifecycle state when each run exits - let timed-out stops finish cleanup asynchronously - allow extra retry-loop polls in the closer test
Reviewable diff: +81/-9 across 2 files (excludes generated, test, and story files).
Summary
Diagnostics error closing is now explicitly activatable and restartable, so a passive Fleet can construct diagnostics without silently starting background work. Standalone
fleetdstill starts the closer during boot and drains it during shutdown.Stack:
fleetdcutover: #788This PR is the diagnostics lifecycle slice and now targets
main. Merged #780 supplies the sharedruntimejobs.Lifecyclecontract; the remaining domain and orchestration refactors are independent sibling PRs and can merge in any order. #788 is temporarily based on the integration branch so its reviewable diff contains only catalog/cutover work; after the siblings merge it will be rebased and retargeted tomain. Passive-mode coordinator wiring, epoch fencing, and request gating remain later HA work.How it works
NewServiceonly constructs dependencies.fleetdcallsStartexplicitly, which creates one activation context and closer loop. The run identity-safely clears its own state before signaling completion, whether it ends throughStopor independent activation-context cancellation.Stopsnapshots the run under the mutex, waits unlocked, and may return at the caller deadline while cleanup continues; restart is admitted after the prior run actually exits.flowchart LR C["Construct diagnostics service"] --> S["fleetd calls Start"] S --> L["Error closer loop"] X["Shutdown or demotion"] --> T["Stop with deadline"] T --> L T --> R["Safe to start again"]Areas of the code involved
server/internal/domain/diagnostics/service.goserver/cmd/fleetd/main.goKey technical decisions & trade-offs
Service; no diagnostics-specific job wrapper is introduced.Related
Related: #740
Testing & validation
go test -short -race -count=1 ./internal/domain/diagnostics ./internal/handlers/errorquery ./cmd/fleetdStart -> Stop -> Start.Post-Deploy Monitoring & Validation
Watch diagnostics closer errors and verify stale miner errors continue to transition closed. Roll back if the closer stops running after startup or shutdown logs report a diagnostics drain failure.