Skip to content

✨ feat(notifications): health-status event notifications (#198) - #505

Merged
scttbnsn merged 2 commits into
dev/v1.6from
feat/v1.6-health-events
Jul 12, 2026
Merged

scttbnsn merged 2 commits into
dev/v1.6from
feat/v1.6-health-events

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements the v1.6 roadmap commitment from Discussion #198: a new container-unhealthy notification rule that fires your existing notification triggers the moment a container's Docker health check enters the unhealthy state.

How it works

  • Detection on both legs. The Docker events stream now subscribes to health_status (near-instant firing), and the cron refresh inspects every already-known container each cycle, so health is still captured while the events listener is disconnected/backing off or with DD_WATCHER_<name>_WATCHEVENTS=false.
  • Edge-triggered. Fires only on an observed transition into unhealthy within the same container instantiation: never repeatedly while a container stays unhealthy, never on first observation with no baseline (fresh discovery/recreate, or store records predating health tracking), and a changed details.startedAt on both observations marks a fast crash-loop as a genuinely new episode.
  • Dispatch reuses the lifecycle-event pipeline (update-applied/agent-disconnect precedent): threshold bypassed, batch mode supported, per-container dd.notification.include/dd.notification.exclude respected, outbox retry on provider failure. Remote-agent containers work via the existing store-forwarding path with zero agent-specific code.
  • Disabled by default. The rule ships enabled: false with an empty trigger list, matching the agent-connectivity rules. Zero new env vars, zero new labels, zero per-provider config.
  • Audit + metrics. container-unhealthy audit rows (status error) with a 5-minute per-container dedupe window and the standard audit Prometheus counter.
  • Fail-safe on unknown values. An out-of-enum State.Health.Status from a future Docker version normalizes to undefined at the model boundary — unknown is not assumed unhealthy, and it can no longer throw mid-update.

Docs

Triggers docs (rules table, dispatch behavior, event types), CHANGELOG [Unreleased], README v1.6 roadmap row, en locale entry for the Notifications view.

Verification

  • 11,684 app tests / 4,060 ui tests green; 100% coverage thresholds hold in both workspaces.
  • Full lefthook pre-push gate green (qlty, sharded coverage, builds, zizmor).
  • Implementation + tests adversarially verified against the scope doc by an 11-agent review workflow; all confirmed findings (the Joi throw on unknown health values, two spurious-fire windows in the v1.5→v1.6 upgrade transition, a coverage gap) were fixed and regression-tested before this PR.

Ref: Discussion #198

Changelog

  • ✨ Added container-unhealthy notification rule (disabled by default) with Docker health_status-driven edge-triggered transitions.
  • ✨ Implemented container health transition event plumbing (emit/register + provider dispatch) with batch-mode support and templates that optionally include “previous health”.
  • ✨ Added time-windowed audit deduplication for container-unhealthy with (was healthy) audit details when previousHealth is available; increments Prometheus counters.
  • ✨ Added restart-episode re-notification behavior using details.startedAt, plus guards to avoid firing on first observation when no prior health baseline exists (legacy records).
  • 🔧 Normalized unknown/invalid Docker health statuses to undefined and updated Docker watcher/inspect flows + event filters to include health_status.
  • 🔧 Updated persistence/normalization and UI/docs/localization for the new notification rule and v1.6 roadmap/triggers.

Concerns

  • Always inspecting stored containers when refreshing/backfilling may increase Docker API usage; confirm operational impact.
  • Audit deduplication is keyed by containerName; verify uniqueness/consistency for the intended audience.
  • Notification/audit correctness is sensitive to details.startedAt availability and rollback-pattern matching; verify these edge cases in production-like data.

- ✨ feat(watcher): capture State.Health on the event leg (new health_status event type, changed-flag wiring) and the cron leg (unconditional store-refresh inspect so health is read every cycle)
- ✨ feat(store): edge-triggered container-unhealthy transition detection — restart-reset via details.startedAt on both observations, no fire without an observed baseline, rollback containers excluded
- ✨ feat(triggers): container-unhealthy notification rule (disabled by default), simple + batch templates, threshold-bypassing dispatch through the existing lifecycle-event pipeline
- ✨ feat(audit): container-unhealthy audit rows with 5-minute per-container dedupe and Prometheus audit counter
- 🐛 fix(model): out-of-enum Docker health values normalize to undefined at the model boundary instead of throwing mid-update
- ✅ test: full 100% coverage across model, watcher, store, event, trigger, notification, and audit suites
- 📝 docs: triggers docs rule/event tables, CHANGELOG entry, README roadmap row, en locale entry

Ref: Discussion #198
@vercel

vercel Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drydock-website Ready Ready Preview, Comment Jul 12, 2026 2:05am
drydockdemo-website Ready Ready Preview, Comment Jul 12, 2026 2:05am

@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 80cf76bc-8bee-4fab-8242-4798862676ac

📥 Commits

Reviewing files that changed from the base of the PR and between 8ae838b and 08da309.

📒 Files selected for processing (6)
  • app/event/audit-subscriptions.test.ts
  • app/event/audit-subscriptions.ts
  • app/store/container.test.ts
  • app/store/container.ts
  • app/watchers/providers/docker/docker-image-details-orchestration.ts
  • content/docs/current/configuration/triggers/index.mdx
🚧 Files skipped from review as they are similar to previous changes (6)
  • content/docs/current/configuration/triggers/index.mdx
  • app/event/audit-subscriptions.test.ts
  • app/event/audit-subscriptions.ts
  • app/watchers/providers/docker/docker-image-details-orchestration.ts
  • app/store/container.test.ts
  • app/store/container.ts

📝 Walkthrough

Walkthrough

Adds Docker health-state normalization and persistence across inspection, event, and store flows. Eligible transitions into unhealthy emit an ordered event with previous health information. Audit subscriptions record deduplicated container-unhealthy actions. Notification rules, templates, trigger lifecycle wiring, batch handling, and provider failure handling support the new event. Tests cover model validation, Docker ingestion, transition detection, event dispatch, auditing, notification persistence, rendering, and lifecycle behavior. Documentation and localization describe the new rule.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/v1.6-health-events

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/watchers/providers/docker/docker-image-details-orchestration.ts (1)

405-430: 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Avoid the extra inspect on the stored-container path. watch() is only reached from watchFromCron(), so this adds one Docker round-trip per tracked container on every scheduled scan. Reuse the inspect already flowing through the refresh path instead of calling inspectDiscoveredContainer() again.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/watchers/providers/docker/docker-image-details-orchestration.ts` around
lines 405 - 430, The stored-container refresh path performs a redundant Docker
inspect. Update refreshContainerAlreadyInStore to reuse the inspect result
already supplied through its context or refresh flow, and remove the direct
inspectDiscoveredContainer call while preserving the existing successful-inspect
health normalization and failure behavior.
🧹 Nitpick comments (2)
app/watchers/providers/docker/docker-image-details-orchestration.ts (1)

405-414: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Dead containerInspect field in RefreshContainerAlreadyInStoreContext.

containerInspect is passed into the context at the call site (line 723) but never destructured/used inside refreshContainerAlreadyInStore — the function always re-fetches its own copy at line 427. This field is vestigial and misleading; drop it from the type/call site, or if the intent was to allow callers to skip a duplicate inspect, wire it through instead of ignoring it.

♻️ Suggested cleanup
   if (containerInStore !== undefined && containerInStore.error === undefined) {
     return refreshContainerAlreadyInStore({
       watcher,
       container,
       dockerContainerName,
       labelOverrides,
       helpers,
       runtimeDetailsFromSummary,
       containerInStore,
-      containerInspect: undefined,
     });
   }

Also applies to: 693-725

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/watchers/providers/docker/docker-image-details-orchestration.ts` around
lines 405 - 414, Remove the unused containerInspect field from
RefreshContainerAlreadyInStoreContext and stop passing it at the
refreshContainerAlreadyInStore call site. Keep the function’s existing container
inspection behavior unchanged unless the field is intentionally wired through to
avoid the duplicate fetch.
app/event/audit-subscriptions.ts (1)

160-180: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Include previousHealth in the audit record's details.

Other handlers (update-failed, security-alert) populate details with useful context; this one omits payload.previousHealth, losing troubleshooting context available on the payload.

♻️ Proposed fix
     auditStore.insertAudit({
       id: '',
       timestamp: new Date().toISOString(),
       action: 'container-unhealthy',
       containerName: payload.containerName,
       status: 'error',
+      details: payload.previousHealth ? `previousHealth: ${payload.previousHealth}` : undefined,
     });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/event/audit-subscriptions.ts` around lines 160 - 180, Update the audit
record created in the registerContainerHealthTransition handler to include
payload.previousHealth in its details field, preserving the existing
container-unhealthy action, status, deduplication, and counter behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/store/container.ts`:
- Around line 738-748: Move the existing.health === undefined guard ahead of the
restarted calculation so unobserved health returns undefined without evaluating
startedAt differences. Preserve restart detection only for containers with a
recorded health value, and add a regression test covering differing startedAt
values with undefined existing health and no entered-unhealthy notification.

In `@content/docs/current/configuration/triggers/index.mdx`:
- Line 185: Update the container-unhealthy trigger description to clarify that
it may fire again when a still-unhealthy container restarts and its
details.startedAt value changes, while retaining the existing behavior for
continuous unhealthy state without a restart.

---

Outside diff comments:
In `@app/watchers/providers/docker/docker-image-details-orchestration.ts`:
- Around line 405-430: The stored-container refresh path performs a redundant
Docker inspect. Update refreshContainerAlreadyInStore to reuse the inspect
result already supplied through its context or refresh flow, and remove the
direct inspectDiscoveredContainer call while preserving the existing
successful-inspect health normalization and failure behavior.

---

Nitpick comments:
In `@app/event/audit-subscriptions.ts`:
- Around line 160-180: Update the audit record created in the
registerContainerHealthTransition handler to include payload.previousHealth in
its details field, preserving the existing container-unhealthy action, status,
deduplication, and counter behavior.

In `@app/watchers/providers/docker/docker-image-details-orchestration.ts`:
- Around line 405-414: Remove the unused containerInspect field from
RefreshContainerAlreadyInStoreContext and stop passing it at the
refreshContainerAlreadyInStore call site. Keep the function’s existing container
inspection behavior unchanged unless the field is intentionally wired through to
avoid the duplicate fetch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 898a5415-12c0-477b-829b-4ec874d6970c

📥 Commits

Reviewing files that changed from the base of the PR and between 4390aef and 8ae838b.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (26)
  • README.md
  • app/event/audit-subscriptions.test.ts
  • app/event/audit-subscriptions.ts
  • app/event/index.test.ts
  • app/event/index.ts
  • app/model/audit.d.ts
  • app/model/container.test.ts
  • app/model/container.ts
  • app/store/container.test.ts
  • app/store/container.ts
  • app/store/notification.test.ts
  • app/store/notification.ts
  • app/triggers/providers/Trigger.test.ts
  • app/triggers/providers/Trigger.ts
  • app/watchers/providers/docker/Docker.containers.details.test.ts
  • app/watchers/providers/docker/Docker.containers.test.ts
  • app/watchers/providers/docker/Docker.events.test.ts
  • app/watchers/providers/docker/container-event-update.test.ts
  • app/watchers/providers/docker/container-event-update.ts
  • app/watchers/providers/docker/docker-event-orchestration.test.ts
  • app/watchers/providers/docker/docker-events.test.ts
  • app/watchers/providers/docker/docker-events.ts
  • app/watchers/providers/docker/docker-image-details-orchestration.test.ts
  • app/watchers/providers/docker/docker-image-details-orchestration.ts
  • content/docs/current/configuration/triggers/index.mdx
  • ui/src/locales/en/listViews.json

Comment thread app/store/container.ts Resolved
 review)

- 🐛 fix(store): move the unobserved-baseline guard ahead of restart detection so a legacy record with no recorded health never fires on its first observed unhealthy state
- ✨ feat(audit): include previous health in the container-unhealthy audit row details
- 🔄 refactor(watcher): drop the dead containerInspect context field from the store-refresh path
- 📝 docs(triggers): document the restart-episode re-notification exception
- ✅ test: regressions for the guard ordering and both audit details branches
@scttbnsn
scttbnsn merged commit 7abd671 into dev/v1.6 Jul 12, 2026
5 checks passed
@scttbnsn
scttbnsn deleted the feat/v1.6-health-events branch July 12, 2026 02:07

This branch was successfully deployed

2 active deployments
Preview – drydock-website — 08da309b Deployed Jul 12, 2026 by vercel[bot]
Preview – drydockdemo-website — 08da309b Deployed Jul 12, 2026 by vercel[bot]
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.

1 participant