Repository navigation
Description
What happened
On main 65e5b2e19c9db6460494682bacc4bee10db755fd, a valid decimal media limit can make an oversized chunked download fail as a generic fetch error instead of a size-limit error. Bounded diagnostic text reads also throw rather than returning their prefix when the byte budget is fractional.
Reproduction
- Set the existing agent default
mediaMaxMbto0.1(the schema accepts positive fractional values). - The shared channel resolver supplies a budget of
104857.6bytes. - Download a chunked HTTP response containing
104858bytes throughreadRemoteMediaBuffer.
Expected: MediaFetchError with code max_bytes. Actual on Node 24.19.0: fetch_failed, caused by RangeError: length must be an integer. A 104857-byte control succeeds.
Directly reading the prefix of abcdef with a 3.5-byte budget also throws that RangeError instead of returning abc with truncated: true.
Root cause and scope
src/infra/http-body.ts counts a sliced overflow chunk using the fractional budget remainder, then supplies that fractional retained length to Buffer.concat. The slice contains whole bytes, so the counter and actual buffer disagree. The shared response reader owns this calculation; request-body limits, network policy, and configuration validation are separate unchanged contracts.
The failure is reproduced with a real loopback HTTP server and native Fetch, plus regressions that fail on the original code. Related: #135418, which investigates the same fractional media-limit trigger at the channel conversion layer.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Sep 2, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed September 2, 2026, 11:50 AM ET / 15:50 UTC.
Summary
Keep open: current main still permits a fractional byte budget to reach the shared response reader, where fractional accounting reaches
Buffer.concatbefore media code can emit its intendedmax_byteserror. The open related PR addresses channel-side normalization but is not merged and does not cover the shared reader’s direct diagnostic-prefix path; themaintainerlabel also requires explicit handling.Reproducibility: yes. source-reproducible with high confidence: a fractional cap makes
remainingandtotalfractional on the overflow branch before buffer assembly. This read-only review did not execute the reporter’s loopback scenario.Maintainer decision needed
Why: The source defect is small and clear, but this issue is protected with the
maintainerlabel and overlaps an active contributor PR without being fully covered by it.Next step
The source-proven repair is small, but the protected
maintainerlabel requires explicit human handling; the adjacent open PR is related but does not yet replace this issue.Review details
Best possible solution:
Normalize a finite response-reader byte budget to whole bytes once at the shared reader boundary, then add focused chunked-media and text-prefix regressions that prove the overflow classification remains
max_bytes.Do we have a high-confidence way to reproduce the issue?
Yes, source-reproducible with high confidence: a fractional cap makes
remainingandtotalfractional on the overflow branch before buffer assembly. This read-only review did not execute the reporter’s loopback scenario.Is this the best way to solve the issue?
Yes: normalizing at the shared response-reader boundary fixes both remote-media and direct-prefix callers, unlike a channel-only conversion guard.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning high; reviewed against cf59ce401fee.
Label changes
Label changes:
P2: Valid fractional configuration can make oversized streamed media fail with the wrong user-visible error, but the trigger is limited to decimal limits and chunked overflow.impact:other: The issue affects bounded media retrieval and diagnostic response handling, which does not map to a more specific owned impact label.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.Label justifications:
P2: Valid fractional configuration can make oversized streamed media fail with the wrong user-visible error, but the trigger is limited to decimal limits and chunked overflow.impact:other: The issue affects bounded media retrieval and diagnostic response handling, which does not map to a more specific owned impact label.Evidence reviewed
What I checked:
src/infra/http-body.ts:162, cf59ce401fee)src/media/fetch.ts:725, cf59ce401fee)src/config/zod-schema.agent-defaults.ts:197, cf59ce401fee)src/infra/http-body.response.test.ts:189, cf59ce401fee)src/infra/http-body.ts:213, c47f102224f9)Likely related people:
How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.fix(media): preserve size errors for fractional byte limits (#136402)
fix(media): preserve size errors for fractional byte limits (openclaw…