Repository navigation
feat(upload): implement concurrent file uploads with improved progres… - #792
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions inline.
Approach: sound — one bounded-concurrency helper (mapPool) plus a queueing limiter, wired only into the upload paths the PR targets, so the change stays local and the existing batch logic on the Files page is left alone.
Reviewed changes
lib/concurrency.ts— newmapPool(bounded concurrency, input-order results, stops starting after the first failure) andcreateLimiter(queueing semaphore).lib/files-api.ts— multipart parts now upload 4 at a time with per-part progress summed into one total; a failed part aborts its siblings viapartsControllerwhile the original error is preserved over siblingUploadAbortedErrors.lib/attachment-api.ts— multipart parts upload 4 at a time with summed progress; whole-file uploads are capped at 3 concurrent through a module-level limiter.
ℹ️ Doc file uploads still upload parts one at a time
uploadDocFile in apps/web/src/lib/doc-api.ts:598 keeps the old sequential loop, so large files inserted into a doc (BlockNote's uploadFile in doc-editor.tsx) don't get the speedup. Now that mapPool exists, switching it is small — worth deciding whether that's an intentional follow-up or should ride along here.
Technical details
# Doc uploads still sequential
## Affected sites
- `apps/web/src/lib/doc-api.ts:598` — `uploadDocFile` still loops `for (const part of parts) { ... await fetch(...) }`.
- `apps/web/src/components/projects/docs/doc-editor.tsx:157` — BlockNote `uploadFile` for docs goes through `uploadDocFile`.
## Required outcome
- Either adopt `mapPool` for doc multipart uploads or note in the PR body that it is a deliberate follow-up, so the omission does not read as an oversight.deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 672db7c → 359cd74:
- Doc uploads go concurrent —
uploadDocFilenow runs multipart parts throughmapPoolwithDOC_MULTIPART_CONCURRENCY = 4instead of a sequential loop. Results keep input order, soCompleteMultipartUploadstill receives ascending part numbers, and the trade-offs (no progress callback, no sibling abort) match the attachment path. - Concurrency helpers get tests — new
concurrency.test.tspins input-order results, the in-flight cap, first-error-wins with stop-starting, empty input, and slot release after a failure. All 6 tests pass, andbiome checkis clean on the touched files. - Limiter scope documented — the attachment limiter comment now states the 3-file cap is app-wide and shared with pastes from other surfaces.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
…r concurrent uploads
There was a problem hiding this comment.
✅ No new issues found.
Approach: sound — the part-cancellation wiring moved into mapPool (a shared per-call AbortSignal plus an optional outerSignal), so all three multipart paths abort siblings on the first failure without each caller owning a controller of its own.
Reviewed changes
Incremental review of 359cd74 → b0d3565:
- Centralized part abort in
mapPool—fnnow receives asignalthat fires on the first item failure (or when the new optionalouterSignalaborts), andcontroller.abort()runs only afterfirstErroris recorded, so the real failure still beats siblingUploadAbortedErrors. That is the invariantfile-uploads.tsrelies on, and this ordering is strictly safer than the old abort-then-rethrow in the item body. - Simplified
files-api.ts— its privatepartsControllerand outer-signal listener are gone;opts.signalis passed straight tomapPool, and cancel still surfaces asUploadAbortedError. - Extended sibling abort to docs and attachments — both
fetchcalls now pass the pool's signal, so a failed part cancels the other in-flight PUTs instead of letting them finish. - Closed a limiter over-subscription race —
createLimiter.release()hands the slot directly to the next queued waiter rather than decrementing first, so a call arriving in the gap can no longer exceed the cap; fractional and non-positive limits are clamped to 1. - Pinned the new behavior with tests — four new cases cover sibling abort, outer-signal abort, limit clamping, and the release race. All 10
concurrency.test.tsand 6files-api.test.tstests pass locally, andbiome checkis clean on the five touched files.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Summary
Uploads now run in parallel at two levels, in the web app only.
files-api.ts) and task attachments (attachment-api.ts). Progress is the sum across parts.files-api.ts, a failed part aborts its sibling parts, and the original error is reported rather than a "cancelled" one. Cancelling still aborts all in-flight parts.New helpers in
lib/concurrency.ts:mapPool(bounded-concurrency map that stops on first failure) andcreateLimiter(queueing semaphore).Notes
MULTIPART_CONCURRENCY = 4in both API files, 3 concurrent files for attachments.fetch, so a part's progress only counts once that part finishes (unchanged from before). Moving it to the XHR helper would give smooth progress; left out of scope.Testing
tsc -band Biome pass.