fix: make the shutdown reason name what set the exit code - #83
Merged
Merged
Conversation
The final `graceful shutdown: complete` line reported `reason` from the drain
phase even when cleanup was what failed, so it could read
`{reason: "drained", exitCode: 1}` — the one line an operator alerts on
contradicting itself. `reason` now names whatever decided the exit code
(`cleanup-timeout` / `cleanup-failed`), and the drain outcome keeps its own
`drain` key: a stable shape that loses neither fact.
The `exit` option's doc also still said it defaults to `process.exit` after the
default became `deferExit`.
Both shipped in v0.5.0 and were found reviewing the same code in
auth.provider#511, which this repo took as its starting point.
210 tests pass; typecheck, lint and build clean.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The change is small and well-tested, and the remaining feedback is limited to minor naming/doc clarity.
Pull request overview
This PR fixes an operationally confusing shutdown log by ensuring the logged reason always matches what set the final exit code (while preserving the drain-phase outcome separately), and updates related documentation and tests to lock the behavior in.
Changes:
- Adjust shutdown completion logging so
reasonreflects the exit-code-deciding outcome (cleanup-timeout/cleanup-failed) whiledrainretains the drain-phase result. - Add tests covering cleanup failure vs cleanup success to prevent regressions in shutdown log shape/semantics.
- Update the
exitoption doc and add an Unreleased changelog entry describing the fix.
File summaries
| File | Description |
|---|---|
| src/shutdown.mts | Updates shutdown completion log fields to avoid reason/exit-code contradictions and corrects exit option doc reference. |
| src/tests/shutdown.test.mts | Adds regression tests asserting the new { reason, drain, exitCode } logging behavior. |
| CHANGELOG.md | Documents the fix in the Unreleased section and notes the doc correction. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+17
to
+19
| `drain` key, so the shape stays stable and neither fact is lost. Shipped in | ||
| 0.5.0; found reviewing the same code in | ||
| [auth.provider#511](https://github.com/o3co/auth.provider/pull/511). |
Comment on lines
+149
to
+153
| // `reason` names whatever decided the exit code, so the line an operator | ||
| // alerts on cannot say "drained" next to a non-zero code. The drain | ||
| // outcome keeps its own key rather than being overwritten — both facts | ||
| // are wanted, and a stable shape is what makes the line queryable. | ||
| let outcome = reason; |
Merged
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.
Follow-up to #81, which shipped in v0.5.0. Both findings came from review of the same code in auth.provider#511 — this repo took that implementation as its starting point, so it inherited them.
The log line contradicted itself
finishsetexitCode = 1when cleanup timed out or threw, butreasonstill carried the drain-phase value. The final line could read:which is the one line an operator alerts on saying the shutdown drained cleanly next to the code that says it did not.
reasonnow names whatever decided the exit code —cleanup-timeoutorcleanup-failedwhen cleanup overrode the drain — and the drain outcome keeps its owndrainkey rather than being overwritten:Stable shape, both facts kept, no contradiction. Two tests pin it: one failed cleanup, one successful.
Stale doc
The
exitoption's doc said it defaults toprocess.exitafter #81 changed the default todeferExit. It points atdeferExitnow.Verification
pnpm test— 210 passed (14 files), 2 newpnpm typecheck,pnpm lint,pnpm build— clean🤖 Generated with Claude Code