Repository navigation
fix(canvas): serve Content-Length on Canvas document HEAD responses - #117964
vincentkoc merged 3 commits into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 7:20 AM ET / 11:20 UTC. ClawSweeper reviewWhat this changesThe PR adds explicit representation-length metadata and bodyless Merge readinessThis PR remains necessary: current Priority: P2 Review scores
Verification
How this fits togetherManaged Canvas documents are stored locally and reached through the gateway’s authenticated Canvas-document request stage. The Canvas response handler selects either decoded HTML or raw asset bytes, then sends HTTP metadata and the response to the client. flowchart LR
A[Managed Canvas document] --> B[Gateway Canvas request stage]
B --> C[Canvas document handler]
C --> D{Representation type}
D -->|HTML| E[Decoded UTF-8 body]
D -->|Static asset| F[Raw file bytes]
E --> G[GET or HEAD metadata]
F --> G
G --> H[HTTP client]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +13, Tests +53. Total +66 across 2 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Merge the representation-specific calculation: use the decoded HTML string length for HTML and raw byte length for static assets, while keeping Canvas storage, authentication, and gateway routing unchanged. Do we have a high-confidence way to reproduce the issue? Yes. Current main permits HEAD at Is this the best way to solve the issue? Yes. The final response owner is the narrowest durable place to derive representation metadata: decoded UTF-8 length for HTML and raw buffer length for assets. The prior concern about invalid UTF-8 is addressed by the added regression case. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 247278262234. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
…-head-content-length
|
Merged via squash.
|
* origin/main: fix(sqlite): skip slow-lock diagnostic when busyTimeoutMs is zero (#115990) fix(canvas): serve Content-Length on Canvas document HEAD responses (#117964) fix(workboard): diagnose archived cards still in an active status (#116359) (#117290) feat(diagnostics): configure OTEL metric name prefixes (#116687) fix(ui): respect UTC when filtering pending usage sessions (#118004)
…penclaw#117964) * fix(canvas): serve Content-Length on Canvas document HEAD responses * fix(canvas): measure decoded HTML representation for Content-Length
* origin/main: fix(sqlite): skip slow-lock diagnostic when busyTimeoutMs is zero (openclaw#115990) fix(canvas): serve Content-Length on Canvas document HEAD responses (openclaw#117964) fix(workboard): diagnose archived cards still in an active status (openclaw#116359) (openclaw#117290) feat(diagnostics): configure OTEL metric name prefixes (openclaw#116687) fix(ui): respect UTC when filtering pending usage sessions (openclaw#118004)
Summary
The gateway's managed Canvas document endpoint (
src/canvas/serve.runtime.ts) accepts HEAD requests but had no HEAD branch: it calledres.end(opened.data)unconditionally, so HEAD responses never carried a Content-Length header.What Problem This Solves
RFC 9110 recommends sending the same header fields for HEAD as for the corresponding GET when they are available. It permits
Content-Lengthon HEAD only when the value equals the octet count a corresponding GET would send. Node's HTTP server suppresses the response body for HEAD automatically, but it does not synthesize that representation length.handleCanvasDocumentHttpRequestallowsGETandHEAD(src/canvas/serve.runtime.ts:57), but both methods fell through tores.end(opened.data).Content-Lengthfrom the ended buffer; for HEAD the body is dropped and no length header is ever set./__openclaw__/canvas/documents/<id>/index.html(asset probes, caches, download managers,curl -I) cannot learn the payload size.代码证据:before the fix,
HEAD /__openclaw__/canvas/documents/widget-1/index.htmlreturned 200 withContent-Security-Policybut noContent-Length, while GET returnedContent-Length: 32.This is the same defect class fixed for control-ui static assets in #117049; here it is simpler because the representation bytes are already fully buffered (
opened.data), so the length is exact for both HTML and static assets — no injection math required.Root Cause
The handler computed the full representation in memory but only let Node's implicit
res.end(buf)behavior produce Content-Length. That implicit path never runs for HEAD (body suppressed), and no explicitContent-Lengthheader was set. The violated invariant: every 200 response on this endpoint should describe its representation metadata regardless of method.Why This Fix
Content-Length: opened.data.byteLengthonce, before the method branches — it is exact for both GET and HEAD, for HTML and static assets alike (the HTML is served unmodified, unlike the A2UI host).User Impact
Content-Length(plus the same CSP header as GET).Evidence
main—HEAD .../index.html→Content-Length=nullwhile GET served 32 bytes;HEAD .../style.css→Content-Length=nullwhile GET served 20 bytes → FAIL.Content-Length: 32/Content-Length: 20matching the GET bodies, CSP preserved → PASS.Real Behavior Proof
Before (on main)
After (with fix)
(Loopback
http.createServer+ realhandleCanvasDocumentHttpRequestagainst a tempOPENCLAW_STATE_DIRwith a managed Canvas document; Node suppresses the HEAD body itself, sobodyBytes=0on HEAD is expected — the header is what matters.)Tests and Validation
e1dcbd25b6547886e3978ebaba2fc6760d2a182enode scripts/run-vitest.mjs src/canvas/serve.runtime.test.ts src/canvas/documents.test.tspassed: 2 files, 11 tests.origin/mainwas clean through P1 with correctness 0.98.