Skip to content

fix(foundation): prevent Backoff::Linear integer overflow and restore dead DegradationLadder test#1580

Open
vivekrajsingh04 wants to merge 1 commit intomofa-org:mainfrom
vivekrajsingh04:fix/linear-backoff-overflow-dead-test
Open

fix(foundation): prevent Backoff::Linear integer overflow and restore dead DegradationLadder test#1580
vivekrajsingh04 wants to merge 1 commit intomofa-org:mainfrom
vivekrajsingh04:fix/linear-backoff-overflow-dead-test

Conversation

@vivekrajsingh04
Copy link
Copy Markdown
Collaborator

Fixes #1579. Details in the issue and commits.

… dead DegradationLadder test

Two related reliability fixes in mofa-foundation:

1. Backoff::Linear::delay_for() used bare + and * operators that panic on
   integer overflow in debug builds and silently wrap in release builds.
   Fixed by using saturating_add/saturating_mul and adding a max_ms cap,
   matching the overflow-safe pattern already used by Backoff::Exponential.
   Added linear_with_max() constructor for explicit cap control.

2. test_degradation_ladder_degrades_to_q4_when_q8_too_large in routing.rs
   was missing its #[test] attribute, making it dead code. The critical Q4
   degradation path (last safety net before cloud fallback on constrained
   devices) had zero test coverage. Added the missing attribute.

New tests:
- test_backoff_linear_saturates_and_caps: verifies no panic on u32::MAX
- test_backoff_linear_with_custom_max: verifies explicit cap behavior

Fixes #XXXX
@SH20RAJ
Copy link
Copy Markdown
Contributor

SH20RAJ commented Apr 7, 2026

Hey @yangrudan @lijingrs, this PR fixes an integer overflow in Backoff::Linear and restores a dead test. Important safety fix. Could you review when available? 🔍

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.

[BUG] Backoff::Linear can panic on integer overflow and DegradationLadder Q4 test is silently dead code

2 participants