Skip to content

fix(progress): clamp loaded to total for computable upload/download events#7458

Merged
jasonsaayman merged 5 commits intoaxios:v1.xfrom
aviu16:codex/fix-7232-react-native-progress-clamp
Apr 9, 2026
Merged

fix(progress): clamp loaded to total for computable upload/download events#7458
jasonsaayman merged 5 commits intoaxios:v1.xfrom
aviu16:codex/fix-7232-react-native-progress-clamp

Conversation

@aviu16
Copy link
Copy Markdown
Contributor

@aviu16 aviu16 commented Feb 28, 2026

Summary

  • clamp loaded to total in progressEventReducer when lengthComputable is true
  • prevent negative/inflated progress byte deltas in overflow/out-of-order progress events
  • add regression tests for overflow (loaded > total) and out-of-order progress events

Why

Issue #7232 reports onUploadProgress.progress values above 100% in React Native. This happens when progress events report loaded larger than total.

Testing

  • npm run test:mocha -- test/unit/helpers/progressEventReducer.js

Fixes #7232

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Confidence score: 4/5

  • Only a moderate test gap: test/unit/helpers/progressEventReducer.js has an ineffective assertion for negative byte deltas, so out-of-order events aren’t being validated and a regression could slip through.
  • Overall risk is limited to test coverage rather than runtime behavior, so this looks safe to merge with minor follow-up.
  • Pay close attention to test/unit/helpers/progressEventReducer.js - strengthen the negative delta/out-of-order event test to catch regressions.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="test/unit/helpers/progressEventReducer.js">

<violation number="1" location="test/unit/helpers/progressEventReducer.js:22">
P2: Ineffective test assertion for negative byte deltas; misses out-of-order event simulation</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread test/unit/helpers/progressEventReducer.js Outdated
@aviu16
Copy link
Copy Markdown
Contributor Author

aviu16 commented Feb 28, 2026

Follow-up: addressed test coverage concern by adding an explicit out-of-order event case in (with decreasing between events) to assert non-negative byte deltas and clamped progress behavior.

@aviu16
Copy link
Copy Markdown
Contributor Author

aviu16 commented Feb 28, 2026

Correction: I pushed a follow-up test update covering an out-of-order progress event (loaded decreases between events) and asserting non-negative byte deltas with clamped progress.

@aviu16
Copy link
Copy Markdown
Contributor Author

aviu16 commented Feb 28, 2026

Maintainer note on scope vs prior attempt:

  • This patch fixes the clamp at the shared progress reducer layer (lib/helpers/progressEventReducer.js), not only one adapter hook.
  • That means the clamp behavior is centralized for computable progress events across adapter call sites that use this reducer.
  • It also guards byte deltas against out-of-order events (Math.max(0, loaded - bytesNotified)), which avoids negative bytes in callback payloads.
  • Added regression test coverage in test/unit/helpers/progressEventReducer.js for both overflow (loaded > total) and out-of-order event sequences.

If maintainers prefer, I can also add a narrow adapter-level assertion on top of the reducer test, but I kept this patch focused to minimize risk.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="test/unit/helpers/progressEventReducer.js">

<violation number="1" location="test/unit/helpers/progressEventReducer.js:25">
P2: Test assertion for `last.bytes` is too permissive. Using `assert.ok(last.bytes >= 0)` passes for both buggy (40 bytes) and correct (20 bytes) implementations. Should use `assert.strictEqual(last.bytes, 20)` to verify the fix for inflated progress byte deltas.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread test/unit/helpers/progressEventReducer.js Outdated
@aviu16
Copy link
Copy Markdown
Contributor Author

aviu16 commented Feb 28, 2026

Addressed: I tightened the test assertion (expected bytes delta is now exact, not permissive) and updated reducer bookkeeping so bytesNotified remains monotonic across out-of-order events. This keeps clamped progress correct and avoids inflated byte deltas after loaded decreases.

@aviu16
Copy link
Copy Markdown
Contributor Author

aviu16 commented Mar 1, 2026

Quick follow-up: this is ready from my side and includes regression coverage for out-of-order progress events. If you want any scope adjustment, I can update immediately.

@aviu16 aviu16 force-pushed the codex/fix-7232-react-native-progress-clamp branch from 4f351b7 to 8627bee Compare March 1, 2026 19:10
@aviu16
Copy link
Copy Markdown
Contributor Author

aviu16 commented Mar 1, 2026

Rebased onto latest v1.x and force-pushed after the recent follow-up fixes. This should clear the branch-behind state; ready for maintainer review.

@jasonsaayman
Copy link
Copy Markdown
Member

Thanks @aviu16 this looks good to me 🔥

@jasonsaayman jasonsaayman merged commit 914bc26 into axios:v1.x Apr 9, 2026
22 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.

Inflated loaded value in onUploadProgress — react native

2 participants