Skip to content

fix(diagnostics): preserve telemetry during service shutdown - #119705

Merged
vincentkoc merged 4 commits into
mainfrom
fix/otel-service-lifecycle-20260805
Aug 5, 2026
Merged

vincentkoc merged 4 commits into
mainfrom
fix/otel-service-lifecycle-20260805

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #119694

What Problem This Solves

The diagnostics OTEL service could detach exporters before other plugin services finished emitting their final queued diagnostics. Its own exporter cleanup failures were also swallowed, so shutdown and reload could appear successful after telemetry cleanup failed.

Why This Change Was Made

  • Stop ordinary diagnostic producers before services that receive the trusted internalDiagnostics capability.
  • Drain the diagnostics queue snapshot before stopping those trusted diagnostics exporters.
  • Preserve existing warn-and-continue behavior for ordinary plugin service stop failures.
  • Attempt every trusted diagnostics exporter stop and propagate only those exporter failures.
  • Attempt every OTEL cleanup step and report one failure or an AggregateError.
  • Reject diagnostics-otel startup before provider construction when the required capability is unavailable.

The generic plugin-service lifecycle owns producer/exporter ordering and trusted exporter failure propagation. The diagnostics-otel service owns provider cleanup. No gateway recovery behavior, config, protocol, endpoint, storage, or payload contract changes are included.

User Impact

Final diagnostics emitted during shutdown or reload are delivered before OTEL listeners detach. Ordinary plugin stop failures still warn and continue, while a trusted diagnostics exporter cleanup failure reaches the existing host lifecycle handling after all service stops have run.

Verification

  • node scripts/run-vitest.mjs extensions/diagnostics-otel/src/service.test.ts src/infra/diagnostic-events.test.ts src/plugins/services.test.ts: 200 passed
  • Tests prove an ordinary producer stop failure does not reject, a trusted diagnostics exporter stop failure does reject, every stop still runs, and producer -> drain -> exporter ordering remains intact
  • node_modules/.bin/oxfmt --check on all six changed files: passed
  • Path-scoped node_modules/.bin/oxlint on the compatibility fix: passed
  • git diff --check origin/main...HEAD: passed
  • Exact-head branch autoreview at 4b7d6fec9fd5b924df34588231a6c38ea8cbb3d8: clean, no P0-P2 findings
  • AWS Crabbox run_5574cea54e2a at 4b7d6fec9fd5b924df34588231a6c38ea8cbb3d8: 291 tests passed, including real OTLP exporter and sibling one-shot lifecycle coverage
  • pnpm qa:otel:smoke -- --collector local --logs-exporter both: passed with 5 spans, 6 metrics, one OTLP log, one stdout log, and one request for each OTLP signal
  • pnpm check:test-types, pnpm tsgo:scripts, and pnpm tsgo:test:root: passed on the exact PR head

Production delta: +63/-17, net +46. Test delta: +190/-7, net +183.

@vincentkoc vincentkoc self-assigned this Aug 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added extensions: diagnostics-otel Extension: diagnostics-otel size: M maintainer Maintainer-authored PR labels Aug 5, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 5, 2026 18:38
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 8d2ea0c2c94866cbe675199cd2a414a6425f1cab. The previous review placeholders reference stale heads.

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

Exact-head ClawSweeper review completed for 8d2ea0c2c94866cbe675199cd2a414a6425f1cab, but its public comment publisher is still queued.

Blocking P1: src/plugins/services.ts:247-260 now aggregates every service stop error. That changes the host-wide contract from warn-and-continue to rejecting hot reload and scheduling gateway recovery when any unrelated plugin cleanup fails.

Required resolution before merge:

  • retain warn-and-continue for ordinary plugin stop failures and propagate only the diagnostics exporter failure this PR owns; or
  • explicitly approve the host-wide behavior change and add gateway reload/close recovery proof.

This blocks dependent protocol PR #119708 until this PR has a clean exact-head review and merges.

Review run: https://github.com/openclaw/clawsweeper/actions/runs/31037516000

@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. labels Aug 5, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 4b7d6fec9fd5b924df34588231a6c38ea8cbb3d8.

The ordinary plugin stop compatibility finding is addressed: ordinary failures remain warn-and-continue; only trusted diagnostics exporter failures propagate. Focused tests prove all stops still run and producer -> drain -> exporter ordering remains intact. Fresh exact-head local autoreview and AWS OTEL proof are in the PR body.

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added the P2 Normal backlog priority with limited blast radius. label Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 3:35 PM ET / 19:35 UTC.

ClawSweeper review

What this changes

The PR drains diagnostics queued during plugin shutdown before OpenTelemetry exporters detach, checks exporter capability before startup, and reports exporter cleanup failures to the host.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open: the final head fixes the prior host-wide error-propagation concern by preserving ordinary plugin stop warnings while propagating only trusted diagnostics-exporter failures. This maintainer-authored, protected PR still needs the normal exact-head CI/approval path.

Priority: P2
Reviewed head: 4b7d6fec9fd5b924df34588231a6c38ea8cbb3d8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The final head is a focused, source-backed repair with targeted regression coverage and no actionable correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its reported OTLP smoke evidence remains useful supplemental validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its reported OTLP smoke evidence remains useful supplemental validation.
Evidence reviewed 7 items Current-main failure contract: Current main warns and continues for every plugin stop error, so a generic propagate-all change would affect gateway reload behavior.
Final-head lifecycle scope: The final head stops ordinary services first, drains queued diagnostics, and collects failures only from services granted the trusted diagnostics capability.
Regression coverage: Exact-head tests prove ordinary stop failures still resolve after warnings and separately prove producer event delivery before the exporter failure is surfaced.
Findings None None.
Security None None.

How this fits together

Plugin services host diagnostics producers and exporter plugins. During shutdown, producers feed an asynchronous diagnostics queue, which OpenTelemetry and Prometheus exporters consume before the gateway closes or reloads.

flowchart LR
  A[Plugin services] --> B[Diagnostics producers]
  B --> C[Async diagnostics queue]
  C --> D[Trusted exporter plugins]
  D --> E[OpenTelemetry providers]
  A --> F[Gateway shutdown or reload]
  F --> B
  F --> D
Loading

Before merge

  • Complete next step (P2) - No repair job is warranted: the final head resolves the prior lifecycle blocker, leaving normal exact-head CI and maintainer approval.
Agent review details

Security

None.

PR surface

Source +46, Tests +183. Total +229 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 63 17 +46
Tests 3 190 7 +183
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 253 24 +229

Review metrics

Metric Value Why it matters
Production vs test LOC production +63/-17 (net +46), tests +190/-7 (net +183) The production growth implements the explicit lifecycle ownership boundary; the larger test delta covers ordering, drain, denied-start, and failure behavior.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #119694
Summary: This PR is the focused candidate repair for the diagnostics shutdown issue; the other linked diagnostics PRs address distinct behavior.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Land the narrow lifecycle-owner repair after exact-head CI confirms the final commit, retaining warn-and-continue behavior for ordinary plugin cleanup and diagnostics-only error propagation.

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

Yes: current main’s reverse-only service shutdown and swallowed cleanup errors establish the affected path, and the exact-head regression tests encode the producer-to-exporter shutdown sequence.

Is this the best way to solve the issue?

Yes: the final head repairs ordering at the generic lifecycle owner while keeping provider cleanup and capability admission inside the diagnostics plugin, rather than changing the host-wide stop contract.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The PR repairs bounded diagnostics delivery and cleanup observability during shutdown and reload.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its reported OTLP smoke evidence remains useful supplemental validation.

Label justifications:

  • P2: The PR repairs bounded diagnostics delivery and cleanup observability during shutdown and reload.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its reported OTLP smoke evidence remains useful supplemental validation.

Evidence

What I checked:

  • Current-main failure contract: Current main warns and continues for every plugin stop error, so a generic propagate-all change would affect gateway reload behavior. (src/plugins/services.ts:177, d6233c29b904)
  • Final-head lifecycle scope: The final head stops ordinary services first, drains queued diagnostics, and collects failures only from services granted the trusted diagnostics capability. (src/plugins/services.ts:242, 4b7d6fec9fd5)
  • Regression coverage: Exact-head tests prove ordinary stop failures still resolve after warnings and separately prove producer event delivery before the exporter failure is surfaced. (src/plugins/services.test.ts:559, 4b7d6fec9fd5)
  • Exporter ownership: The OTEL service all-settles independent cleanup actions and checks the internal diagnostics capability before constructing providers. (extensions/diagnostics-otel/src/service.ts:70, 4b7d6fec9fd5)
  • Gateway consumer behavior: Gateway shutdown catches rejected plugin-service disposal, logs it, records a shutdown warning, and continues later cleanup; runtime replacement awaits the handle so exporter failures remain observable. (src/gateway/server-close.ts:582, d6233c29b904)
  • Lifecycle provenance: History identifies a recent plugin-service lifecycle refactor by Peter Steinberger; the current-main implementation was later carried in the merge-sync commit. (src/plugins/services.ts:166, c52bc5374525)

Likely related people:

  • Peter Steinberger: History shows major recent work on plugin service lifecycle and diagnostics service orchestration. (role: recent plugin-service lifecycle contributor; confidence: high; commits: c52bc5374525, 6454b07b1701; files: src/plugins/services.ts, extensions/diagnostics-otel/src/service.ts)
  • vincentkoc: History shows repeated diagnostics-OTEL and async-event work in addition to the current focused lifecycle repair. (role: diagnostics area contributor; confidence: high; commits: 4b7d6fec9fd5; files: src/infra/diagnostic-events.ts, extensions/diagnostics-otel/src/service.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the required exact-head CI complete before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

@vincentkoc
vincentkoc merged commit 880dde9 into main Aug 5, 2026
131 checks passed
@vincentkoc
vincentkoc deleted the fix/otel-service-lifecycle-20260805 branch August 5, 2026 19:58
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 5, 2026
…cope

* origin/main:
  fix(qa): report cleanup failures truthfully (openclaw#119727)
  fix: keep completed actions visible after settled finalization (openclaw#119726)
  fix(agents): rearm yielded requester wake (openclaw#119696)
  fix(diagnostics): preserve telemetry during service shutdown (openclaw#119705)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
…w#119705)

* fix(diagnostics): preserve otel service shutdown lifecycle

* test(diagnostics): type OTEL unsubscribe callback

* test(diagnostics): normalize async stop assertion

* fix(plugins): preserve ordinary stop handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: diagnostics-otel Extension: diagnostics-otel maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

[Bug]: diagnostics-otel lifecycle can drop queued telemetry and hide shutdown failures

1 participant