Skip to content

fix(gateway): preserve local avatar HEAD content length - #117124

Merged
steipete merged 1 commit into
mainfrom
codex/qa-gateway-avatar-head-content-length
Aug 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-gateway-avatar-head-content-length

Conversation

@steipete

@steipete steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Control UI's authenticated /avatar/:agentId route already accepts HEAD, but silently omitted Content-Length while the corresponding GET response included the exact image size. Clients probing local assistant-avatar metadata therefore could not discover the representation size without downloading the image.

Root Cause and Fix

The avatar owner validates and pins the local image descriptor before deciding between GET and HEAD; the exact descriptor size is already available as openedFile.stat.size. Its HEAD branch returned without publishing that known size.

The fix sets Content-Length only in that existing authenticated HEAD branch, using the already-validated pinned descriptor. It performs no additional filesystem reads, closes the descriptor through the existing finally, and leaves the GET branch completely unchanged so bounded reads and post-open file-growth handling retain their original behavior.

This follows RFC 9110 §9.3.2 and RFC 9110 §8.6: a HEAD response may include Content-Length when it exactly equals the bytes a corresponding GET would send.

  • Works for supported PNG, JPEG, GIF, WebP, and SVG assistant avatars, including multibyte filenames/content and zero-byte images.
  • Preserves existing MIME type, cache policy, security headers, bearer authentication, workspace boundaries, hardlink/symlink checks, descriptor closure, root-mounted routes, and configured /openclaw base paths.
  • Unauthorized HEAD remains 401 without opening an avatar; unavailable avatars remain 404.
  • No configuration/defaults, public protocol/SDK, security-policy, persistent-state, or provider changes.

Regression-First Proof

Frozen parent: 9878bfc8e505f9bbc87905b67488248e51546eaf.

The added owner-local cases failed authentically 7 times before the production fix: five supported image types plus both authenticated Control UI base-path variants returned 200 with no Content-Length.

Immutable candidate: 155775535030c0eb9bfd86cb89b87469af2f774b.

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs \
  src/gateway/control-ui.http.test.ts \
  src/gateway/assistant-avatar.test.ts \
  src/gateway/user-profiles-http.test.ts

Test Files  3 passed (3)
     Tests  158 passed (158)

The complete owner and sibling suites verify byte-accurate multibyte lengths for PNG/JPEG/GIF/WebP/SVG, bodyless HEAD, no file reads, descriptor closure, unchanged GET body and headers, authenticated root and /openclaw paths, missing/unauthorized outcomes, existing pinned-file growth bounds, and sibling profile-avatar/static/media behavior.

Focused true type-aware oxlint (--type-aware --type-check), targeted oxfmt, and git diff --check all passed. Production changes just two lines: one ownership comment and the HEAD-only representation header.

Actual Production HTTP Proof

The exact immutable production handler was exercised through real bearer-authenticated loopback HTTP/TCP, with five actual local image types at both root and configured base paths. Native filesystem operations were instrumented around the real pinned descriptor.

{"candidate":"155775535030c0eb9bfd86cb89b87469af2f774b","actualHttpAssertions":159,"formats":["png","jpeg","gif","webp","svg"],"basePaths":["/","/openclaw"],"head":200,"get":200,"unauthorizedHead":401,"missingHead":404,"headDescriptorOpens":1,"headDescriptorReads":0,"headDescriptorCloses":1,"zeroByteContentLength":"0","getBodyUnchanged":true}

All 159 actual production assertions passed. Every HEAD exposed the exact corresponding GET byte length and MIME without transferring or reading image bytes; every pinned descriptor closed exactly once. Unauthorized probes opened no descriptor.

Review

Genuine whole-branch autoreview --mode branch --base 9878bfc8e505f9bbc87905b67488248e51546eaf --max-priority P3: zero P0/P1/P2/P3 findings, TruffleHog clean, verdict patch is correct, confidence 0.97.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 1, 2026
@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 31, 2026, 8:32 PM ET / August 1, 2026, 00:32 UTC.

ClawSweeper review

What this changes

The PR adds Content-Length to authenticated Control UI local-avatar HEAD responses and tests normal-size avatars across supported image formats and Control UI base paths.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep this PR open: the header is added in the correct response owner, but it can advertise an oversized avatar that the corresponding bounded GET refuses to serve. The local checkout is at 4f7fbcb rather than the supplied current-main SHA e8d546c, so a final exact-head/current-main refresh is also needed before merge.

Priority: P2
Reviewed head: 155775535030c0eb9bfd86cb89b87469af2f774b

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong reported live proof covers normal avatar sizes, but a P1 boundary mismatch keeps the patch from being merge-ready.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body and successful real-behavior-proof check provide concrete after-fix authenticated loopback HTTP/TCP evidence, but the reported coverage does not include the oversized descriptor state required for HEAD/GET parity.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body and successful real-behavior-proof check provide concrete after-fix authenticated loopback HTTP/TCP evidence, but the reported coverage does not include the oversized descriptor state required for HEAD/GET parity.
Evidence reviewed 5 items GET has a serving-size contract: The current avatar handler reads GET bodies through readFileDescriptorBounded(..., AVATAR_MAX_BYTES) and maps any error to the existing unavailable response, while the proposed HEAD line returns before that guard.
Bounded-read overflow is explicit: The wrapper preserves a RangeError when a pinned descriptor exceeds the maximum, and its regression test confirms this contract; an oversized avatar therefore cannot be assumed to have a servable GET representation.
Proposed branch bypasses the size guard: The PR diff sets Content-Length from openedFile.stat.size in the early HEAD branch, so a file over the two-megabyte avatar cap can receive HEAD 200 with a length although GET reaches the catch path.
Findings 1 actionable finding [P1] Match HEAD availability to the bounded GET representation
Security None None.

How this fits together

The gateway serves a configured assistant avatar after authenticating the request and opening a file safely beneath the agent workspace. HEAD returns metadata only, while GET reads the same descriptor through a maximum-size guard before sending image bytes.

flowchart LR
  Client[Control UI client] --> Request[Authenticated avatar request]
  Request --> Pin[Pin safe local avatar descriptor]
  Pin --> Method{Request method}
  Method -->|HEAD| Metadata[Metadata response]
  Method -->|GET| Limit[Bounded file read]
  Limit --> Body[Image bytes]
  Metadata --> Client
  Body --> Client
Loading

Before merge

  • Match HEAD availability to the bounded GET representation (P1) - GET reads this descriptor through readFileDescriptorBounded(..., AVATAR_MAX_BYTES), which rejects files larger than the serving limit and reaches the unavailable response. This new HEAD branch returns 200 and advertises the full stat size without that eligibility check, so probes can observe a representation that a corresponding GET cannot retrieve. Gate this header on the same size limit and add the boundary regression.
  • Resolve merge risk (P1) - An avatar larger than AVATAR_MAX_BYTES can make GET fail in the bounded-read branch while this patch returns 200 and advertises its full stat size on HEAD, so the header does not describe a corresponding GET representation.
  • Resolve merge risk (P1) - The available checkout is at 4f7fbcb34da23e93b7a2cc050db893f18fd9da5a, not the supplied current-main SHA e8d546c8da8d76f19e8e5df6df08f6ecc79a4123; the unavailable promisor remote prevented a final post-base verification.
  • Complete next step (P2) - The P1 repair is mechanically clear, but the maintainer label and unavailable current-main checkout require a maintainer-directed exact-head refresh before any automated repair lane.

Findings

  • [P1] Match HEAD availability to the bounded GET representation — src/gateway/control-ui.ts:834
Agent review details

Security

None.

PR surface

Source +2, Tests +86. Total +88 across 2 files.

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

Review metrics

None.

Stored data model

Persistent data-model change detected: persistent cache schema: src/gateway/control-ui.http.test.ts, serialized state: src/gateway/control-ui.http.test.ts, vector/embedding metadata: src/gateway/control-ui.http.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Align HEAD with bounded GET eligibility (recommended)
    Reject or map an oversized pinned avatar to the existing unavailable response before setting Content-Length, then cover HEAD/GET parity at the size boundary.
  2. Accept divergent probe behavior
    Merge the current behavior only if maintainers explicitly want HEAD to publish local-file metadata even when GET cannot serve the file.
  3. Pause the change
    Defer the change if parity with GET is not desired and the metadata benefit does not justify a divergent endpoint contract.

Technical review

Best possible solution:

Preserve the single pinned-descriptor flow, but make oversized local avatars take the same unavailable outcome for HEAD and GET; publish Content-Length only after establishing that the descriptor is within the maximum servable representation size.

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

Yes in source: configure a local avatar whose safely pinned descriptor exceeds AVATAR_MAX_BYTES; GET enters the bounded read and reaches the unavailable response, while the proposed HEAD branch returns 200 with its stat size.

Is this the best way to solve the issue?

No: adding the header at this owner branch is appropriate, but it must share GET’s maximum-size eligibility before promising an exact corresponding representation.

Full review comments:

  • [P1] Match HEAD availability to the bounded GET representation — src/gateway/control-ui.ts:834
    GET reads this descriptor through readFileDescriptorBounded(..., AVATAR_MAX_BYTES), which rejects files larger than the serving limit and reaches the unavailable response. This new HEAD branch returns 200 and advertises the full stat size without that eligibility check, so probes can observe a representation that a corresponding GET cannot retrieve. Gate this header on the same size limit and add the boundary regression.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The patch changes a narrow authenticated Control UI avatar metadata path, with the defect limited to an oversized local-file state.
  • add merge-risk: 🚨 compatibility: The new HEAD metadata can diverge from the existing bounded GET availability contract for oversized configured avatars.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body and successful real-behavior-proof check provide concrete after-fix authenticated loopback HTTP/TCP evidence, but the reported coverage does not include the oversized descriptor state required for HEAD/GET parity.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body and successful real-behavior-proof check provide concrete after-fix authenticated loopback HTTP/TCP evidence, but the reported coverage does not include the oversized descriptor state required for HEAD/GET parity.

Label justifications:

  • P2: The patch changes a narrow authenticated Control UI avatar metadata path, with the defect limited to an oversized local-file state.
  • merge-risk: 🚨 compatibility: The new HEAD metadata can diverge from the existing bounded GET availability contract for oversized configured avatars.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body and successful real-behavior-proof check provide concrete after-fix authenticated loopback HTTP/TCP evidence, but the reported coverage does not include the oversized descriptor state required for HEAD/GET parity.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and successful real-behavior-proof check provide concrete after-fix authenticated loopback HTTP/TCP evidence, but the reported coverage does not include the oversized descriptor state required for HEAD/GET parity.

Evidence

What I checked:

  • GET has a serving-size contract: The current avatar handler reads GET bodies through readFileDescriptorBounded(..., AVATAR_MAX_BYTES) and maps any error to the existing unavailable response, while the proposed HEAD line returns before that guard. (src/gateway/control-ui.ts:837, 4f7fbcb34da2)
  • Bounded-read overflow is explicit: The wrapper preserves a RangeError when a pinned descriptor exceeds the maximum, and its regression test confirms this contract; an oversized avatar therefore cannot be assumed to have a servable GET representation. (src/infra/boundary-file-read.ts:67, 4f7fbcb34da2)
  • Proposed branch bypasses the size guard: The PR diff sets Content-Length from openedFile.stat.size in the early HEAD branch, so a file over the two-megabyte avatar cap can receive HEAD 200 with a length although GET reaches the catch path. (src/gateway/control-ui.ts:834, 155775535030)
  • Feature provenance: Blame attributes the existing avatar GET/HEAD split and bounded-read lifecycle to the recent Control UI gateway work; the immediately preceding commit was the related HEAD-metadata change. (src/gateway/control-ui.ts:832, 6b40ad6a66c0)
  • Release and current-main check: v2026.7.1 resolves to 2d2ddc4, and git merge-base --is-ancestor v2026.7.1 4f7fbcb returned nonzero, confirming the inspected gateway behavior is main-only relative to that release. The supplied current-main SHA e8d546c was unavailable in this checkout because the promisor remote could not resolve. (4f7fbcb34da2)

Likely related people:

  • Peter Steinberger: The current avatar response lifecycle is attributed to Peter Steinberger by blame, and the adjacent HEAD-metadata change is also authored by him. (role: feature owner and recent area contributor; confidence: high; commits: 6b40ad6a66c0, 4f7fbcb34da2, 505f8ae6a3a6; files: src/gateway/control-ui.ts, src/gateway/control-ui.http.test.ts)

Rank-up moves

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

  • Guard the HEAD header using the same maximum-size eligibility as GET.
  • Add an oversized-avatar regression proving matching HEAD and GET availability.
  • Refresh against current main and include the updated redacted loopback result in the PR body.

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.

@steipete
steipete merged commit afa8fff into main Aug 1, 2026
130 of 142 checks passed
@steipete
steipete deleted the codex/qa-gateway-avatar-head-content-length branch August 1, 2026 00:36
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@clawsweeper

clawsweeper Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): preserve local avatar HEAD content length This is item 3/3 in the current shard. Shard 7/43.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

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

Labels

app: web-ui App: web-ui gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant