Skip to content

fix(diagnostics-prometheus): send Content-Length on metrics HEAD responses - #120212

Merged
steipete merged 2 commits into
openclaw:mainfrom
zenglingbiao:fix/prometheus-head-content-length
Aug 8, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
zenglingbiao:fix/prometheus-head-content-length

Conversation

@zenglingbiao

@zenglingbiao zenglingbiao commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where HEAD /api/diagnostics/prometheus omitted the representation length even though the equivalent GET returned a fully rendered metrics body.

HTTP permits Content-Length on a HEAD response. When present, its value must match the octet count that the corresponding GET response would send.

Why This Change Was Made

The metrics handler already materializes the canonical Prometheus text before it branches on the request method. It now records Buffer.byteLength(body) once for both GET and HEAD, while preserving the existing empty HEAD body.

The regression uses the existing diagnostics listener to record a real non-empty metric, then serves the real handler over a loopback HTTP server. It verifies:

  • GET returns a non-empty body and a byte-accurate Content-Length.
  • HEAD returns the same Content-Length.
  • HEAD returns no body bytes.
  • Server shutdown is awaited so the test cannot leak a listener.

No auth, routing, cache, content type, config, SDK, or plugin contract changes.

User Impact

Monitoring clients that probe the Prometheus endpoint with HEAD now receive accurate representation metadata without downloading the metrics body. GET behavior and body bytes are unchanged.

Evidence

  • Current-main loopback reproduction: GET returned 2972 bytes with Content-Length: 2972; HEAD returned no Content-Length and zero body bytes.
  • Rewritten-head loopback proof: GET and HEAD both returned Content-Length: 2972; HEAD returned zero body bytes.
  • Focused owner suite: 21/21 passed.
  • Focused regression: 20/20 repeated runs passed.
  • Targeted formatting and git diff --check: passed.
  • Local ClawSweeper on patch-identical tree ddb4fcc2877d57503214f57c71423a951bef4419: complete, high confidence, no actionable P0/P1 findings, no rank-up moves.
  • Max-P1 autoreview: clean, patch correct with 0.99 confidence.

Production delta: +1 line. Test delta: +53 lines.

Punchcard-Session: ember-willow-timber-gk

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 7, 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 commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 7:39 PM ET / 23:39 UTC.

ClawSweeper review

What this changes

The PR adds a byte-accurate Content-Length header to the Prometheus metrics endpoint so HEAD returns the same representation length as GET without returning metrics bytes.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still omits Content-Length on the Prometheus HEAD response, and this active, assigned PR supplies the narrow plugin-owned repair with suitable loopback proof and no blocking review finding.

Priority: P2
Reviewed head: d5338b68b9aac27a8f0a6b862c420cb0c073f189

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrowly scoped owner-boundary fix with direct before/after loopback evidence and focused regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body records before/after loopback requests through the real handler, showing matching GET/HEAD lengths and a zero-byte HEAD body; the regression test exercises the same boundary.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body records before/after loopback requests through the real handler, showing matching GET/HEAD lengths and a zero-byte HEAD body; the regression test exercises the same boundary.
Evidence reviewed 5 items Current main still lacks HEAD length metadata: The handler renders the metrics representation and sets cache/content-type headers, but its HEAD branch ends the response before a Content-Length header is set.
Patch changes the owning response boundary: The PR adds Buffer.byteLength(body) as Content-Length before the shared GET/HEAD split, preserving the empty HEAD body and GET content.
Route reaches the plugin handler: The plugin registers the authenticated Prometheus route, and gateway plugin HTTP dispatch invokes its handler; this is live route ownership rather than a test-only seam.
Findings None None.
Security None None.

How this fits together

The diagnostics-prometheus plugin converts OpenClaw diagnostic events into Prometheus text and serves it at an authenticated gateway HTTP route. Monitoring probes use GET or HEAD on that route, then consume the response body or its metadata.

flowchart LR
  A[Diagnostic events] --> B[Prometheus metric store]
  B --> C[Metrics HTTP route]
  C --> D{Request method}
  D -->|GET| E[Metrics body and headers]
  D -->|HEAD| F[Matching headers and empty body]
  E --> G[Monitoring client]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind main; before landing, confirm the clean three-way merge and required checks on the exact head.
  • Complete next step (P2) - This active assigned PR already contains the correct bounded repair and needs normal maintainer merge review rather than a separate repair job.
Agent review details

Security

None.

PR surface

Source +1, Tests +53. Total +54 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 0 +1
Tests 1 53 0 +53
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 54 0 +54

Review metrics

Metric Value Why it matters
Production versus test delta production +1, tests +53 The single production header aligns response framing at the owner boundary, while the added loopback test covers GET/HEAD byte parity and teardown.

Stored data model

Persistent data-model change detected: vector/embedding metadata: extensions/diagnostics-prometheus/src/service.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the plugin-local header calculation after exact-head merge and CI confirmation, retaining GET bytes and the empty HEAD body.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the plugin-local header calculation after exact-head merge and CI confirmation, retaining GET bytes and the empty HEAD body.

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

Yes. A loopback Node HTTP server around the real registered handler can reproduce the current-main asymmetry: GET has a body-derived length while HEAD ends without that header.

Is this the best way to solve the issue?

Yes. Computing the length once from the already-rendered representation at the plugin handler is narrower and safer than altering gateway-wide framing behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This corrects monitoring metadata on one optional diagnostics endpoint without affecting message delivery, auth, or stored state.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records before/after loopback requests through the real handler, showing matching GET/HEAD lengths and a zero-byte HEAD body; the regression test exercises the same boundary.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records before/after loopback requests through the real handler, showing matching GET/HEAD lengths and a zero-byte HEAD body; the regression test exercises the same boundary.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Current handler lines blame to Vincent Koc, who also authored the original protected metrics-exporter feature and the PR’s proof-hardening commit. (role: feature owner and recent area contributor; confidence: high; commits: e455cafa1386, 0f2e7510cbda; files: extensions/diagnostics-prometheus/src/service.ts, extensions/diagnostics-prometheus/index.ts)
  • huangjianxiong: Authored a recent diagnostics-prometheus repair in the same service module. (role: recent plugin-specific contributor; confidence: medium; commits: fae5421; files: extensions/diagnostics-prometheus/src/service.ts)
  • Peter Steinberger: Authored the recent diagnostics refactor that touched this plugin area. (role: recent adjacent refactor contributor; confidence: medium; commits: 525db34; files: extensions/diagnostics-prometheus/src/service.ts)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-07T12:38:18.249Z sha afea68102155e544e04ab0dcc2dbb0a2aec980e4 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. labels Aug 7, 2026
@steipete
steipete force-pushed the fix/prometheus-head-content-length branch from afea681 to d5338b6 Compare August 8, 2026 22:53
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 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 rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 8, 2026
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper rank-up moves are resolved for exact head d5338b68b9aac27a8f0a6b862c420cb0c073f189:

  • Exact-head CI completed successfully with no failed checks (run 31282726709).
  • The native hosted prepare gate completed successfully on the same head.
  • The maintainer merge review found no correctness, security, routing, or ownership concern.
  • No additional rebase was performed solely for unrelated current-main movement: GitHub reports the PR mergeable, and current main has no intervening changes in the two touched plugin files.

No ClawSweeper finding or repair remains.

@steipete
steipete merged commit 2289d96 into openclaw:main Aug 8, 2026
89 checks passed
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 9, 2026
Punchcard-Session: amber-workshop-workshop-36

* origin/main: (28 commits)
  perf(doctor): keep bundled doctor contract closures dependency-light (#120698)
  fix(elevenlabs): preserve repeated committed speech segments (#120792)
  fix(ai): fence Responses replay metadata (#120777)
  fix(ai): invalidate stale compaction replay (#120786)
  fix(telegram): clean up every failed webhook startup phase (#120788)
  fix(codex): preserve configured MCP tools in scheduled turns (#120366)
  fix(ui): show dev checkout commit lag in Updates (#120769)
  fix(agents): repair XML-polluted tool names (#113814)
  fix(discord): remove only the bot own reactions (#120785)
  fix(macos): complete ChatGPT subscription setup (#120782)
  fix(plugins): surface safe administrator install warnings (#120783)
  fix(release): keep upgrade survivor sessions fresh (#120778)
  fix(providers): preserve realtime tool-result delivery ownership (#120776)
  fix(plugins): retain incognito scope for embedded session ownership (#120215)
  fix(elevenlabs): surface realtime provider error events (#120772)
  fix(agents): preserve exact steering delivery ownership (#120770)
  fix(telegram): prevent session-count routing slowdown (#120774)
  fix(agents): preserve authoritative background process outcomes (#120754)
  test(process): make Linux adapter wiring portable (#120741)
  fix(diagnostics-prometheus): send Content-Length on metrics HEAD responses (#120212)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 9, 2026
…onses (openclaw#120212)

* fix(diagnostics-prometheus): send Content-Length on metrics HEAD responses

* fix(diagnostics-prometheus): harden HEAD metadata proof

Punchcard-Session: ember-willow-timber-gk

Co-authored-by: zenglingbiao <[email protected]>

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: diagnostics-prometheus P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

3 participants