Skip to content

fix(gateway): send Content-Length on MCP App standalone HEAD responses - #120905

Merged
steipete merged 1 commit into
openclaw:mainfrom
zenglingbiao:fix/mcp-app-standalone-head-content-length
Aug 25, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
zenglingbiao:fix/mcp-app-standalone-head-content-length

Conversation

@zenglingbiao

@zenglingbiao zenglingbiao commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix GET/HEAD representation metadata for the opt-in standalone MCP App host (mcp.apps.enabled === true). The public shell, authenticated view, unauthorized ticket challenge, and active-view-limit response now advertise the exact UTF-8 byte length of their corresponding GET representation while HEAD sends no response body.

Problem and root cause

Node suppresses HEAD response bodies but does not synthesize Content-Length for them. The standalone host built HTML, JSON, and plain-text responses through separate paths, so all four HEAD responses omitted useful representation-size metadata even though their GET equivalents exposed it. RFC 9110 permits omitting Content-Length; when supplied on HEAD, its value must match the corresponding GET representation. This change restores interoperability and GET/HEAD parity; it does not claim the previous responses violated the RFC.

Fix and scope

  • Reuse the existing canonical respondPlainText implementation for standalone 401/404/503 responses and remove the duplicated local plain-text responder.
  • Set the bounded shell HTML byte length explicitly, and use one small owner-local JSON representation responder for authorized view metadata and active-view-limit 429 responses.
  • Serialize each JSON representation once and calculate its size with Buffer.byteLength, including multibyte HTML and tool payloads.
  • Preserve ticket authorization, WWW-Authenticate, Vary: Authorization, CSP, cache policy, active-view leases and concurrency limits, POST behavior, the browser's initial-load timeout, and the existing operation-timeout grace projection.
  • Keep global Gateway response helpers, public configuration, protocol, and persistence unchanged. Production delta: +35/-34 (net +1); the extra line implements the previously absent representation-size contract.

Real HTTP proof

The focused regression starts a real ephemeral localhost HTTP server, invokes handleMcpAppStandaloneHttpRequest, and sends real fetch GET and HEAD requests. On unmodified current main, all four new cases failed because the HEAD Content-Length was absent:

shell 200: expected 8890, received null
authenticated multibyte view 200: expected 371, received null
unauthorized ticket challenge 401: expected 12, received null
saturated active-view 429: expected 64, received null
Tests: 4 failed, 12 passed

After the fix, every route has identical GET/HEAD status and UTF-8 byte length, HEAD has an empty body, authorization/challenge/Vary and cache headers remain intact, and the authenticated representation still contains the current 65-second operation timeout:

node scripts/run-vitest.mjs \
  src/gateway/mcp-app-standalone.test.ts \
  src/gateway/mcp-app-sandbox-http.test.ts \
  src/gateway/board-http.test.ts
Test Files  3 passed (3)
     Tests  36 passed (36)

Formatting and a fresh independent Codex autoreview both passed without actionable findings. Contributor credit is preserved for @zenglingbiao.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Aug 9, 2026
@zenglingbiao
zenglingbiao force-pushed the fix/mcp-app-standalone-head-content-length branch from bb4a514 to 7f86406 Compare August 9, 2026 05:07
@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 Aug 9, 2026
@zenglingbiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the previous review run appears to have stalled at the status placeholder (lease expired without a durable review). Re-queueing. HEAD 7f86406d58d.

@clawsweeper

clawsweeper Bot commented Aug 9, 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: 🐚 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 Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 4:38 AM ET / 08:38 UTC.

ClawSweeper review

What this changes

The PR makes standalone MCP App GET and HEAD responses expose matching UTF-8 Content-Length metadata while HEAD remains bodyless.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this PR open: current main still omits the standalone host’s HEAD representation lengths, while this refreshed branch applies the existing sibling pattern with focused real-HTTP coverage. No actionable correctness or security finding was identified.

Priority: P2
Reviewed head: 26c5fdf7c892e82ea85b644422e99b75ad816a04

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused repair has credible boundary-level HTTP proof and no confirmed correctness or security defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR provides after-fix localhost HTTP output, and its added regression runs the real handler through an ephemeral server and real fetch GET/HEAD clients.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR provides after-fix localhost HTTP output, and its added regression runs the real handler through an ephemeral server and real fetch GET/HEAD clients.
Evidence reviewed 6 items Current-main gap: Current main has HEAD branches that end the shell and JSON responses without first recording representation length; its local text helper also omits Content-Length.
Owner-boundary repair: The PR serializes each JSON representation once, records byte length, and suppresses only the HEAD body; HTML receives the same explicit metadata and text errors use the canonical responder.
Boundary-level regression coverage: The added table runs the real handler behind an ephemeral localhost HTTP server and compares GET/HEAD status, byte length, body suppression, authorization metadata, and a multibyte payload.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/mcp-app-standalone.test.ts src/gateway/mcp-app-sandbox-http.test.ts src/gateway/board-http.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs src/gateway/mcp-app-standalone.test.ts src/gateway/mcp-app-sandbox-http.test.ts src/gateway/board-http.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-120905-kkO8T9/target$ node scripts/run-vitest.mjs src/gateway/mcp-app-standalone.test.ts src/gateway/mcp-app-sa
ndbox-http.test.ts src/gateway/board-http.test.ts
node scripts/run-vitest.mjs src/gateway/mcp-app-standalone.test.ts src/gateway/mcp-app-sandbox-http.test.ts src/gateway/board-http.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-120905-kkO8T9/target

 ✓  gateway-core  ../../src/gateway/mcp-app-sandbox-http.test.ts (6 tests) 226ms
 ✓  gateway-core  ../../src/gateway/board-http.test.ts (14 tests) 630ms
 ✓  gateway-core  ../../src/gateway/mcp-app-standalone.test.ts (16 tests) 277ms

 Test Files  3 passed (3)
      Tests  36 passed (36)
   Start at  08:39:10
   Duration  11.22s (transform 15.57s, setup 3.65s, import 16.13s, tests 1.13s, environment 0ms)

[test] passed 1 Vitest shard in 17.59s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-120905-kkO8T9/target$ node scripts/run-vitest.mjs src/gateway/mcp-app-standalone.test.ts src/gateway/mcp-app-sa
ndbox-http.test.ts src/gateway/board-http.test.ts































Assertions:

  • PASS expect_output: Test Files

How this fits together

The Gateway’s opt-in standalone MCP App host serves a shell and authenticated app-view responses over HTTP. Browser and MCP App clients enter through the host handler, which authorizes requests and returns HTML, JSON, or plain-text representations.

flowchart LR
  Client[Browser or MCP App client] --> Request[Standalone HTTP request]
  Request --> Route[Host routing and authorization]
  Route --> Representation[HTML JSON or text representation]
  Representation --> Headers[Response metadata]
  Headers --> Output[GET body or bodyless HEAD response]
Loading

Before merge

  • Complete next step (P2) - The contributor PR already owns the bounded repair; wait for the queued exact-head checks, then complete normal maintainer merge review.
Agent review details

Security

None.

PR surface

Source +1, Tests +79. Total +80 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 35 34 +1
Tests 1 80 1 +79
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 115 35 +80

Review metrics

Metric Value Why it matters
Production vs test LOC production +1 net (+35/-34); tests +79 net (+80/-1) The production change consolidates response construction around explicit representation length, while the test growth covers four real HTTP GET/HEAD parity cases.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/mcp-app-standalone.ts, vector/embedding metadata: src/gateway/mcp-app-standalone.test.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Merge the owner-local representation serializer and canonical plain-text reuse after exact-head CI confirms the refreshed branch.

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

Yes—source-reproducible with high confidence: current main suppresses HEAD bodies before setting a representation length, and the PR’s localhost HTTP regression directly exercises those paths.

Is this the best way to solve the issue?

Yes—the response owner is the narrowest place to serialize once and attach matching metadata, consistent with the existing sandbox and board HTTP handlers.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs metadata parity for an opt-in Gateway HTTP surface without evidence of broader availability or security impact.
  • 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): The PR provides after-fix localhost HTTP output, and its added regression runs the real handler through an ephemeral server and real fetch GET/HEAD clients.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides after-fix localhost HTTP output, and its added regression runs the real handler through an ephemeral server and real fetch GET/HEAD clients.

Evidence

What I checked:

  • Current-main gap: Current main has HEAD branches that end the shell and JSON responses without first recording representation length; its local text helper also omits Content-Length. (src/gateway/mcp-app-standalone.ts:630, 5b5fdacfdaa8)
  • Owner-boundary repair: The PR serializes each JSON representation once, records byte length, and suppresses only the HEAD body; HTML receives the same explicit metadata and text errors use the canonical responder. (src/gateway/mcp-app-standalone.ts:214, 26c5fdf7c892)
  • Boundary-level regression coverage: The added table runs the real handler behind an ephemeral localhost HTTP server and compares GET/HEAD status, byte length, body suppression, authorization metadata, and a multibyte payload. (src/gateway/mcp-app-standalone.test.ts:225, 26c5fdf7c892)
  • Production entry point: The Gateway dispatches these routes only when MCP Apps are enabled, then invokes the standalone handler under Gateway HTTP work admission. (src/gateway/server-http.ts:515, 26c5fdf7c892)
  • Sibling invariant: The merged sandbox host already records UTF-8 Content-Length and suppresses only the HEAD body, matching this PR’s representation-level approach. (src/gateway/mcp-app-sandbox-http.ts:49, 26c5fdf7c892)
  • Feature history: Current-main blame attributes the existing standalone response construction to recent gateway work by Peter Steinberger; this PR head preserves that newer timeout projection while changing only response metadata. (src/gateway/mcp-app-standalone.ts:213, 041d48eccbc5)

Likely related people:

  • Peter Steinberger: Current-main blame ties the existing standalone response construction to his recent gateway work, and he authored the refreshed head. (role: recent area contributor; confidence: high; commits: 041d48eccbc5, 26c5fdf7c892; files: src/gateway/mcp-app-standalone.ts, src/gateway/mcp-app-standalone.test.ts)
  • zenglingbiao: Authored the merged sandbox-host GET/HEAD metadata repair that establishes the closest sibling pattern. (role: adjacent response-metadata contributor; confidence: medium; commits: b121219a446e; files: src/gateway/mcp-app-sandbox-http.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 (5 earlier review cycles)
  • reviewed 2026-08-09T06:39:23.021Z sha 7f86406d58d5a14ff3962f0a38d6e5e7173fb256 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-09T06:45:41.169Z sha 7f86406d58d5a14ff3962f0a38d6e5e7173fb256 :: needs changes before merge. :: [P2] Route the active-view 429 through the HEAD responder
  • reviewed 2026-08-09T07:43:40.335Z sha dfc4fcc5435d4e633f062551953519580ceac764 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-09T07:51:17.021Z sha dfc4fcc5435d4e633f062551953519580ceac764 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-21T13:16:40.490Z sha dfc4fcc5435d4e633f062551953519580ceac764 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added 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. and removed 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 9, 2026
@zenglingbiao
zenglingbiao force-pushed the fix/mcp-app-standalone-head-content-length branch from 7f86406 to dfc4fcc Compare August 9, 2026 07:38
@zenglingbiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the P2 finding is addressed at head dfc4fcc5435: the active-view-limit 429 now goes through the same HEAD-aware respondString as the other routes, with a GET/HEAD parity regression test at activeRequests = 4 (429 carries the JSON Content-Length, HEAD ends with no body). Branch also rebased onto current main as flagged.

@clawsweeper

clawsweeper Bot commented Aug 9, 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: 🐚 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 Aug 9, 2026
@steipete
steipete force-pushed the fix/mcp-app-standalone-head-content-length branch from dfc4fcc to 26c5fdf Compare August 25, 2026 08:33
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 25, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

Refreshed this contributor PR onto current main after resolving the real stale-branch conflict. The corrected head preserves the newer standalone browser and operation timeouts, reuses the canonical plain-text response helper, and proves GET/HEAD parity for shell, multibyte authenticated view, unauthorized challenge, and active-view-limit responses against a real localhost HTTP server. Current-main reproduction failed all four new cases; the repaired standalone, sandbox, and board suites pass all 36 tests. The PR description also clarifies that HEAD Content-Length is optional under RFC 9110 and that standalone MCP Apps are opt-in.

@clawsweeper

clawsweeper Bot commented Aug 25, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor

Maintainer verification for reviewed head 26c5fdf:

  • Root cause: Node suppresses HEAD bodies but does not synthesize representation byte lengths; the standalone shell, ticket-authorized view, unauthorized challenge, and active-view-limit response each omitted HEAD Content-Length.
  • Current-main reproduction uses a real ephemeral localhost HTTP server and real GET/HEAD requests. Before the fix: shell 200 expected 8890 bytes, multibyte authenticated view 200 expected 371, unauthorized 401 expected 12, and active-view-limit 429 expected 64; all four HEAD headers were absent (4 failed, 12 passed).
  • Corrected owner reuses canonical respondPlainText, computes bounded HTML/JSON UTF-8 byte lengths, and preserves empty HEAD bodies. Existing ticket authorization, challenge/Vary, CSP, no-store policy, active-view limits, POST operations, browser initial-load deadline, and 65-second operation-timeout grace remain intact. Production delta is +35/-34, net +1.
  • Focused standalone and neighboring sandbox/board proof: node scripts/run-vitest.mjs src/gateway/mcp-app-standalone.test.ts src/gateway/mcp-app-sandbox-http.test.ts src/gateway/board-http.test.ts → 3 files, 36 tests passed.
  • Formatting, fresh independent Codex autoreview, two independent exact-head source reviews, and repository-native review artifacts all passed without findings. Original contributor @zenglingbiao is credited in the signed commit.

This is an opt-in MCP App surface. RFC 9110 allows HEAD Content-Length to be omitted; when present, it must match the corresponding GET representation. The fix improves interoperability without changing authentication, public configuration, protocol, persistence, or global Gateway responders.

@steipete
steipete merged commit 6f4b9a2 into openclaw:main Aug 25, 2026
257 of 259 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants