feat: notify when a container fails or turns unhealthy #26

Merged
jfro merged 1 commit from feat/19-notifications into main 2026-11-30 19:30:54 +00:00
Owner

Desktop notifications when a container exits with an error, runs out of memory, or turns unhealthy. Clicking one (or its Show Logs button) opens Krane on that container's logs.

Closes #19

Stacked on #25 (start at login), which is stacked on #24, #23 and #22. Retarget to main once those merge.

What's in it

  • src/notify.rs: listens to container events and talks to org.freedesktop.Notifications over D-Bus. zbus is already in the build through ksni, so it's now a direct dependency with no new crates.
  • What stays quiet, following Nye's event research for Docker 26 and Podman 5.4:
    • stops Krane makes (stop, restart, remove; it remembers the ids for 10 s, which covers Podman too, since Podman sends no kill/stop events)
    • docker stop/kill/rm -f from the CLI on Docker (a kill or stop within 10 s before the die)
    • clean exits (code 0)
  • oom + die become one "Ran out of memory" notification. A restart loop notifies at most once a minute per container, and the new notification replaces the old one.
  • Health: Docker's health_status: unhealthy notifies. Podman's health_status has no status and repeats on every check, so Krane inspects the container and notifies only when it turns unhealthy.
  • The title uses the compose service and project when there is one ("web (shop) stopped"). The body is escaped for servers that parse markup. Actions are sent only if the server supports them. D-Bus calls time out after 5 s, so a missing or stuck notification server can't hold up the listener.
  • Setting: Notify When Containers Fail in the tray menu and the window's settings menu, on by default. It's stored in ~/.config/krane/settings.json.
  • README features and layout updated. Screenshots regenerated (the settings scene shows the new item).

notification

(Xfce 4.20 here. The icon is blank only because Krane's icon isn't installed on this test box.)

Tested

  • 8 unit tests for the event logic: crash, clean exit, CLI stop, Krane stop without kill events, oom+die, restart loop, Docker health, Podman health transitions.
  • Live on Docker 29 with xfce4-notifyd:
    • a crash (exit 3) and an unhealthy container each notified once
    • docker stop stayed quiet
    • clicking Show Logs opened the window on the crashed container's logs
  • Not tried on Podman or KDE/GNOME notification servers.
  • Local CI: fmt, clippy -D warnings with and without mock, build, and tests with and without mock.

#16 will need to move this listener onto the shared engine client and restart it when the engine changes.

Desktop notifications when a container exits with an error, runs out of memory, or turns unhealthy. Clicking one (or its **Show Logs** button) opens Krane on that container's logs. Closes #19 Stacked on #25 (start at login), which is stacked on #24, #23 and #22. Retarget to main once those merge. ## What's in it - **`src/notify.rs`**: listens to container events and talks to `org.freedesktop.Notifications` over D-Bus. zbus is already in the build through ksni, so it's now a direct dependency with no new crates. - **What stays quiet**, following Nye's event research for Docker 26 and Podman 5.4: - stops Krane makes (stop, restart, remove; it remembers the ids for 10 s, which covers Podman too, since Podman sends no kill/stop events) - `docker stop`/`kill`/`rm -f` from the CLI on Docker (a kill or stop within 10 s before the `die`) - clean exits (code 0) - `oom` + `die` become one "Ran out of memory" notification. A restart loop notifies at most once a minute per container, and the new notification replaces the old one. - **Health**: Docker's `health_status: unhealthy` notifies. Podman's `health_status` has no status and repeats on every check, so Krane inspects the container and notifies only when it *turns* unhealthy. - The title uses the compose service and project when there is one ("web (shop) stopped"). The body is escaped for servers that parse markup. Actions are sent only if the server supports them. D-Bus calls time out after 5 s, so a missing or stuck notification server can't hold up the listener. - **Setting**: *Notify When Containers Fail* in the tray menu and the window's settings menu, on by default. It's stored in `~/.config/krane/settings.json`. - README features and layout updated. Screenshots regenerated (the settings scene shows the new item). ![notification](https://git.knope.dev/attachments/7786e7d8-ba43-46fc-b1c3-6266c236d3fa) (Xfce 4.20 here. The icon is blank only because Krane's icon isn't installed on this test box.) ## Tested - 8 unit tests for the event logic: crash, clean exit, CLI stop, Krane stop without kill events, oom+die, restart loop, Docker health, Podman health transitions. - Live on Docker 29 with xfce4-notifyd: - a crash (exit 3) and an unhealthy container each notified once - `docker stop` stayed quiet - clicking Show Logs opened the window on the crashed container's logs - Not tried on Podman or KDE/GNOME notification servers. - Local CI: fmt, clippy -D warnings with and without mock, build, and tests with and without mock. #16 will need to move this listener onto the shared engine client and restart it when the engine changes.
feat: notify when a container fails or turns unhealthy
All checks were successful
CI / test (pull_request) Successful in 5m3s
f4730a01ae
Closes #19
jfro force-pushed feat/19-notifications from f4730a01ae
All checks were successful
CI / test (pull_request) Successful in 5m3s
to 78bdd8e0d5
All checks were successful
CI / test (pull_request) Successful in 5m15s
2026-11-30 17:24:57 +00:00
Compare
jfro left a comment

Review from Nye (posted by Upper Wolfjaw):

PR #26 (#19 notifications) review at f4730a0: CHANGES REQUESTED

C7 pass: fmt, clippy -D warnings (with/without mock), both builds, 26 tests. Live on Docker 26
(private D-Bus session, fake notification server fake_notifyd.py, pr26-live.sh): crash exit 3 ->
"stopped / Exited with code 3." with default+Show Logs actions; OOM -> one alert "Ran out of memory";
health-cmd false -> "is unhealthy"; clean exit and docker stop quiet. Code reads well: Tracker logic,
5 s D-Bus timeouts, escaping only with body-markup, replaces_id per container.

F9 (medium): Podman CLI stops alert. podman stop (and docker stop/compose against Podman's socket)
send only die 137 (no kill/stop event; checked on the events stream), so Krane shows
"nye-p-stop stopped / Exited with code 137". README promises CLI stops stay quiet.
Proof: notes/pr26-podman-stop-proof.sh (run in pr26 worktree; needs rootless podman socket).
Fix options: treat die with exitCode 137 or 143 and no preceding oom as a stop (quiet), at least when
the engine is Podman (version Components "Podman Engine"); or narrow the README claim. Former preferred.

F8 (low): login race. Notifier::connect caches GetCapabilities; if the notification server isn't on
the bus yet (KDE/GNOME: server is the shell, not D-Bus activatable; Krane via start at login), caps =
[] for the whole session -> no "default" action (click never opens logs) and no escaping.
Proof: notes/pr26-live.sh late (bus config session-noactivation.conf, server starts 3 s after Krane).
Fix: don't keep an empty/failed capability answer; re-ask GetCapabilities in show() until one succeeds
(or ask every time; it's one cheap call with the 5 s timeout).

Notes (not blocking):

  • Noise worth a later look: docker run --rm img false or Ctrl-C (130) in docker run -it alerts.
  • Quiet minute is shared by die and unhealthy (unhealthy then crash within 60 s: crash quiet). Fine.
  • Pre-existing, not this PR: on Podman Krane logs "Failed to fetch containers: unknown variant
    stopping" when a container is mid-stop (bollard enum). Worth an issue for #16 (engine picker).
  • Untried: real click on KDE/GNOME, Podman health/oom path (UW also untried).
Review from Nye (posted by Upper Wolfjaw): # PR #26 (#19 notifications) review at f4730a0: CHANGES REQUESTED C7 pass: fmt, clippy -D warnings (with/without mock), both builds, 26 tests. Live on Docker 26 (private D-Bus session, fake notification server fake_notifyd.py, pr26-live.sh): crash exit 3 -> "stopped / Exited with code 3." with default+Show Logs actions; OOM -> one alert "Ran out of memory"; health-cmd false -> "is unhealthy"; clean exit and `docker stop` quiet. Code reads well: Tracker logic, 5 s D-Bus timeouts, escaping only with body-markup, replaces_id per container. F9 (medium): Podman CLI stops alert. `podman stop` (and `docker stop`/compose against Podman's socket) send only `die 137` (no kill/stop event; checked on the events stream), so Krane shows "nye-p-stop stopped / Exited with code 137". README promises CLI stops stay quiet. Proof: notes/pr26-podman-stop-proof.sh (run in pr26 worktree; needs rootless podman socket). Fix options: treat die with exitCode 137 or 143 and no preceding oom as a stop (quiet), at least when the engine is Podman (version Components "Podman Engine"); or narrow the README claim. Former preferred. F8 (low): login race. Notifier::connect caches GetCapabilities; if the notification server isn't on the bus yet (KDE/GNOME: server is the shell, not D-Bus activatable; Krane via start at login), caps = [] for the whole session -> no "default" action (click never opens logs) and no escaping. Proof: `notes/pr26-live.sh late` (bus config session-noactivation.conf, server starts 3 s after Krane). Fix: don't keep an empty/failed capability answer; re-ask GetCapabilities in show() until one succeeds (or ask every time; it's one cheap call with the 5 s timeout). Notes (not blocking): - Noise worth a later look: `docker run --rm img false` or Ctrl-C (130) in `docker run -it` alerts. - Quiet minute is shared by die and unhealthy (unhealthy then crash within 60 s: crash quiet). Fine. - Pre-existing, not this PR: on Podman Krane logs "Failed to fetch containers: unknown variant `stopping`" when a container is mid-stop (bollard enum). Worth an issue for #16 (engine picker). - Untried: real click on KDE/GNOME, Podman health/oom path (UW also untried).
jfro force-pushed feat/19-notifications from 78bdd8e0d5
All checks were successful
CI / test (pull_request) Successful in 5m15s
to 42dfed553a
All checks were successful
CI / test (pull_request) Successful in 5m18s
2026-11-30 18:02:28 +00:00
Compare
Author
Owner

Fixed both findings in 42dfed5 (amended; #27 rebased onto it as 73ece6f).

  • F8: the notification server's capabilities are no longer read once at start. Until the server answers GetCapabilities, Krane asks again before each notification, and keeps the answer only once it gets one. notes/pr26-live.sh late passes: the crash alert has the default/Show Logs actions.
  • F9: Krane checks the engine's version components when it connects. On Podman, a die with 137 or 143 and no oom counts as a stop and stays quiet. Crashes (any other code) and OOMs still alert, and nothing changes on Docker. notes/pr26-podman-stop-proof.sh passes on Podman 5.4.2. New unit test: podman_cli_stop_is_quiet_but_its_crashes_and_ooms_alert.
    Trade-off: on Podman, an outside kill -9 (with no OOM) is now quiet too, because the events stream can't tell it apart from a stop.

Local CI is green: fmt, clippy (both feature sets), builds, and 31 tests.

Fixed both findings in 42dfed5 (amended; #27 rebased onto it as 73ece6f). - **F8**: the notification server's capabilities are no longer read once at start. Until the server answers GetCapabilities, Krane asks again before each notification, and keeps the answer only once it gets one. `notes/pr26-live.sh late` passes: the crash alert has the default/Show Logs actions. - **F9**: Krane checks the engine's version components when it connects. On Podman, a `die` with 137 or 143 and no `oom` counts as a stop and stays quiet. Crashes (any other code) and OOMs still alert, and nothing changes on Docker. `notes/pr26-podman-stop-proof.sh` passes on Podman 5.4.2. New unit test: `podman_cli_stop_is_quiet_but_its_crashes_and_ooms_alert`. Trade-off: on Podman, an outside `kill -9` (with no OOM) is now quiet too, because the events stream can't tell it apart from a stop. Local CI is green: fmt, clippy (both feature sets), builds, and 31 tests.
jfro changed target branch from feat/18-start-at-login to main 2026-11-30 18:28:04 +00:00
jfro force-pushed feat/19-notifications from 42dfed553a
All checks were successful
CI / test (pull_request) Successful in 5m18s
to 5838fb897c
Some checks failed
CI / test (pull_request) Successful in 4m49s
CI / test (push) Has been cancelled
2026-11-30 18:54:35 +00:00
Compare
Author
Owner

F11 fixed in 5838fb8: a die 137/143 with no kill, stop or oom event now inspects the container. State.OOMKilled=true alerts "Ran out of memory" (Podman's only signal, and Docker's oom-after-die race). Otherwise Podman treats it as a stop, and Docker alerts the exit code. A late oom only counts within 10 s of the die. Nye's OOM proof passes (2 of 3 containers marked OOMKilled, both alerted as out of memory; podman stop quiet), and the F9 stop proof still passes. 3 new unit tests.

F11 fixed in 5838fb8: a `die` 137/143 with no kill, stop or oom event now inspects the container. `State.OOMKilled=true` alerts "Ran out of memory" (Podman's only signal, and Docker's oom-after-die race). Otherwise Podman treats it as a stop, and Docker alerts the exit code. A late `oom` only counts within 10 s of the die. Nye's OOM proof passes (2 of 3 containers marked OOMKilled, both alerted as out of memory; podman stop quiet), and the F9 stop proof still passes. 3 new unit tests.
jfro merged commit 5838fb897c into main 2026-11-30 19:30:54 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/krane!26
No description provided.