Skip to content

feat(upload): implement concurrent file uploads with improved progres… - #792

Merged
pikann merged 3 commits into
masterfrom
feature/implement-concurrency-file-uploads
Nov 19, 2026
Merged

pikann merged 3 commits into
masterfrom
feature/implement-concurrency-file-uploads

Conversation

@pikann

@pikann pikann commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Uploads now run in parallel at two levels, in the web app only.

  • Multipart parts: files over 5 MiB are split into parts, and up to 4 parts per file upload at once instead of one after another. This applies to the Files page (files-api.ts) and task attachments (attachment-api.ts). Progress is the sum across parts.
  • Failure and cancel: in 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.
  • Task attachments: picking or dropping many files used to start every upload at once. They are now capped at 3 concurrent files and the rest queue.
  • Files page: it already uploaded 3 files at a time, so batch behavior there is unchanged.

New helpers in lib/concurrency.ts: mapPool (bounded-concurrency map that stops on first failure) and createLimiter (queueing semaphore).

Notes

  • Limits are constants: MULTIPART_CONCURRENCY = 4 in both API files, 3 concurrent files for attachments.
  • The attachment multipart path uses 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 -b and Biome pass.
  • Not yet exercised against a real object store or in the browser.

@pullfrog pullfrog 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.

ℹ️ 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 — new mapPool (bounded concurrency, input-order results, stops starting after the first failure) and createLimiter (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 via partsController while the original error is preserved over sibling UploadAbortedErrors.
  • 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment thread apps/web/src/lib/concurrency.ts Resolved
Comment thread apps/web/src/lib/attachment-api.ts Resolved

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Incremental review of 672db7c → 359cd74:

  • Doc uploads go concurrent — uploadDocFile now runs multipart parts through mapPool with DOC_MULTIPART_CONCURRENCY = 4 instead of a sequential loop. Results keep input order, so CompleteMultipartUpload still 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.ts pins 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, and biome check is 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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ 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 — fn now receives a signal that fires on the first item failure (or when the new optional outerSignal aborts), and controller.abort() runs only after firstError is recorded, so the real failure still beats sibling UploadAbortedErrors. That is the invariant file-uploads.ts relies on, and this ordering is strictly safer than the old abort-then-rethrow in the item body.
  • Simplified files-api.ts — its private partsController and outer-signal listener are gone; opts.signal is passed straight to mapPool, and cancel still surfaces as UploadAbortedError.
  • Extended sibling abort to docs and attachments — both fetch calls 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.ts and 6 files-api.test.ts tests pass locally, and biome check is clean on the five touched files.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann
pikann merged commit c6f787a into master Nov 19, 2026
2 checks passed
@pikann
pikann deleted the feature/implement-concurrency-file-uploads branch November 19, 2026 15:41
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