Skip to content

fix(health): exit 1 on probe usage errors and drop always-healthy healthcheck docs - #495

Merged
ff-fab merged 4 commits into
mainfrom
fix/health-probe-exit-codes
Oct 4, 2026
Merged

ff-fab merged 4 commits into
mainfrom
fix/health-probe-exit-codes

Conversation

@ff-fab

@ff-fab ff-fab commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

Health-probe argument errors previously exited 2, which Docker reserves for HEALTHCHECK. Both <app> health and cosalette health now exit 1 with unhealthy: usage error: <message> on stderr for invalid arguments.

  • Register a shared HealthCommand in both CLIs to map parsing errors to unhealthy results and explicitly preserve typer.Exit, including successful help exits.
  • Cover negative and nonnumeric maximum ages, unknown options, missing values for all three probe options, unexpected positional arguments, and successful help in both CLIs.
  • Replace the misleading MQTT subscription and process-existence healthcheck examples with explanations of their limitations. Qualify the retained-message prerequisite and the wait/timeout before the first retained status publish.
  • Document that options parsed before health still 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 Exit separate from TyperException; 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.
  • Combined unit/integration suite in 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

Fabian Koerner and others added 2 commits October 4, 2026 14:02
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>
Copilot AI balanced review requested due to automatic review settings October 4, 2026 14:13

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Low severity

Open (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 1 in 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.

Comment thread docs/guides/deployment.md Outdated
Comment on lines +360 to +363
- **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.
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

📖 Documentation Preview

https://cosalette-pr-495.surge.sh

Preview has been removed (PR closed).

Fabian Koerner added 2 commits October 4, 2026 14:48
Qualify retained status checks before the first publish.

Refs: cos-ht8o.1, cos-ht8o.2
@ff-fab
ff-fab merged commit ecb7c4f into main Oct 4, 2026
16 checks passed
@ff-fab
ff-fab deleted the fix/health-probe-exit-codes branch October 4, 2026 15:00
This was referenced Nov 21, 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