Skip to content

fix(container): surface docker health status in rtk docker ps output - #1845

Closed
Donotavio wants to merge 1 commit into
rtk-ai:developfrom
Donotavio:fix/container-surface-docker-health
Closed

Donotavio wants to merge 1 commit into
rtk-ai:developfrom
Donotavio:fix/container-surface-docker-health

Conversation

@Donotavio

Copy link
Copy Markdown

Problem

`rtk docker ps` fetches `{{.Status}}` which already includes health state when configured:
```
Up 2 hours (healthy)
Up 1 hour (unhealthy)
```

But `docker_ps()` parsed `parts[2]` (Status field) and discarded it completely. An AI agent monitoring containers had no way to identify unhealthy services.

Fix

  • Include Status field in output between name and image
  • Prefix unhealthy containers with `[!]` for immediate visibility
  • All other states (healthy, plain Up, Exited, Restarting) pass through verbatim

Refactoring

  • Extract `format_docker_ps_line(parts) -> Option` as `pub(crate)` pure function — directly unit-testable without spawning docker
  • Extract `trim_image_registry()` helper — eliminates duplication with `format_compose_ps()` which had the identical `.split('/').next_back()` pattern
  • Add `UNHEALTHY_PREFIX` constant

Tests

7 new unit tests:

  • `test_docker_ps_preserves_healthy_status` — (healthy) shown verbatim, no [!]
  • `test_docker_ps_marks_unhealthy_prominently` — [!] prefix present
  • `test_docker_ps_shows_status_without_health_check` — plain Up shown
  • `test_docker_ps_exited_no_flag` — Exited shown, no [!]
  • `test_docker_ps_restarting_no_flag` — Restarting shown, no [!]
  • `test_docker_ps_line_too_few_parts_returns_none` — None guard for malformed input
  • `test_docker_ps_formats_all_five_containers` — all 5 states in one pass

Identified via adversarial testing: https://www.reddit.com/r/ClaudeCode/comments/1spiy8t/

docker ps already fetches {{.Status}} which includes health state:
  'Up 2 hours (healthy)', 'Up 1 hour (unhealthy)'
but docker_ps() parsed parts[2] and discarded it silently. An AI agent
monitoring containers could not detect unhealthy services.

Changes:
- Extract format_docker_ps_line(parts) as pub(crate) pure function
  so it can be unit-tested without spawning docker
- Include status in output between name and image
- Prefix unhealthy containers with [!] for immediate visibility
- Extract trim_image_registry() helper, eliminating duplication
  with format_compose_ps() which had the same split('/').next_back()
- Add UNHEALTHY_PREFIX const to avoid magic string duplication
- Add 7 targeted tests covering healthy, unhealthy, exited,
  restarting states and the None guard for malformed input
@CLAassistant

CLAassistant commented May 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
@KuSh

KuSh commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this. The docker ps line formatting was pulled into its own helper on develop as format_container_line_from_parts, shared with docker ps -a, and it now prints the container status, first in #1895 on 2026-05-19 and then in commits 861a46d, 3d4189c and b52db52 in June, which also added the never-worse guard and the tee hint around it. Because develop prints the fields in a different order (id, name, image, status), the tests here assert a shape that no longer exists. Two things from this PR are still missing on develop: there is no visual marker such as [!] when a health check is failing, so (unhealthy) reads like any other status text, and the registry trim is still duplicated at three call sites instead of a shared helper. Both would be welcome as a small issue or a narrow PR on the current helper. If I missed a part of this, please comment or reopen.

@KuSh KuSh closed this Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants