Skip to content

improve(health): surface dead-lettered delivery queue entries - #99842

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
masatohoshino:fix/health-delivery-queue-dead-letter
Jul 6, 2026
Merged

vincentkoc merged 3 commits into
openclaw:mainfrom
masatohoshino:fix/health-delivery-queue-dead-letter

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Prompt request: Make openclaw health report deliveries that were dead-lettered by the durable delivery queue, so silent message loss becomes visible, while keeping the queue's enqueue, retry, and recovery behavior unchanged.

Proof target: Show that dead-lettered entries surface in the health snapshot (JSON field and warning line) and that a queue with only pending entries reports nothing.

What Problem This Solves

Resolves a problem where messages that permanently fail delivery are invisible to operators. When a delivery exhausts its retries, the durable delivery queue moves the entry to a failed status that is retained for diagnostics — but nothing ever reads those rows back: openclaw health stays all-green, and the only trace is a gateway log line at the moment it happened. An operator whose channel had an outage has no way to notice that messages were dropped.

Why This Change Was Made

The SQLite delivery queue already persists dead-lettered entries with a failed_at timestamp; the gap is purely read-side. This change adds a per-queue failed-count accessor to the storage layer and reports dead-lettered entries from getHealthSnapshot, the builder shared by the gateway health state and the openclaw health command. It follows the existing plugin and context-engine health section pattern: the deliveryQueues field is omitted when nothing is dead-lettered, a storage read failure degrades to omitting the section rather than failing health, and the text renderer adds one warning line. Because the gateway health handler can serve a cached snapshot for up to a refresh interval, the cached-response merge path recomputes the delivery queue summary the same way it already refreshes context-engine and model-pricing state, so a delivery that dead-letters right after the cache fills is still reported. Observer-only — no retry, purge, or queue behavior change.

User Impact

Operators now see dead-lettered deliveries in openclaw health: a JSON deliveryQueues.failed entry per queue (count plus oldest failure timestamp) and a text line such as Delivery queue: warning (dead-lettered entries — outbound: 2; oldest 2h ago). Healthy systems see no new output.

Evidence

Real-runtime capture using the production storage layer with no mocks (isolated OPENCLAW_STATE_DIR; three outbound deliveries enqueued via upsertDeliveryQueueEntry, two dead-lettered via moveDeliveryQueueEntryToFailed, then the real getHealthSnapshot):

Before (main):

[health-json] deliveryQueues=undefined (field absent)
PROOF: health shows nothing despite dead-lettered deliveries

After (this PR):

[health-json] deliveryQueues={"failed":[{"queueName":"outbound","count":2,"oldestFailedAt":1783143277568}]}
[health-text] Delivery queue: warning (dead-lettered entries — outbound: 2; oldest 2s ago)
PROOF: dead-lettered deliveries visible in health

The still-pending third delivery does not appear — only dead-lettered entries are reported.

Focused tests: src/infra/delivery-queue-sqlite.test.ts — an empty queue returns no counts; dead-lettered entries are counted per queue with exact oldest-failure timestamps (fake timers) while pending entries stay excluded. src/commands/health.snapshot.test.ts — the built health snapshot omits the field for a clean queue and reports the dead-lettered entry against an isolated state dir. src/commands/health.test.ts — openclaw health renders the warning line from a gateway summary, and the formatter returns null when nothing is dead-lettered. src/gateway/server-methods/server-methods.test.ts — a cached gateway health response reports a delivery dead-lettered after the cache was filled. The new assertions fail without the change.

Deliveries that exhaust retries are moved to the failed status in the
SQLite delivery queue for diagnostics, but no health surface ever read
them back: openclaw health stayed all-green while messages sat
dead-lettered, visible only in gateway logs. Add a per-queue failed
count accessor and report dead-lettered entries in the health snapshot
(JSON field plus a warning line), following the existing plugin and
context-engine health section pattern. Observer-only: no retry, purge,
or behavior change.
Add getHealthSnapshot coverage against an isolated state dir, an
openclaw health text-output test for the warning line, exact
oldest-failure timestamp assertions via fake timers, and a debug log
when the delivery-queue health read fails.
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: M labels Jul 4, 2026
@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 4, 2026, 2:40 AM ET / 06:40 UTC.

Summary
Adds a failed delivery queue aggregate, exposes optional deliveryQueues.failed in gateway health JSON/text output, refreshes it for cached health responses, and covers fresh and cached paths in tests.

PR surface: Source +104, Tests +212. Total +316 across 8 files.

Reproducibility: yes. source-reproducible. Current main persists failed delivery queue rows with failed_at but has no deliveryQueues health field; the PR body also shows before/after terminal output for the same path.

Review metrics: 1 noteworthy metric.

  • Health payload surface: 1 optional field added. deliveryQueues is an additive gateway health JSON field that operators or integrations may start consuming.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Next step before merge

  • No automated repair job is indicated; the prior cached-health blocker is addressed and the remaining action is ordinary maintainer review and CI gating.

Security
Cleared: Cleared: the diff adds a read-only SQLite aggregate and health output formatting; it does not change secrets, auth, dependencies, CI, or code execution paths.

Review details

Best possible solution:

Land the additive read-only health diagnostic after ordinary maintainer review and CI, keeping enqueue, retry, purge, and recovery behavior unchanged.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible. Current main persists failed delivery queue rows with failed_at but has no deliveryQueues health field; the PR body also shows before/after terminal output for the same path.

Is this the best way to solve the issue?

Yes. Reusing the existing SQLite queue state and shared health snapshot is the narrow maintainable path, and the latest commit now covers the cached gateway response path that normal openclaw health uses.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cafbd745c1b1.

Label changes

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Sufficient: the PR body includes before/after terminal output from a real production-storage path with an isolated state directory showing the changed health result.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The PR improves operator visibility into retained failed deliveries with limited runtime blast radius and no queue behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Sufficient: the PR body includes before/after terminal output from a real production-storage path with an isolated state directory showing the changed health result.
  • proof: sufficient: Contributor real behavior proof is sufficient. Sufficient: the PR body includes before/after terminal output from a real production-storage path with an isolated state directory showing the changed health result.
Evidence reviewed

PR surface:

Source +104, Tests +212. Total +316 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 105 1 +104
Tests 4 213 1 +212
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 318 2 +316

What I checked:

  • Current main stores dead-lettered queue rows but has no health payload field: Current main marks pending delivery queue entries as failed with failed_at, while HealthSummary has channels/plugins/context/model-pricing fields but no delivery queue section. (src/infra/delivery-queue-sqlite.ts:245, cafbd745c1b1)
  • PR adds the read-side failed-count query: The PR head adds countFailedDeliveryQueueEntries, a Kysely aggregate over delivery_queue_entries grouped by queue name and filtered to status = failed. (src/infra/delivery-queue-sqlite.ts:253, cb9bc66e52e4)
  • PR wires the new summary into fresh health snapshots and text output: The PR head builds an optional delivery queue health summary, includes it in getHealthSnapshot, and renders a warning line only when failed rows exist. (src/commands/health.ts:248, cb9bc66e52e4)
  • Cached gateway health path is covered after the latest commit: The latest PR head drops cached deliveryQueues, recomputes the cheap live summary before returning cached health, and adds a cached-handler regression test. (src/gateway/server-methods/health.ts:96, cb9bc66e52e4)
  • Contributor proof is real terminal output: The PR body includes before/after terminal output using the production storage layer with an isolated state directory: current main omits deliveryQueues, while the PR reports failed rows and a text warning. (cb9bc66e52e4)
  • Related-search pass found no canonical replacement: Live GitHub title/body search for dead-letter delivery queue health found adjacent closed message-delivery work, but no open canonical issue or PR replacing this health diagnostic change.

Likely related people:

  • RomneyDa: Current blame for the delivery queue SQLite module and gateway health handler in this checkout points to the recent merged repository/import commit associated with fix: avoid native command QA timeout under CI contention #99743. (role: recent area contributor and merger; confidence: medium; commits: 13652f6654da; files: src/infra/delivery-queue-sqlite.ts, src/gateway/server-methods/health.ts, src/commands/health.ts)
  • steipete: Bounded git log -G history for health summary and gateway health surfaces includes multiple earlier commits by Peter Steinberger, including the original CLI health command and later command/gateway health refactors. (role: health command and gateway health history contributor; confidence: medium; commits: 2714ed503b21, 3c4c2aa98cfc, f14d622c0f64; files: src/commands/health.ts, src/gateway/server-methods/health.ts)
  • vincentkoc: Bounded health-surface history includes adjacent context/model-pricing health and type-surface work by Vincent Koc, making him a useful routing candidate for the added health payload shape. (role: adjacent health surface contributor; confidence: low; commits: 74e7b8d47b18, e085fa1a3ffd; files: src/commands/health.ts, src/commands/health.types.ts, src/gateway/server-methods/health.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. labels Jul 4, 2026
The gateway health handler can serve a cached snapshot for up to a
refresh interval, so a delivery dead-lettered after the cache was
filled stayed hidden from openclaw health. Recompute the delivery
queue summary in mergeCachedHealthRuntimeState alongside the existing
context-engine and model-pricing live merges, and cover the cached
handler path with a regression test.
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Jul 4, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 4, 2026
@vincentkoc
vincentkoc merged commit ef1c832 into openclaw:main Jul 6, 2026
128 of 135 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 7, 2026
…aw#99842)

* improve(health): surface dead-lettered delivery queue entries

Deliveries that exhaust retries are moved to the failed status in the
SQLite delivery queue for diagnostics, but no health surface ever read
them back: openclaw health stayed all-green while messages sat
dead-lettered, visible only in gateway logs. Add a per-queue failed
count accessor and report dead-lettered entries in the health snapshot
(JSON field plus a warning line), following the existing plugin and
context-engine health section pattern. Observer-only: no retry, purge,
or behavior change.

* test(health): cover snapshot and CLI dead-letter reporting

Add getHealthSnapshot coverage against an isolated state dir, an
openclaw health text-output test for the warning line, exact
oldest-failure timestamp assertions via fake timers, and a debug log
when the delivery-queue health read fails.

* fix(health): recompute dead-letter counts for cached gateway responses

The gateway health handler can serve a cached snapshot for up to a
refresh interval, so a delivery dead-lettered after the cache was
filled stayed hidden from openclaw health. Recompute the delivery
queue summary in mergeCachedHealthRuntimeState alongside the existing
context-engine and model-pricing live merges, and cover the cached
handler path with a regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants