Skip to content

fix: make the shutdown reason name what set the exit code - #83

Merged
y1o1 merged 1 commit into
developfrom
fix/shutdown-reason-consistency
Sep 6, 2026
Merged

y1o1 merged 1 commit into
developfrom
fix/shutdown-reason-consistency

Conversation

@y1o1

@y1o1 y1o1 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

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

finish set exitCode = 1 when cleanup timed out or threw, but reason still carried the drain-phase value. The final line could read:

{ reason: "drained", exitCode: 1 }

which is the one line an operator alerts on saying the shutdown drained cleanly next to the code that says it did not.

reason now names whatever decided the exit code — cleanup-timeout or cleanup-failed when cleanup overrode the drain — and the drain outcome keeps its own drain key rather than being overwritten:

{ reason: "cleanup-failed", drain: "drained", exitCode: 1 }

Stable shape, both facts kept, no contradiction. Two tests pin it: one failed cleanup, one successful.

Stale doc

The exit option's doc said it defaults to process.exit after #81 changed the default to deferExit. It points at deferExit now.

Verification

  • pnpm test210 passed (14 files), 2 new
  • pnpm typecheck, pnpm lint, pnpm build — clean

🤖 Generated with Claude Code

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>
Copilot AI lite review requested due to automatic review settings September 6, 2026 11:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 reason reflects the exit-code-deciding outcome (cleanup-timeout / cleanup-failed) while drain retains the drain-phase result.
  • Add tests covering cleanup failure vs cleanup success to prevent regressions in shutdown log shape/semantics.
  • Update the exit option 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 thread CHANGELOG.md
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 thread src/shutdown.mts
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;
@y1o1
y1o1 merged commit def6fe0 into develop Sep 6, 2026
2 checks passed
@y1o1
y1o1 deleted the fix/shutdown-reason-consistency branch September 6, 2026 11:17
@y1o1 y1o1 mentioned this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants