Skip to content

fix(patchy): a tier 2 file write over the cap is refused as too_large at any size - #689

Merged
allisonmahmood merged 2 commits into
mainfrom
fix/605-guest-file-cap
Oct 15, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
fix/605-guest-file-cap

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

A tier 2 action that put a file over 32 MiB got a generic error instead of too_large. workerd limits serialized RPC arguments to 32 MiB, so the body never reached the loader's 20 MiB check: the RPC threw inside the guest, a handler that caught it saw a plain Error ("Serialized RPC arguments or return values are limited to 32MiB…"), and an uncaught one replied handler_failed.

The guest's shared callback routine now refuses a body over GuestProtocol.callbackFileLimit before the RPC, with the loader's own refusal, through the existing refusal registration. That covers Uint8Array, ArrayBuffer and Blob inputs, measured after conversion to bytes. The refusal body moves to GuestProtocol.callbackFileTooLarge, so the loader, supervisor and guest give the same one by construction. The loader, supervisor and gateway still enforce the cap; the guest's check only improves the error.

A new Engine test runs through real workerd. A 32 MiB + 1 Uint8Array put and a 40 MiB Blob put each reply with exactly the loader's refusal, and neither reaches the host. A handler that catches the 32 MiB + 1 refusal sees the same PatchyError as one that catches the same refusal returned through the loader's RPC; the test's host refuses a small put the way the supervisor does. Without the guest change, the test fails with handler_failed. The existing cap test still covers 20971520 bytes stored and 20971521 refused.

Tested by hand

pnpm dev up team, then a tier 2 patch under patchy dev whose action puts N bytes as a Uint8Array or Blob, with and without catching. Before → after, as the handler and the viewer saw it:

Put Before After
33 MiB Uint8Array, caught Error: "Serialized RPC arguments or return values are limited to 32MiB, but the size of this value was: 34603184 bytes." PatchyError too_large, scope: "viewer", limitId: "tier2.callbacks.fileBytes", value: 20971520, operation: "files.put", 2 ms in the handler
40 MiB Blob, caught the same RPC Error (41943215 bytes) the same too_large refusal, 65 ms in the handler
20971520 B Uint8Array stored stored
20971521 B Uint8Array, caught too_large as above unchanged, identical to the 33 MiB error

For the uncaught puts, the server's invocation record showed callbacks: 0 and durationMs: 17: the body never reached the host and nothing waited on a deadline.

Not changed: an uncaught over-cap put still reaches the viewer as handler_failed

This was true before the change at every size over the cap, including 20971521 bytes. The host relays a guest's source: "patchy" refusal only if the host itself issued it to that attempt (packages/runtime/src/Invocation.ts), and it never sees the loader's or the guest's local file refusal. So the issue's "the viewer correctly gets too_large" between 20 and 32 MiB holds for the guest's reply, which the acceptance tests check through workerd, but not for the viewer. Letting the host trust this one static refusal from a guest changes its trust rule, so it needs its own decision rather than riding along here.

Surfaces

  • Wire contract: only the private guest wire (@patchy/api/guest) gains callbackFileTooLarge; nothing public, so docs/API.md is unchanged.
  • CLI, skills, product and glossary: no command, flag or concept changed. docs/API.md, docs/product.md and the patchy-server, patchy-files and patchy-shared-stores skills already say an over-cap file is too_large; this makes that true at every size.
  • Dev loop, migrations, company resources, served pages, reverse states, repo layout: not touched.

Closes #605

Made by Claude Opus 5.5 in Claude Code, running in T3 Code.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

GPT 6.1 Sol (xhigh, one pass) reviewed git diff origin/main...HEAD before this PR opened.

  • Low, fixed in 146b342: the caught-error comparison compared two refusals that both stopped in the guest (20 MiB + 1 is now refused there too), so it never checked the guest's refusal against one that crossed the RPC. The test's host now refuses a small put the way the supervisor does (413 with GuestProtocol.callbackFileTooLarge), and the test asserts the handler sees the same PatchyError for that RPC-delivered refusal as for the guest's 32 MiB + 1 refusal.
  • Not changed: the new workerd test doesn't put an ArrayBuffer. Sol called the conversion correct by inspection, and existing tests cover small inputs of all three types; the acceptance criteria name only Uint8Array and Blob.
  • No other findings. Sol rated correctness fine (all three inputs are measured as bytes, 20971520 allowed and 20971521 refused, allowed bodies unchanged), found no missed surfaces, called callbackFileTooLarge a justified extraction rather than scope creep, and agreed the viewer's handler_failed from the host's relay rule is out of scope and should be tracked separately.

@github-actions github-actions Bot added area:server Touches the server area area:cli Touches the cli area size:s Under 100 changed lines labels Oct 15, 2026
… at any size

workerd limits serialized RPC arguments to 32 MiB, so a file body over that
never reached the loader's 20 MiB check: the RPC threw inside the guest and a
handler saw a generic Error instead of the too_large refusal.

The guest's callback routine now gives the loader's refusal itself for a body
over GuestProtocol.callbackFileLimit, before the RPC. The refusal body moves to
GuestProtocol.callbackFileTooLarge so the loader, supervisor and guest share
it. The loader, supervisor and gateway still enforce the cap.

Closes #605

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed the RPC

Both sizes in the caught comparison stopped in the guest, so it never checked
the guest's refusal against a reply from the loader. The test's host now
refuses as the supervisor does, so a small put's refusal crosses the RPC.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 2f9b213 into main Oct 15, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the fix/605-guest-file-cap branch October 15, 2026 19:55
allisonmahmood added a commit that referenced this pull request Oct 16, 2026
…u when they fail (#720)

Release 13's What's new entry, written from `c9b8fc4`, ahead of
deploying it. `patchy` and `CURRENT_RELEASE` move to `0.13.0`, so CLIs
and patch repos installed before this deploy are told to upgrade.

| Change | PRs |
| --- | --- |
| New: Home puts the patches you use first | #713, #716, #719 |
| New: Every patch in one list | #715 |
| Improved: Each patch's page leads with Open | #717 |
| New: See when your tools are failing | #718 |
| Fixed: Everyone has a name | #687 |
| Improved: Your company's look is easier to get right | #697, #696,
#703, #688 |
| Improved: Forms follow your look's error states | #691, #692 |
| Improved: Clearer answers when a publish goes wrong | #686, #685, #689
|
| Fixed: Your agent's Patchy commands are steadier | #695, #704, #680,
#681 |
| Behind the scenes: stricter checks on static pages and tools' database
requests; malformed requests are logged | #682, #693, #683 |
| Behind the scenes: usage numbers count every publish, sharing change
and restore | #698, #699, #700, #690 |
| Test and tooling only, no line | #705, #702, #701, #694, #684, #607 |

Made by Claude Opus 5.5 in Claude Code, running in T3 Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Touches the cli area area:server Touches the server area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(patchy): a tier 2 file write over 32 MiB fails with handler_failed instead of too_large

1 participant