Skip to content

fix(upload): harden upload progress and terminal-state handling#2117

Open
joshtrichards wants to merge 2 commits into
nextcloud-libraries:mainfrom
joshtrichards:jtr/harden-upload-tracking
Open

fix(upload): harden upload progress and terminal-state handling#2117
joshtrichards wants to merge 2 commits into
nextcloud-libraries:mainfrom
joshtrichards:jtr/harden-upload-tracking

Conversation

@joshtrichards

@joshtrichards joshtrichards commented Jun 19, 2026

Copy link
Copy Markdown

This PR hardens upload progress tracking across Upload and Uploader by ignoring stale byte-progress updates once uploads enter assembling or terminal states.

  • guard the Upload.uploaded setter against updates once the upload enters ASSEMBLING, CANCELLED, FAILED, or FINISHED (this is the authoritative state gate)
  • add matching short-circuit guards in Uploader callback sites (onUploadProgress, onUploadRetry, and chunk .then()) when the upload is already in a non-updatable state (to avoid unnecessary updateStats() calls; primary protection is already provided by the new guard in Upload.uploaded)
  • clamp tracked uploaded bytes to the valid 0..size range to keep progress reconciliation safe during retries and async updates
  • deduplicate the getMaxChunksSize() call in the Upload constructor (was called three times; now called once and a tad more natural to read)
  • fix inconsistent this.eta.reset() -> this._eta.reset() in updateStats()
  • tighten Upload.status getter return type from number to Status
  • improve JSDoc comments throughout Upload

This primarily hardens upload state transitions against late async progress callbacks, which can otherwise cause transient progress or ETA inconsistencies around retries, cancellation, and chunk assembly.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI [used for initial implementation analysis, brainstorming, sanity checking, and preliminary review]

- ignore stale progress updates after assembling or terminal states
- clamp tracked uploaded bytes to the valid range
- tighten Status typing on the status getter
- improve Upload model documentation and inline comments

Signed-off-by: Josh <josh.t.richards@gmail.com>
- ignore stale progress updates after uploads reach terminal states
- avoid unnecessary progress mutations and stats recalculations from late async callbacks
- preserve existing retry and queue orchestration behavior

Signed-off-by: Josh <josh.t.richards@gmail.com>
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