fix(upload): align client precheck with optional public max MB - #1069
Conversation
…ing (FV-04) An over-limit guideline PDF was transferred in full before the server answered 413 — on a large file over a clinic connection that is a long wait for a guaranteed rejection, with the limit itself never stated anywhere in the UI. - New dependency-free `src/lib/upload-limits.ts` holds the ceiling so a client component can import it; `src/lib/http.ts` (next/server) and `src/lib/env.ts` (server-only secrets) both can't cross into the bundle. - `env.MAX_UPLOAD_MB` now derives its cap and default from that constant, so the configured limit can only ever be *lower* than what the client rejects up front — the pre-check can never refuse a file the server would have accepted, and the server stays the authority. - `UploadPanel` skips an over-ceiling file with the server's own 413 wording (shared message builder, so the two can't diverge) and still uploads the rest of the batch, matching per-file outcome semantics. - The file field states "PDF only, up to 150 MB per file", wired via aria-describedby so it is announced, not just visible. The ingress pin in tests/upload-ingress-limits.test.ts now asserts the constant's value plus env's derivation from it, keeping the 151mb proxy envelope tied to the same number. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Expose NEXT_PUBLIC_MAX_UPLOAD_MB via getClientMaxUploadMb() so DocumentManagerPanel rejects/hints at a lowered operator limit instead of always using the 150 MB ceiling; server env.MAX_UPLOAD_MB remains authoritative. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughThe change adds shared client upload-limit helpers, rejects oversized files before upload, exposes an accessible limit hint, adds DOM coverage, and wires ChangesClient upload pre-check
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant UploadPanel
participant upload_limits
participant UploadAPI
User->>UploadPanel: select files
UploadPanel->>upload_limits: validate each file size
alt oversized file
upload_limits-->>UploadPanel: limit exceeded
UploadPanel-->>User: show failed outcome
else valid file
UploadPanel->>UploadAPI: upload file
UploadAPI-->>UploadPanel: return upload result
end
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
#1064 was squash-merged, so this branch's own FV-04 commits are not ancestors of main even though their content is. That made every FV-04 file an add/add or content conflict against main's squashed copy. Verified before resolving that main's version of all six FV-04 files is byte-identical to the state merged as #1064 (git diff d51e2fb origin/main was empty for each), so main contributed no new content to them and the branch side is the correct resolution. The three resolved files are byte-identical to the pre-merge branch tip c023b92, leaving only the NEXT_PUBLIC_MAX_UPLOAD_MB work as this PR's delta. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:ab53ff0925
ℹ️ 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".
Uh oh!
There was an error while loading. Please reload this page.
BigSimmo
commented
Jul 22, 2026
@codex resolve actionable Codex review findings for this pull request and current head using the repository instructions. This is the pull request's single automatic repair pass: do not perform a fresh review, create new standalone findings, or request another review. Work only the existing unresolved Codex threads on the current head. Always fix P0 and P1 findings. For P2 and lower findings, fix only clear, scoped, low-risk issues; otherwise disposition them with a concise reason. After fixing or dispositioning a thread, reply in that thread with as the first line, followed by a concise summary; that marker authorizes the workflow to close that exact thread. If human input or new authorization is required, do not use the marker and leave the thread open with the blocker. Finish only after every actionable thread is fixed or dispositioned and closed, or explicitly left open for a human decision. Do not update the branch from main, address unrelated reviews, broaden scope, or create more than one scoped fix commit. Do not use external APIs, paid services, credentials, dependency changes, or broad refactors unless explicitly authorized. Add targeted tests where behavior changes and run the narrowest relevant validation. |
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:0900a1e416
ℹ️ 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".
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:ee6d038374
ℹ️ 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".
Uh oh!
There was an error while loading. Please reload this page.
BigSimmo
commented
Jul 22, 2026
@codex please resolve the merge conflict for me and commit and push it |
Summary
Testing
|
Add NEXT_PUBLIC_MAX_UPLOAD_MB ARG/ENV + CI build-arg so lowered upload limits inline at image build time, and stub the env empty in default DOM cases so inherited shell values cannot flake the 150 MB assertions. Co-authored-by: Cursor <cursoragent@cursor.com>
…66' into run-pr/1069-fix
Summary
getClientMaxUploadMb()/NEXT_PUBLIC_MAX_UPLOAD_MB(clamped to ceiling) for DocumentManagerPanel hint + precheck; serverenv.MAX_UPLOAD_MBstays authoritative.NEXT_PUBLIC_MAX_UPLOAD_MBthrough DockerARG/ENVand docker-image CI build-args so Railway/Docker builds can inline a lowered limit.NEXT_PUBLIC_MAX_UPLOAD_MBin DOM testbeforeEachso inherited shell/CI env cannot flake default-limit assertions..env.exampleand deployment docs for build-time mirroring.Verification
node scripts/run-vitest.mjs run tests/upload-size-precheck.dom.test.tsx(prior Codex pass; re-run in CI)Risk and rollout
NEXT_PUBLIC_MAX_UPLOAD_MBis not rebuilt whenMAX_UPLOAD_MBis lowered — mitigated by Docker build-arg wiring and docs.Clinical Governance Preflight
Document-access / upload path touch (private guideline PDF uploads), not answer generation or retrieval.
Clinical KB Database(sjrfecxgysukkwxsowpy)Test plan
node scripts/run-vitest.mjs run tests/upload-size-precheck.dom.test.tsxNEXT_PUBLIC_MAX_UPLOAD_MB=50, confirm 51 MB file is rejected locallyRAG impact: no retrieval behaviour change — upload UI limit wiring only.