Skip to content

feat(web): add bounded buffered file uploads - #1407

Closed
purplelight wants to merge 2 commits into
e2e-inc:mainfrom
purplelight:codex/buffered-native-filechooser
Closed

purplelight wants to merge 2 commits into
e2e-inc:mainfrom
purplelight:codex/buffered-native-filechooser

Conversation

@purplelight

@purplelight purplelight commented Oct 27, 2026 •

Copy link
Copy Markdown
  • Add web({ fileUploads: 'buffered' }) for tests that inspect multipart request bytes before forwarding. Chromium can omit disk-backed file bytes from intercepted request bodies; replaying that body can truncate the upload.
  • Read the selected files through bounded regular-file handles, then hand their actual bytes to Playwright's native file-payload API. No HTTP body or destination is rewritten. Path-based uploads remain the default, including their existing large-file behavior.
  • Buffered mode limits the selection to 32 files and 2,000,000 bytes. It refuses symlinks, files changed during reading, oversized selections and PDF extensions without a PDF header. It uses basenames and normal MIME lookup. Payload lastModified follows Playwright's current-time behavior, documented as opt-in.
engine: web({ fileUploads: 'buffered' })

The common preparation helper can also serve the preferred button-upload path in #958. This PR contains none of the closed #1386 chooser-node workflow. It grants no upload destination or mutation permission and changes no redirect policy.

Issue

Related to the native upload work in #954 and #958. This addresses the separate file-byte omission seen when a guarded caller inspects and replays multipart bodies.

Verified

Ran it locally: yes, deterministic Chromium and owned loopback HTTP, Playwright1.64.1 and Node24.19.0.

  • pnpm --filter @e2e-dev/web exec vitest run tests/unit/upload-files.test.ts tests/unit/actions.test.ts tests/unit/protected-app-options.test.ts tests/integration/buffered-upload.test.ts: 72 checks passed in independent review. The server verifies the selected binary file's exact bytes, name, size and SHA. The page receives200, and a307 response is not followed.
  • Core/web builds and package typecheck passed, including public negative type checks. File-change, pathname replacement, cancellation after reads/cleanup, aggregate byte/count bounds and the default no-read path have regression coverage. A real file-close preparation delay times out before any native call as NOT_ACTIONABLE; a started native call that hangs remains ACTION_MAY_HAVE_COMMITTED. The old classifier fails this causal control,12pass/1fail. Non-upload classification and cancellation remain unchanged.
Native multipart control Path/default Buffered
Intercepted selected file File content omitted Exact selected bytes present
Strict byte guard Refuses before forwarding Accepts exact name/size/SHA
Owned server No upload forwarded Exact bytes received once
Redirect follow No change 307 target never reached

These are native protocol and source checks, not a real-agent or production-application pass. Full CLI/testbed/benchmark and model verification have not run for this change; no model or production call was made. A separate real-agent loopback allocation is planned before any application opts in. The complete application upload failures remain retained.

@mintlify

mintlify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 881d6ff.

Approve preview

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 15 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread docs/reference/web.mdx Resolved
Comment thread packages/web/src/actions.ts Resolved

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. The integration control is good: it shows Chromium leaving disk-backed file bytes out of route.request().postDataBuffer(), so the underlying problem is real. Before the code questions, there is a product question.

For the maintainer

  • No issue is linked, and I found no issue where we agreed on this feature. Under the community policy, a new web() option needs agreement on an issue first. #954 and #958 deal with upload buttons and file choosers, which is a different problem.
  • I don't think we have an in-repo caller that hits the problem. The public WebRoute (packages/web/src/browser.ts:80) exposes postData as a string, and it has no fetch. continue() with no overrides already forwards the original body, file bytes included. Losing bytes requires raw Playwright through surfaceOf() plus route.fetch() or a replayed body, which is exactly what the integration test does. Should we add an engine-wide mode for that consumer?
  • Playwright parity: Playwright solves this per call. setInputFiles accepts { name, mimeType, buffer } payloads. Our locator.setInputFiles (packages/e2e/src/types.ts:540) only takes paths. If we want this at all, payload support on setInputFiles is the Playwright-shaped primitive. The global fileUploads: 'buffered' switch is not.

Must fix (if the feature is accepted)

  1. upload-files.ts:67 refuses any .pdf file that does not start with %PDF-. That check guesses validity from the file extension, and it breaks a common test: uploading a malformed PDF to check that the app rejects it. Your own unit test not-a-pdf.pdf shows the refusal. Please remove it.
  2. upload-files.ts:43,48,61-63 add a second file policy inside the engine: no symlinks, regular files only, and dev/ino/size/mtime/ctime compared across 3 stats. Core already decides which files may be uploaded (packages/e2e/src/agent/upload-paths.ts: inside the project root, symlinks resolved, regular files only). Path mode follows symlinks, so switching modes changes which files are allowed. Reading the file once and refusing it only when the byte count differs from stat.size is enough.
  3. upload-files.ts:24 uses one fixed message for count, size, symlink, changed file, PDF and I/O failures alike. A user has no way to tell which limit they hit. Paths stay out of observations if you name the cause without the path, e.g. "buffered upload exceeds 2000000 bytes" or "buffered upload allows at most 32 files".
  4. surface.ts:869-888 plus actions.ts:109-110 add a mutable uploadDispatched closure flag, an onUploadDispatch callback threaded positionally through dispatchLocatorAction, and a special case in the error classifier, all so that a timeout during preparation does not count as ACTION_MAY_HAVE_COMMITTED. A simpler approach: prepare the payloads in perform before this.guard(...), then pass the ready files to the action. A preparation failure then never enters the action guard, and the flag, the callback and the classifier branch can all go. surface.ts is already 1142 lines on main, so please don't add special cases to it.
  5. The timeout budget is applied twice. actions.ts:168 wraps the work in withConnectionBudget, and prepareUploadFiles wraps it again at upload-files.ts:35. Keep one. Also drop the mode parameter and the 'path' branch (upload-files.ts:33). The caller already branches on the mode, so that branch is reached only by tests, and dropping it also removes the string[] | BufferedFile[] return union.
  6. upload-files.ts:74: handle.close().catch(() => { throw refused(); }) inside finally replaces the real error, and it fails an upload whose read already succeeded if only the close fails. Let close errors through, or ignore them.
  7. pnpm check fails because packages/web/tests/types/upload-files.ts is never reached from an entry point (fallow reports it as an unused file). Add it to entry in .fallowrc.json next to the other packages/web/tests/types/* files.
  8. Integration tests: only the first case (upload('buffered')) runs the engine change. I checked this by switching the engine back to path mode: that case failed and the other three still passed. The nativeChooser cases call prepareUploadFiles and chooser.setFiles directly. The redirect case checks the test's own route.fetch({ maxRedirects: 0 }), which no code in this PR can affect. Please drive the cases through surface.perform, drop the redirect case, and write the shared setup as ordinary multi-line code instead of the 80-line function with boolean flags and several statements per line.

Nits

  1. docs/reference/web.mdx:378-399 describes Chromium internals, a "future native chooser implementation" and "redirect and request admission policy". Keep only what a user needs: what the option does, the limits, and the lastModified change. Trim the setup.md row the same way.
  2. engine.ts:84 validates inline. The other options use validate* helpers. Also, fileUploads was added first in WEB_OPTION_KEYS and WebOptions, which reorders the existing unknown-key error message. Add it at the end.
  3. Please name the 2,000,000-byte and 32-file limits in the docs, and say why those numbers. As written they look arbitrary.

This was an automated review.

@KrzysztofMoch

Copy link
Copy Markdown
Member

Thanks for this

I'm closing this because we're solving it per call instead of with an engine-wide mode. #1883 is adding in-memory payloads to locator.setInputFiles ({ name, mimeType, buffer }, as in Playwright), which gives a test the exact bytes without a new web() option or the size and file-type limits a global mode needs.

If #1883 doesn't cover your case once it lands, please open an issue describing the test you're writing and we'll look at what's missing.

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.

3 participants