Repository navigation
fix(health): exit 1 on probe usage errors and drop always-healthy healthcheck docs - #495
Conversation
Docker reserves exit code 2 for HEALTHCHECK (ADR-083), but Click exits 2 on usage errors such as `health --max-age -1` or an unknown option. The health subcommand now uses a HealthCommand class in both CLIs that reports these as `unhealthy: usage error: <message>` on stderr and exits 1. Errors in options placed before `health` are parsed by the group and still exit 2; the CLI reference documents this. Refs: cos-ht8o.1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
{prefix}/status is retained (heartbeat and LWT), so `mosquitto_sub -C 1`
gets the last message at once, even "offline", and exits 0 while the
broker is up. pgrep passes for a hung process. Replace both examples
with a short note on why they cannot fail and point to the health file
probe.
Refs: cos-ht8o.2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bcbcfe17bf
ℹ️ 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".
| # Any: the base returns typer's vendored, non-public click Context. | ||
| try: | ||
| return super().make_context(*args, **kwargs) | ||
| except typer.TyperException as exc: |
There was a problem hiding this comment.
Preserve successful health help exits
When a user runs cosalette health --help or <app> health --help, Typer raises its normal Exit(0) while building the context. Typer 0.27.2 explicitly makes all exception classes, including Exit, inherit TyperException (upstream change), so this handler intercepts the successful help exit and turns it into an exit-1 failure (and may attempt the unavailable format_message() on Exit). Re-raise typer.Exit unchanged or otherwise restrict this handler to actual usage errors.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The scoped implementation and regression coverage are consistent; only a non-blocking documentation qualification remains.
Review effort: Balanced
Findings: 1
What changed in this PR
Makes health-probe argument errors use Docker-compatible exit codes and steers deployment guidance toward the health-file probe.
Changes:
- Maps health argument errors to exit
1in both CLIs. - Adds six regression cases covering invalid arguments.
- Replaces unreliable healthcheck examples and documents the group-level parsing limitation.
| File | Description |
|---|---|
| packages/tests/unit/health/test_liveness.py | Tests usage errors across both CLIs. |
| packages/src/cosalette/_package_cli/__init__.py | Registers the custom health command. |
| packages/src/cosalette/_health/_liveness_cli.py | Converts parsing errors to unhealthy results. |
| packages/src/cosalette/_cli.py | Applies the command to application CLIs. |
| docs/reference/cli.md | Documents exit codes and parsing scope. |
| docs/guides/deployment.md | Replaces unreliable checks with warnings. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| - **Subscribing to `{prefix}/status`**, for example with `mosquitto_sub -C 1`. | ||
| The heartbeat and the LWT are both retained, so the broker hands the | ||
| subscriber the last message at once, even when that message is `"offline"`. | ||
| The command exits `0` for as long as the broker is up. |
📖 Documentation Preview
Preview has been removed (PR closed). |
Qualify retained status checks before the first publish. Refs: cos-ht8o.1, cos-ht8o.2

Summary
Health-probe argument errors previously exited 2, which Docker reserves for HEALTHCHECK. Both
<app> healthandcosalette healthnow exit 1 withunhealthy: usage error: <message>on stderr for invalid arguments.HealthCommandin both CLIs to map parsing errors to unhealthy results and explicitly preservetyper.Exit, including successful help exits.healthstill use the parent group's exit code 2.The parser uses Typer's public exception base because Typer vendors Click. Installed Typer 0.27.2 keeps
Exitseparate fromTyperException; the explicit passthrough makes the intended behavior clear and preserves it if the hierarchy changes.PR #494 has merged, and its formatting and lockfile fixes are integrated into this branch.
Validation
task lint: passed.task test:unit: 5,106 passed.task pre-pr: 5,206 passed, 15 deselected (MQTT/Docker tests excluded by the task).task pre-pr: passed, including pre-commit, lint, type checking, tests, complexity, documentation, security audits, and beads check.Refs: cos-ht8o.1, cos-ht8o.2