Skip to content

fix(gateway): send Content-Length on MCP App sandbox HEAD responses - #118553

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
zenglingbiao:fix/mcp-app-sandbox-head-content-length
Aug 10, 2026
Merged

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

Conversation

@zenglingbiao

@zenglingbiao zenglingbiao commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve byte-accurate representation metadata for GET and HEAD responses from the dedicated MCP App sandbox origin.

The rewritten change:

  • reuses the shared plain-text responder for deterministic 400 and 404 metadata;
  • materializes the sandbox HTML once;
  • sets its byte-accurate Content-Length for both methods;
  • suppresses only the HEAD response body.

What Problem This Solves

The sandbox handler accepted HEAD, but its successful response called res.end() without the HTML body. Node therefore had no bytes from which to derive Content-Length. The same problem existed on the route's plain-text 400 and 404 responses.

Current-main loopback reproduction:

Response GET Content-Length HEAD Content-Length
sandbox HTML (200) 4469 missing
missing path (404) 9 missing
malformed policy (400) 30 missing

This is a metadata parity defect, not a claim that RFC 9110 universally requires Content-Length on every HEAD response. When supplied on HEAD, the value must match the corresponding GET representation size.

Root Cause

The route relied on Node's implicit length calculation from res.end(body). That calculation worked for GET, but the handler intentionally passed no body for HEAD. Error branches duplicated response construction and had the same omission.

Provenance: the route and HEAD branch originated in f3971bbd56e / #69039. The current PR author is @zenglingbiao.

Why This Change Was Made

The route owns the representation, so it is the correct place to record its byte length. Reusing respondPlainText() also removes duplicate error-response policy and fixes 400/404 through the existing canonical helper.

Alternatives rejected:

  • Set the header only in a HEAD branch: leaves GET and HEAD on separate metadata paths.
  • Depend on Node to synthesize it: impossible when the handler supplies no HEAD body.
  • Add range, compression, standalone, config, or protocol behavior: unrelated to this defect.

User Impact

Clients probing the sandbox origin with HEAD receive the same representation metadata as GET while still receiving no body. GET response bytes and sandbox security headers remain unchanged.

Evidence

  • Current-main real loopback regression: all three cases above reproduced missing HEAD lengths.
  • Focused Vitest: src/gateway/mcp-app-sandbox-http.test.ts passes 6/6; repeated local runs stayed green.
  • Max-P1 autoreview: clean, no actionable findings, confidence 0.97.
  • Local ClawSweeper on exact commit 613b01fbaac027d1f18b10ffd3d40857197e7305: nothing_found, high confidence.
  • Secretless direct AWS Crabbox on exact PR head: 6/6 passed, lease cbx_843c23648b61, run run_1a97b1290420.
  • Production LOC: +8/-8 (net 0). Tests: +66/-0.

Punchcard-Session: coral-summit-orchard-93

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Aug 3, 2026
@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 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 10, 2026, 9:46 AM ET / 13:46 UTC.

ClawSweeper review

What this changes

The PR makes MCP App sandbox GET and HEAD responses expose the same byte-accurate Content-Length and adds loopback parity coverage.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This PR remains necessary: current main still omits Content-Length on the dedicated sandbox listener’s HEAD success and error responses. The response owner is the right repair point, and the separate standalone-host follow-up is already tracked independently.

Priority: P2
Reviewed head: 613b01fbaac027d1f18b10ffd3d40857197e7305

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, net-neutral owner-boundary repair with real-listener proof and no correctness findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR provides after-fix real-loopback evidence through the production listener for successful and error responses, and the added 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 provides after-fix real-loopback evidence through the production listener for successful and error responses, and the added test exercises the same boundary.
Evidence reviewed 5 items Current-main defect: The success HEAD branch suppresses the body without recording representation length, and the error paths end their strings without explicit Content-Length.
Canonical error-response helper: The existing helper already sets UTF-8 Content-Type and byte-accurate Content-Length for non-204 plain-text responses, making it the appropriate owner for the sandbox error paths.
Runtime entry point: Gateway runtime startup creates this dedicated listener on the adjacent sandbox origin, confirming the changed handler is the production response boundary.
Findings None None.
Security None None.

How this fits together

The MCP App sandbox is a dedicated unauthenticated HTTP origin that serves a generated proxy page for embedded MCP App views. It receives sandbox requests from the gateway runtime and returns isolated HTML or plain-text errors.

flowchart LR
A[MCP App view request] --> B[Dedicated sandbox listener]
B --> C{Valid route and policy?}
C -->|No| D[Plain-text error]
C -->|Yes| E[Generated sandbox HTML]
D --> F[GET or HEAD response]
E --> F
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head build and lint checks are still running; merge only after they complete green.
  • Complete next step (P2) - No repair dispatch is needed; this is a normal focused PR pending completion of its existing exact-head CI gate.
Agent review details

Security

None.

PR surface

Source 0, Tests +66. Total +66 across 2 files.

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

Review metrics

Metric Value Why it matters
Production versus test LOC production +8/-8 (net 0), tests +66/-0 The response-owner repair is net-neutral and adds real-listener coverage for three representation classes.

Stored data model

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

Root-cause cluster

Relationship: canonical
Canonical: #118553
Summary: This PR is the canonical repair for the dedicated sandbox listener; related HEAD metadata fixes address separate gateway listeners.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land this net-neutral listener repair after exact-head CI completes, while keeping the standalone MCP App host repair in fix(gateway): send Content-Length on MCP App standalone HEAD responses #120905 separate.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land this net-neutral listener repair after exact-head CI completes, while keeping the standalone MCP App host repair in #120905 separate.

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

Yes: current main visibly takes the HEAD no-body path without setting a length, and the PR supplies a focused real-loopback GET/HEAD comparison.

Is this the best way to solve the issue?

Yes: the listener owns the generated representation, while the existing shared helper owns plain-text metadata; this avoids a HEAD-only workaround or duplicate error policy.

AGENTS.md: found and applied where relevant.

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

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 is a bounded gateway HTTP metadata correction with limited operator-facing impact.
  • 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 provides after-fix real-loopback evidence through the production listener for successful and error responses, and the added test exercises the same boundary.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides after-fix real-loopback evidence through the production listener for successful and error responses, and the added test exercises the same boundary.

Evidence

What I checked:

  • Current-main defect: The success HEAD branch suppresses the body without recording representation length, and the error paths end their strings without explicit Content-Length. (src/gateway/mcp-app-sandbox-http.ts:18, 14f8ed121e03)
  • Canonical error-response helper: The existing helper already sets UTF-8 Content-Type and byte-accurate Content-Length for non-204 plain-text responses, making it the appropriate owner for the sandbox error paths. (src/gateway/control-ui-http-utils.ts:34, 14f8ed121e03)
  • Runtime entry point: Gateway runtime startup creates this dedicated listener on the adjacent sandbox origin, confirming the changed handler is the production response boundary. (src/gateway/server-runtime-state.ts:373, 14f8ed121e03)
  • Behavior-level regression coverage: The proposed test starts the real listener and checks GET/HEAD status, headers, body suppression, and byte lengths for HTML, 404, and malformed-policy responses; this is boundary coverage rather than a mock-only assertion. (src/gateway/mcp-app-sandbox-http.test.ts:104, 613b01fbaac0)
  • History and release boundary: Current sandbox-listener code entered main in this commit; the latest release tag predates the file entirely, so the reported behavior is neither already fixed on main nor present in the latest release. (src/gateway/mcp-app-sandbox-http.ts:18, 890a4b0089f1)

Likely related people:

  • jesse-merhi: Current main attributes the sandbox listener and its tests to this commit. (role: current listener author; confidence: high; commits: 890a4b0089f1; files: src/gateway/mcp-app-sandbox-http.ts, src/gateway/mcp-app-sandbox-http.test.ts)
  • sallyom: The merged MCP Apps feature is the reported origin of the sandbox capability. (role: MCP Apps feature introducer; confidence: medium; commits: f3971bbd56e4; files: src/gateway/mcp-app-sandbox-http.ts)
  • xzh-icenter: The merged plain-text response update established the helper reused by this patch. (role: shared-helper contributor; confidence: medium; commits: f64d7fab2101; files: src/gateway/control-ui-http-utils.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 (2 earlier review cycles)
  • reviewed 2026-08-03T07:08:31.904Z sha 2a400649d414fc0f99ec909cc7abf68cfea2ccde :: needs maintainer review before merge. :: none
  • reviewed 2026-08-05T04:07:58.816Z sha 2a400649d414fc0f99ec909cc7abf68cfea2ccde :: needs maintainer review before merge. :: none

Punchcard-Session: coral-summit-orchard-93
@vincentkoc
vincentkoc force-pushed the fix/mcp-app-sandbox-head-content-length branch from 2a40064 to 613b01f Compare August 10, 2026 13:33
@vincentkoc vincentkoc self-assigned this Aug 10, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 10, 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 10, 2026
@vincentkoc
vincentkoc merged commit b121219 into openclaw:main Aug 10, 2026
134 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 11, 2026
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: 🦞 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.

2 participants