Skip to content

fix(gateway): merge runtime state into health endpoint channel snapshots#42586

Closed
rstar327 wants to merge 1 commit into
openclaw:mainfrom
rstar327:fix-health-endpoint-whatsapp-status
Closed

fix(gateway): merge runtime state into health endpoint channel snapshots#42586
rstar327 wants to merge 1 commit into
openclaw:mainfrom
rstar327:fix-health-endpoint-whatsapp-status

Conversation

@rstar327

Copy link
Copy Markdown
Contributor

Summary

  • Problem: The health endpoint returns running: false, connected: false for WhatsApp (and other channels) even when the channel is active, while channels.status returns the correct values
  • Why it matters: Monitoring systems relying on the health endpoint get false negatives, potentially triggering unnecessary alerts or restarts
  • What changed: getHealthSnapshot() now accepts optional runtime state and merges it into channel snapshots before passing to buildChannelSummary. The gateway wires getRuntimeSnapshot from the channel manager through startGatewayMaintenanceTimerssetRuntimeSnapshotFnrefreshGatewayHealthSnapshot
  • What did NOT change (scope boundary): channels.status endpoint, CLI health command (no runtime available in CLI context), channel manager runtime tracking

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

The health endpoint now returns correct running and connected values for all channels, matching channels.status.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Any
  • Channel: WhatsApp (or any channel with runtime state)

Steps

  1. Start gateway with WhatsApp linked and connected
  2. Call health endpoint
  3. Check channels.whatsapp.running and channels.whatsapp.connected

Expected

  • running: true, connected: true (matching channels.status)

Actual

  • Before: running: false, connected: false
  • After: running: true, connected: true

Evidence

Human Verification (required)

  • Verified scenarios: Runtime snapshot is merged into channel account snapshot via spread operator, with accountId/enabled/configured taking precedence over runtime values
  • Edge cases checked: CLI health command (no runtime available — behavior unchanged, runtime param is optional); channel with no runtime entry (runtimeSnapshot is undefined, no spread)
  • What you did not verify: End-to-end with live WhatsApp channel

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Revert commit
  • Files/config to restore: src/commands/health.ts, src/gateway/server/health-state.ts, src/gateway/server-maintenance.ts, src/gateway/server.impl.ts
  • Known bad symptoms reviewers should watch for: Health snapshot including unexpected runtime fields

Risks and Mitigations

  • Risk: Runtime snapshot fields could conflict with snapshot fields set by buildChannelSummary
    • Mitigation: Runtime is spread first, then accountId, enabled, configured override it, maintaining the same priority as before

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime commands Command implementations size: XS labels Mar 11, 2026
@rstar327
rstar327 force-pushed the fix-health-endpoint-whatsapp-status branch from 01e398f to dc16f0a Compare March 11, 2026 00:24
@greptile-apps

greptile-apps Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a real bug where the health endpoint returned running: false, connected: false for channels while channels.status returned correct values. The fix threads the channel manager's getRuntimeSnapshot through startGatewayMaintenanceTimerssetRuntimeSnapshotFnrefreshGatewayHealthSnapshotgetHealthSnapshot, where runtime fields are spread before the overriding accountId/enabled/configured fields.

Core correctness: The merge order (...runtimeSnapshot, accountId, enabled, configured) is correct; authoritative health-check fields take precedence over runtime state. The implementation properly handles edge cases: CLI health command (runtime param is optional), channels without runtime entries (no spread applied). The spread operator safely merges runtime state without overwriting intended fields.

What changed:

  • getHealthSnapshot() now accepts optional runtime state and merges it into channel snapshots before buildChannelSummary
  • refreshGatewayHealthSnapshot calls runtimeSnapshotFn?.() to obtain runtime state and passes it through
  • setRuntimeSnapshotFn setter provides a way for startGatewayMaintenanceTimers to inject the runtime snapshot function
  • Gateway wires getRuntimeSnapshot from the channel manager through the maintenance timer setup

Confidence Score: 4/5

  • Safe to merge — core fix is correct and properly scoped; runtime state threading is secure and backward compatible.
  • The PR directly addresses the documented bug (health endpoint returning incorrect channel state). The fix properly merges runtime state via spread operator with field-override precedence to maintain intended behavior. Code handles edge cases correctly: optional runtime for CLI context, safe handling of missing runtime entries, consistent health-check field priority. No issues prevent merging.
  • No files require special attention.

Last reviewed commit: dc16f0a

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 27, 2026
@clawsweeper

clawsweeper Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Codex automated review: keeping this open.

Keep this PR open. Current main still lacks the runtime-state merge that this PR is trying to add, and the canonical maintainer repair remains open/unmerged with explicit maintainer guidance not to close duplicate or superseded PRs yet.

Best possible solution:

Keep this PR open while maintainer PR #72417 remains open and explicitly asks not to close duplicate or superseded PRs yet. The maintainer path is to review and land #72417 once clean and validated; otherwise, salvage this PR by rebasing it onto current main, threading runtime through the current gateway health refresh path, projecting only safe runtime fields, preserving probe behavior deliberately, and adding regression tests for health snapshots and gateway health refresh.

What I checked:

  • current_health_snapshot_has_no_runtime_input: On current main, getHealthSnapshot only accepts timeoutMs and probe; the channel account snapshot passed into plugin summary builders is built from config/probe fields and does not accept or merge channel runtime state. (src/commands/health.ts:363, 9bc703213bb3)
  • gateway_health_refresh_does_not_pass_runtime: The gateway health refresh path still calls getHealthSnapshot({ probe: opts?.probe }) directly, caches/broadcasts that result, and has no runtime callback or runtime snapshot projection. (src/gateway/server/health-state.ts:72, 9bc703213bb3)
  • channels_status_uses_runtime_state: The channels.status method reads context.getRuntimeSnapshot(), selects channel/account runtime entries, and passes runtime into buildChannelAccountSnapshot, confirming that status and health use different state sources today. (src/gateway/server-methods/channels.ts:161, 9bc703213bb3)
  • whatsapp_defaults_absent_runtime_to_false: WhatsApp's health summary builder reports running and connected as false when those fields are absent from the snapshot, so a live runtime state omitted from health can still produce the false-negative symptom described by the linked bug. (extensions/whatsapp/src/channel.ts:243, 9bc703213bb3)
  • canonical_maintainer_repair_open: Related maintainer PR fix(gateway): preserve runtime-backed health state #72417 is open, author-associated MEMBER, labeled maintainer, credits this PR's runtime snapshot plumbing approach, and explicitly says not to close duplicate or superseded PRs until that repair is pushed, review-clean, and validated. (2397a253a9ec)
  • pr_security_review_no_new_execution_surface_but_data_projection_risk: The PR diff only threads runtime state through health snapshot generation and gateway maintenance. It does not add dependencies, workflows, lifecycle scripts, downloaded artifacts, network calls, or secret-handling changes. The main review risk is functional/data exposure: it spreads a full ChannelAccountSnapshot into health summaries instead of projecting only safe runtime fields. (src/commands/health.ts:454, 2b5583255d02)

Remaining risk / open question:

  • This PR is stale against the current gateway startup path and likely needs a rebase before it can merge cleanly.
  • The current patch has no regression coverage for runtime-backed getHealthSnapshot or gateway health refresh behavior.
  • The PR spreads full runtime channel snapshots into health-summary input; a final fix should prefer a narrow, safe runtime projection so secret-bearing or unrelated snapshot fields cannot leak through plugin summaries.

Codex Review notes: model gpt-5.5, reasoning high; reviewed against 9bc703213bb3.

@vincentkoc vincentkoc added the clawsweeper Tracked by ClawSweeper automation label Apr 27, 2026
@vincentkoc

Copy link
Copy Markdown
Member

ProjectClownfish landed the canonical replacement in #72417, merged at be6263d.

Closing this as superseded by that merged fix. Your contribution was carried forward and credited in the changelog/source PR notes.

@vincentkoc vincentkoc closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper Tracked by ClawSweeper automation commands Command implementations gateway Gateway runtime size: XS stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: health endpoint returns incorrect running=false for WhatsApp

2 participants