Skip to content

feat(uploads): report PDFs and covers go straight to R2 - #1699

Merged
sickerine merged 3 commits into
devfrom
feat/uploads-r2
Dec 1, 2026
Merged

sickerine merged 3 commits into
devfrom
feat/uploads-r2

Conversation

@sickerine

Copy link
Copy Markdown
Collaborator

Our Convex address sits behind Cloudflare's proxy, which takes at most 100 MB a request on dev. Supplements and larger reports need Zenodo's limit, 50 GB. This first part moves the report PDF and its cover picture to R2. Extraction, screening, community settings and assistant uploads follow in the next pull requests. Part of #1695.

How an upload goes now

  • Start. The browser asks files/uploads:start for signed addresses. A file up to 64 MB gets one address. A larger one gets an R2 upload in parts, one address per 64 MB part.
  • Send. The browser sends the file straight to the UPLOADS_* bucket (openscholar-uploads-dev on dev), 4 parts at a time and 3 tries a part (lib/files/upload.ts).
  • Finish. files/uploads:finish is only the sender's. It joins the parts and refuses unless R2 holds exactly the size declared.
  • Hand over. The sender may hand a finished file to a report for an hour, for the right purpose, while nothing else holds it.
  • Sweep. An hourly job deletes files nothing took after a day, and uploads never finished after two days.

Reports

  • A report's PDF, the copy its author uploaded beside a PDF with the byline page, its text and its cover are kept in R2.
  • Report fields take a file in R2 or, until migrations/reportFilesToR2 has run, one still in Convex storage. Every reader handles both.
  • An R2 file is never handed out by its own address. /reports/open (files out for everyone) and /reports/file (the workspace and reviewers) check who may have it each time, then redirect to an address signed for 15 minutes. The app's routes follow that redirect as before, ranges included.
  • A withdrawn or private report's R2 file stops being reachable at once, so the old move of files on withdrawal applies only to files still in Convex storage.

Checks

  • npx tsc --noEmit, check:user-actions, check:convex-rules, check:ui-rules
  • npx vitest run convex/reports convex/files convex/migrations: all pass, including new tests for the upload boundary, the sweep and the migration
  • Run for real on a throwaway Convex project, since deleted, against the dev bucket:
    • start signs in Convex's own runtime
    • a browser-style preflight from http://localhost:3685 passes CORS
    • finish refuses a file that hasn't arrived and accepts it once it has
    • a 130 MB file goes up in 3 parts, with R2 exposing each part's ETag to the browser
    • a signed read address answers a range request with the report's file name
    • The test files are deleted from the bucket.
  • Our server uploads to Zenodo's sandbox at about 100 MB/s, so a 50 GB file takes about 8 minutes, inside the 15-minute action limit.

After merge

  1. On dev: npx convex run migrations/reportFilesToR2:run '{"dryRun":true}', then with false.
  2. On prod at promotion: create its bucket (openscholar-uploads-prod) with CORS for discover.openscholar.ai, a token scoped to it, and the four UPLOADS_* settings. Then run the same migration.

The browser asks Convex for signed addresses (files/uploads:start) and sends a file straight to the uploads bucket,
in 64 MB parts when it is larger, so no upload goes through our proxy, which takes at most 100 MB a request on dev.
files/uploads:finish checks R2 holds all of it. A file is its sender's to hand to a report for an hour; one nothing
takes is swept away after a day, as is an upload never finished.

A report's PDF, the one its author uploaded beside a PDF with the byline page, its text and its cover are kept in R2.
Report fields take a file in R2 or, until migrations/reportFilesToR2 has run, one still in Convex storage. A file in
R2 is never handed out by its own address: /reports/open and /reports/file check who may have it each time and send
them on to an address signed for 15 minutes.

Part of #1695.
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d11d93f8-bafc-4ce6-9063-fd91ecf5109e
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T22:08:06.898060Z 955b77b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 955b77b1f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread convex/files/r2.ts Resolved
Comment thread convex/files/read.ts Resolved
…d by the address it came by, and nothing is left in R2 that no row names

- A file sent with one PUT is copied, once checked, to a key no address was signed for; the copy it was sent as is
  deleted. Files sent in parts need no copy: once joined, their addresses write to nothing.
- A report's file is served as a PDF or a JPEG whatever it was sent as.
- A deleted file's row stays, dropping, until R2 has let its bytes go; the sweep tries a failed delete again.
- A file the server makes gets its row before its bytes, and nothing holds it until the function it was made for
  takes it, so one whose maker failed is swept too.
- Kept files nothing took are swept by when they arrived, not when they were started.
- The migration copies in Node, which holds a 100 MB PDF, and a report's text claim is deleted with it.
…it said; only a file it doesn't hold reads as gone
@sickerine
sickerine merged commit 7631ae7 into dev Dec 1, 2026
6 checks passed
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.

1 participant