Skip to content

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

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

fix(container): surface docker health status in rtk docker ps output#1845
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
Copy link
Copy Markdown

CLAassistant commented May 11, 2026

CLA assistant check
All committers have signed the CLA.

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