Skip to content

R2 JSRPC Bindings (double fork edition) - #8114

Merged
jp4a50 merged 1 commit into
mainfrom
jp4a50/r2-jsrpc-bindings
Nov 3, 2026
Merged

jp4a50 merged 1 commit into
mainfrom
jp4a50/r2-jsrpc-bindings

Conversation

@jp4a50

@jp4a50 jp4a50 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Cloned from @bthwaites PR (original commit SHA e717f1b): #7913

@jp4a50
jp4a50 requested review from a team as code owners October 30, 2026 23:00
@jp4a50
jp4a50 requested a review from edmundhung October 30, 2026 23:00
@jp4a50
jp4a50 enabled auto-merge October 30, 2026 23:02

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 0ecd063b.

This review, of e717f1bf

💬 Approved with comments — One WARNING: a ranged get over RPC can compute the wrong body length when the backend returns an offset-only or suffix-only range. The remaining items are suggestions or informational.

Findings: 1 warning · 1 info · 1 suggestion (1 is an inline comment on the diff)

Not opened by the correctness review: 5 changed files it was meant to read
  • .bazelrc
  • compile_flags.txt
  • doxyfile
  • src/workerd/api/r2-multipart.h
  • src/workerd/api/r2.h

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8114.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, which `headResultFromSerializable` accepts. The body then ends before its declared length and reading it fails.
- **File:** src/workerd/api/r2-bucket.c++:651

## INFO (1)

### [Code Quality] The continuation in unwrapR2RpcPromise captures the TypeHandler by bare reference. This is probably safe because it lives as long as the isolate, but it is the pattern `workerd-unsafe-continuation-capture` flags.
- **File:** src/workerd/api/r2-rpc.h:49

## SUGGESTION (1)

### [Code Quality] uploadPartRpc does not apply the 1..10000 part-number check that the HTTP uploadPart enforces, so the error depends on the backend.
- **File:** src/workerd/api/r2-multipart.c++:141

📋 Code Quality: ⚠️ 1 warning · 1 info · 1 suggestion

Wrong body length for ranged gets with offset-only or suffix-only ranges, plus a few minor consistency and test-coverage notes.

Recommendation: 📝 Minor Comments

  • [WARNING] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, which headResultFromSerializable accepts. The body then ends before its declared length and reading it fails. (src/workerd/api/r2-bucket.c++:651)
  • [INFO] The continuation in unwrapR2RpcPromise captures the TypeHandler by bare reference. This is probably safe because it lives as long as the isolate, but it is the pattern workerd-unsafe-continuation-capture flags. (src/workerd/api/r2-rpc.h:49)
  • [SUGGESTION] uploadPartRpc does not apply the 1..10000 part-number check that the HTTP uploadPart enforces, so the error depends on the backend. (src/workerd/api/r2-multipart.c++:141)
View full review

getResultBodyLength ignores offset-only and suffix-only ranges (src/workerd/api/r2-bucket.c++:647-656)

  • The body length is range.length.orDefault(size). headResultFromSerializable (lines 605-620) accepts a range with only offset, where the body is size - offset bytes, and a range with only suffix, where the body is min(suffix, size) bytes. For both, this returns the full object size.
  • That length becomes the expected length of the identity pipe the body goes through. The body therefore ends before the declared length, and reading it fails.
  • The binding contract in r2-binding-service.ts says a backend can return what a native binding returns, and the backend gets the caller's R2GetOptions unnormalized. A backend that echoes the requested range back hits this path.
  • Fix: compute the length from offset, length and suffix against size, or reject unresolved ranges for get results. No test covers a partial range over RPC.

uploadPartRpc skips the part-number check (src/workerd/api/r2-multipart.c++:132-151)

  • The HTTP path rejects part numbers outside 1..10000 with a TypeError. The RPC path forwards the number unchecked, so the error a caller sees depends on the backend. The contract hands validation to the backend on purpose, but a shared check would keep the error the same on both sides of the flag.

Reference capture in a promise continuation (src/workerd/api/r2-rpc.h:49)

  • The .then lambda captures &resultPromiseHandler. This is most likely safe because TypeHandlers live as long as the isolate. It is still the pattern the workerd-unsafe-continuation-capture check flags.

r2-test no longer runs with disable_fast_jsg_struct (src/workerd/api/tests/r2-test.wd-test)

  • This test no longer exercises the legacy struct shape unless another variant enables that flag.

✅ All other checks passed

🔒 Security: ✅ LGTM

  • R2 resource serialization is limited to JSRPC.
  • Deserialized results are validated for size, range and kind.
  • Inline bodies stay within a fixed 16 MiB budget; larger ones are sent as streams.
  • RPC method names come from a fixed set, never from user input.
  • Trace tags match the tags the existing code already emits.

📖 AGENTS.md: ✅ LGTM

The compatibility flag adds a second R2 transport that calls named JSRPC methods on a backend entrypoint. A short entry in src/workerd/api/AGENTS.md pointing to r2-rpc.{h,c++}, the binding contract in tests/r2-binding-service/ and the related tests would make this path easier to find.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: e717f1bf

Comment thread src/workerd/api/r2-bucket.c++ Resolved
@jp4a50
jp4a50 force-pushed the jp4a50/r2-jsrpc-bindings branch 2 times, most recently from 9918d55 to 0ecd063 Compare November 2, 2026 21:21

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 69733ada.

This review, of 0ecd063b

💬 Approved with comments — One WARNING is still open: getResultBodyLength uses the full object size for offset-only and suffix-only ranges, so reading a ranged get body over RPC can fail. Everything else is a suggestion or informational.

Findings: 1 warning · 2 info · 2 suggestions (4 are inline comments on the diff)

Not opened by the correctness review: 2 changed files it was meant to read
  • compile_flags.txt
  • doxyfile

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8114.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it fails.
- **File:** src/workerd/api/r2-bucket.c++:651

## INFO (2)

### [Code Quality] The continuation captures the TypeHandler by bare reference, the pattern the workerd-unsafe-continuation-capture check flags.
- **File:** src/workerd/api/r2-rpc.h:49

### [Code Quality] Removing disable_fast_jsg_struct means no HTTP-transport R2 config runs with the legacy struct shape.
- **File:** src/workerd/api/tests/r2-test.wd-test:17

## SUGGESTION (2)

### [AGENTS.md] Add a short R2 JSRPC entry to src/workerd/api/AGENTS.md pointing to the implementation, the backend contract and the tests.
- **File:** src/workerd/io/compatibility-date.capnp:1780

### [Code Quality] uploadPartRpc does not apply the 1..10000 part-number check that the HTTP uploadPart enforces.
- **File:** src/workerd/api/r2-multipart.c++:141

📋 Code Quality: ⚠️ 1 warning · 2 info · 1 suggestion

The earlier range body-length warning is still present; the other notes are minor.

Recommendation: 📝 Minor Comments

  • [WARNING] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it fails. (src/workerd/api/r2-bucket.c++:651)
  • [INFO] The continuation captures the TypeHandler by bare reference, the pattern the workerd-unsafe-continuation-capture check flags. (src/workerd/api/r2-rpc.h:49)
  • [INFO] Removing disable_fast_jsg_struct means no HTTP-transport R2 config runs with the legacy struct shape. (src/workerd/api/tests/r2-test.wd-test:17)
  • [SUGGESTION] uploadPartRpc does not apply the 1..10000 part-number check that the HTTP uploadPart enforces. (src/workerd/api/r2-multipart.c++:141)
View full review

getResultBodyLength ignores offset-only and suffix-only ranges (src/workerd/api/r2-bucket.c++:647-656)

  • The body length is range.length.orDefault(size).
  • headResultFromSerializable (lines 605-620) accepts two ranges this gets wrong:
    • a range with only offset, where the body is size - offset bytes;
    • a range with only suffix, where the body is min(suffix, size) bytes.
  • In both cases the function returns the full size, and that value becomes the length of the identity pipe in ensureBodyLength. The body then ends before its declared length, and reading it fails.
  • No test sends a partial range over RPC.

uploadPartRpc skips the part-number check (src/workerd/api/r2-multipart.c++:132-151)

  • The HTTP path rejects part numbers outside 1..10000 with a TypeError. The RPC path forwards the number unchecked, so the error a caller sees depends on the backend.

Reference capture in a promise continuation (src/workerd/api/r2-rpc.h:49)

  • The .then lambda captures &resultPromiseHandler by bare reference. This is probably safe, because the TypeHandler lives as long as the isolate. It is still the pattern the workerd-unsafe-continuation-capture check flags.

Legacy struct shape no longer tested on the HTTP path (src/workerd/api/tests/r2-test.wd-test:17)

  • disable_fast_jsg_struct was removed from the test worker and the tail worker. No HTTP-transport config now runs with the legacy struct shape.

📖 AGENTS.md: 💬 1 suggestion

Optional pointer to the new R2 JSRPC path in the API guide.

Recommendation: 💬 Optional Nits

  • [SUGGESTION] Add a short R2 JSRPC entry to src/workerd/api/AGENTS.md pointing to the implementation, the backend contract and the tests. (src/workerd/io/compatibility-date.capnp:1780)
View full review

A short entry in src/workerd/api/AGENTS.md would make the new path easier to find. It could point to r2-rpc.{h,c++}, the binding contract in tests/r2-binding-service/ and the related tests.


✅ All other checks passed

🔒 Security: ✅ LGTM

  • R2 resource serialization is limited to JSRPC.
  • Deserialized results are checked for size, range and kind.
  • Inline bodies are capped at 16 MiB; larger bodies are sent as streams.
  • RPC method names come from a fixed set, never from user input.

⚡ Performance: ✅ LGTM

No performance concerns. Inline buffering is bounded, and the pipe setup runs once per result.


📝 Documentation: ✅ LGTM

The new r2_binding_jsrpc flag is experimental and has no enable date. Its doc comment in compatibility-date.capnp describes the backend contract.


Reviewed commit: 0ecd063b

Comment thread src/workerd/api/r2-rpc.h Resolved
Comment thread src/workerd/api/tests/r2-test.wd-test Resolved
Comment thread src/workerd/io/compatibility-date.capnp Resolved
Comment thread src/workerd/api/r2-multipart.c++ Resolved
@jp4a50
jp4a50 force-pushed the jp4a50/r2-jsrpc-bindings branch from 0ecd063 to 69733ad Compare November 2, 2026 22:08

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of adfed1ed.

This review, of 69733ada

💬 Approved with comments — One open WARNING: getResultBodyLength uses the full object size for offset-only and suffix-only ranges. The author has deferred the fix to a later PR. Two INFO notes remain.

Findings: 1 warning · 2 info

Not opened by the correctness review: 2 changed files it was meant to read
  • compile_flags.txt
  • doxyfile

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8114.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @jp4a50 [author] deferred the fix to a later PR; the code is unchanged.
- **File:** src/workerd/api/r2-bucket.c++:651

## INFO (2)

### [Code Quality] The continuation captures the TypeHandler by bare reference, the pattern the workerd-unsafe-continuation-capture check flags.
- **File:** src/workerd/api/r2-rpc.h:49

### [Code Quality] Removing disable_fast_jsg_struct means no HTTP-transport R2 config runs with the legacy struct shape.
- **File:** src/workerd/api/tests/r2-test.wd-test:17

📋 Code Quality: ⚠️ 1 warning · 2 info

One WARNING carried over (ranged get body length over RPC) and two INFO notes; nothing new in the BUILD.bazel change.

Recommendation: 📝 Minor Comments

  • [WARNING] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @​jp4a50 [author] deferred the fix to a later PR; the code is unchanged. (src/workerd/api/r2-bucket.c++:651)
  • [INFO] The continuation captures the TypeHandler by bare reference, the pattern the workerd-unsafe-continuation-capture check flags. (src/workerd/api/r2-rpc.h:49)
  • [INFO] Removing disable_fast_jsg_struct means no HTTP-transport R2 config runs with the legacy struct shape. (src/workerd/api/tests/r2-test.wd-test:17)
View full review

getResultBodyLength ignores offset-only and suffix-only ranges (src/workerd/api/r2-bucket.c++:647-656)

  • The body length is range.length.orDefault(size).
  • headResultFromSerializable accepts two ranges this gets wrong:
    • offset only: the body is size - offset bytes;
    • suffix only: the body is min(suffix, size) bytes.
  • In both cases the function returns the full size, and ensureBodyLength uses that as the identity-pipe length. The body then ends before its declared length, and reading it fails.
  • @​jp4a50 [author] deferred the fix to a later PR, saying it only affects custom backends. The code is unchanged, so this is carried at WARNING.

Reference capture in a promise continuation (src/workerd/api/r2-rpc.h:49)

  • The lambda captures &resultPromiseHandler by bare reference. This is probably safe because the TypeHandler lives as long as the isolate, but it is the pattern workerd-unsafe-continuation-capture flags.

Legacy struct shape no longer tested on the HTTP path (src/workerd/api/tests/r2-test.wd-test:17)

  • disable_fast_jsg_struct was removed from the test worker and the tail worker, so no HTTP-transport config runs with the legacy struct shape any more.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues. Serialization of R2 resources is limited to JSRPC, deserialized results are checked for size, range and kind, inline bodies are capped, and RPC method names come from a fixed set.


📖 AGENTS.md: ✅ LGTM

No new AGENTS.md concerns.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The new r2_binding_jsrpc flag is experimental and has no enable date. Its doc comment describes the backend contract.


Reviewed commit: 69733ada

@jp4a50
jp4a50 force-pushed the jp4a50/r2-jsrpc-bindings branch from 69733ad to adfed1e Compare November 2, 2026 23:30

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of cddf50a9.

This review, of adfed1ed

💬 Approved with comments — One open WARNING: getResultBodyLength uses the full object size for offset-only and suffix-only ranges. The author has deferred the fix to a later PR. Two INFO notes remain.

Findings: 1 warning · 2 info

Not opened by the correctness review: 2 changed files it was meant to read
  • compile_flags.txt
  • doxyfile

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8114.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @jp4a50 [author] deferred the fix to a later PR; the code is unchanged.
- **File:** src/workerd/api/r2-bucket.c++:651

## INFO (2)

### [Code Quality] The continuation captures the TypeHandler by bare reference, the pattern the workerd-unsafe-continuation-capture check flags.
- **File:** src/workerd/api/r2-rpc.h:49

### [Code Quality] Removing disable_fast_jsg_struct means no HTTP-transport R2 config runs with the legacy struct shape.
- **File:** src/workerd/api/tests/r2-test.wd-test:17

📋 Code Quality: ⚠️ 1 warning · 2 info

One WARNING carried over (ranged get body length over RPC) and two INFO notes; nothing new in the BUILD.bazel change.

Recommendation: 📝 Minor Comments

  • [WARNING] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @​jp4a50 [author] deferred the fix to a later PR; the code is unchanged. (src/workerd/api/r2-bucket.c++:651)
  • [INFO] The continuation captures the TypeHandler by bare reference, the pattern the workerd-unsafe-continuation-capture check flags. (src/workerd/api/r2-rpc.h:49)
  • [INFO] Removing disable_fast_jsg_struct means no HTTP-transport R2 config runs with the legacy struct shape. (src/workerd/api/tests/r2-test.wd-test:17)
View full review

getResultBodyLength ignores offset-only and suffix-only ranges (src/workerd/api/r2-bucket.c++:647-656)

  • The body length is range.length.orDefault(size).
  • headResultFromSerializable accepts two ranges this gets wrong:
    • offset only: the body is size - offset bytes;
    • suffix only: the body is min(suffix, size) bytes.
  • In both cases the function returns the full size, and ensureBodyLength uses that as the identity-pipe length. The body then ends before its declared length, and reading it fails.
  • @​jp4a50 [author] deferred the fix to a later PR, saying it only affects custom backends. The code is unchanged, so this is carried at WARNING.

Reference capture in a promise continuation (src/workerd/api/r2-rpc.h:49)

  • The lambda captures &resultPromiseHandler by bare reference. This is probably safe because the TypeHandler lives as long as the isolate, but it is the pattern workerd-unsafe-continuation-capture flags.

Legacy struct shape no longer tested on the HTTP path (src/workerd/api/tests/r2-test.wd-test:17)

  • disable_fast_jsg_struct was removed from the test worker and the tail worker, so no HTTP-transport config runs with the legacy struct shape any more.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues. Serialization of R2 resources is limited to JSRPC, deserialized results are checked for size, range and kind, inline bodies are capped, and RPC method names come from a fixed set.


📖 AGENTS.md: ✅ LGTM

No new AGENTS.md concerns.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The new r2_binding_jsrpc flag is experimental and has no enable date. Its doc comment describes the backend contract.


Reviewed commit: adfed1ed — same changes as 69733ada, so this is that commit's review (no new review was run; line numbers are as of 69733ada)

@jp4a50
jp4a50 force-pushed the jp4a50/r2-jsrpc-bindings branch from adfed1e to cddf50a Compare November 3, 2026 01:16

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 7d9d173f.

This review, of cddf50a9

💬 Approved with comments — One open WARNING: getResultBodyLength uses the full object size for offset-only and suffix-only ranges. The author has deferred the fix to a later PR. Two INFO notes remain.

Findings: 1 warning · 2 info

Not opened by the correctness review: 2 changed files it was meant to read
  • compile_flags.txt
  • doxyfile

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8114.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @jp4a50 [author] deferred the fix to a later PR; the code is unchanged.
- **File:** src/workerd/api/r2-bucket.c++:651

## INFO (2)

### [Code Quality] The continuation captures the TypeHandler by bare reference, the pattern the workerd-unsafe-continuation-capture check flags.
- **File:** src/workerd/api/r2-rpc.h:49

### [Code Quality] Removing disable_fast_jsg_struct means no HTTP-transport R2 config runs with the legacy struct shape.
- **File:** src/workerd/api/tests/r2-test.wd-test:17

📋 Code Quality: ⚠️ 1 warning · 2 info

One WARNING carried over (ranged get body length over RPC) and two INFO notes; nothing new in the BUILD.bazel change.

Recommendation: 📝 Minor Comments

  • [WARNING] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @​jp4a50 [author] deferred the fix to a later PR; the code is unchanged. (src/workerd/api/r2-bucket.c++:651)
  • [INFO] The continuation captures the TypeHandler by bare reference, the pattern the workerd-unsafe-continuation-capture check flags. (src/workerd/api/r2-rpc.h:49)
  • [INFO] Removing disable_fast_jsg_struct means no HTTP-transport R2 config runs with the legacy struct shape. (src/workerd/api/tests/r2-test.wd-test:17)
View full review

getResultBodyLength ignores offset-only and suffix-only ranges (src/workerd/api/r2-bucket.c++:647-656)

  • The body length is range.length.orDefault(size).
  • headResultFromSerializable accepts two ranges this gets wrong:
    • offset only: the body is size - offset bytes;
    • suffix only: the body is min(suffix, size) bytes.
  • In both cases the function returns the full size, and ensureBodyLength uses that as the identity-pipe length. The body then ends before its declared length, and reading it fails.
  • @​jp4a50 [author] deferred the fix to a later PR, saying it only affects custom backends. The code is unchanged, so this is carried at WARNING.

Reference capture in a promise continuation (src/workerd/api/r2-rpc.h:49)

  • The lambda captures &resultPromiseHandler by bare reference. This is probably safe because the TypeHandler lives as long as the isolate, but it is the pattern workerd-unsafe-continuation-capture flags.

Legacy struct shape no longer tested on the HTTP path (src/workerd/api/tests/r2-test.wd-test:17)

  • disable_fast_jsg_struct was removed from the test worker and the tail worker, so no HTTP-transport config runs with the legacy struct shape any more.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues. Serialization of R2 resources is limited to JSRPC, deserialized results are checked for size, range and kind, inline bodies are capped, and RPC method names come from a fixed set.


📖 AGENTS.md: ✅ LGTM

No new AGENTS.md concerns.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The new r2_binding_jsrpc flag is experimental and has no enable date. Its doc comment describes the backend contract.


Reviewed commit: cddf50a9 — same changes as 69733ada, so this is that commit's review (no new review was run; line numbers are as of 69733ada)

@jp4a50 jp4a50 changed the title R2 JSRPC Bindings R2 JSRPC Bindings (double fork edition) Nov 3, 2026
@jp4a50
jp4a50 force-pushed the jp4a50/r2-jsrpc-bindings branch from cddf50a to 7d9d173 Compare November 3, 2026 11:02

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of bbacfd4e.

This review, of 7d9d173f

💬 Approved with comments — One WARNING is still open: the body length is wrong for offset-only and suffix-only ranges. The author has deferred the fix to a later pull request. Nothing new was found in the change since the last review.

Findings: 1 warning

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8114.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @jp4a50 [author] deferred the fix to a later pull request; the code is unchanged.
- **File:** src/workerd/api/r2-bucket.c++:651

📋 Code Quality: ⚠️ 1 warning

One open WARNING: getResultBodyLength gets the body length wrong for offset-only and suffix-only ranges.

Recommendation: 📝 Minor Comments

  • [WARNING] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @​jp4a50 [author] deferred the fix to a later pull request; the code is unchanged. (src/workerd/api/r2-bucket.c++:651)
View full review

getResultBodyLength ignores offset-only and suffix-only ranges (src/workerd/api/r2-bucket.c++:647-656)

  • The function computes the body length as range.length.orDefault(size).
  • headResultFromSerializable accepts two kinds of range that this gets wrong:
    • offset only: the body is size - offset bytes;
    • suffix only: the body is min(suffix, size) bytes.
  • In both cases the function returns the full size. ensureBodyLength then uses that as the identity-pipe length, so the body ends before its declared length and reading it fails.
  • Carried at WARNING: @​jp4a50 [author] deferred the fix to a later pull request, saying only custom backends are affected. The code is unchanged.

compile_flags.txt, doxyfile and types/BUILD.bazel are consistent with the rest of the change. Two earlier informational notes on unchanged code remain open.


✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md concerns.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The new r2_binding_jsrpc flag is experimental and has no enable date.


Reviewed commit: 7d9d173f

- Enabled with compatibility flag r2_binding_jsrpc
@jp4a50
jp4a50 force-pushed the jp4a50/r2-jsrpc-bindings branch from 7d9d173 to bbacfd4 Compare November 3, 2026 12:19

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Approved with comments — One WARNING is still open: the body length is wrong for offset-only and suffix-only ranges, and the author has deferred the fix to a later pull request. The only change since the last review is the new compatibility-flag entry, and it raises no new issues.

Findings: 1 warning

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8114.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @jp4a50 [author] deferred the fix to a later pull request, and the code at this commit is unchanged.
- **File:** src/workerd/api/r2-bucket.c++:651

📋 Code Quality: ⚠️ 1 warning

One WARNING is still open: getResultBodyLength gives the wrong body length for offset-only and suffix-only ranges. The fix has been deferred.

Recommendation: 📝 Minor Comments

  • [WARNING] getResultBodyLength returns the full object size for offset-only or suffix-only ranges, so the body ends before its declared length and reading it over RPC fails. Carried at WARNING: @​jp4a50 [author] deferred the fix to a later pull request, and the code at this commit is unchanged. (src/workerd/api/r2-bucket.c++:651)
View full review

getResultBodyLength ignores offset-only and suffix-only ranges (src/workerd/api/r2-bucket.c++:647-656)

  • The function computes the body length as range.length.orDefault(size).
  • headResultFromSerializable accepts two kinds of range that this gets wrong:
    • offset only: the body is size - offset bytes;
    • suffix only: the body is min(suffix, size) bytes.
  • In both cases the function returns the full size. ensureBodyLength then uses that value as the identity-pipe length, so the body ends before its declared length and reading it fails.
  • Carried at WARNING: @​jp4a50 [author] deferred the fix to a later pull request, saying only custom backends are affected. The code at this commit is unchanged.

The change since the last review, r2BindingsJsrpc @203 in compatibility-date.capnp, uses an ordinal no other entry uses and raises no issues.


✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found. Serialization and deserialization of R2 resources are allowed only in RPC contexts. Range and size metadata are validated before use. Body length is enforced through an identity pipe.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md concerns.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The new r2_binding_jsrpc flag is experimental and has no enable date.


Reviewed commit: bbacfd4e

@jp4a50
jp4a50 merged commit 4379e39 into main Nov 3, 2026
37 of 39 checks passed
@jp4a50
jp4a50 deleted the jp4a50/r2-jsrpc-bindings branch November 3, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants