Skip to content

core: frontend: system-information: Fix negative bandwidth display#3779

Open
patrickelectric wants to merge 1 commit intobluerobotics:masterfrom
patrickelectric:fix-1
Open

core: frontend: system-information: Fix negative bandwidth display#3779
patrickelectric wants to merge 1 commit intobluerobotics:masterfrom
patrickelectric:fix-1

Conversation

@patrickelectric
Copy link
Member

@patrickelectric patrickelectric commented Feb 10, 2026

Closes #3587

Summary by Sourcery

Prevent negative bandwidth values from being calculated or displayed in the system information frontend.

Bug Fixes:

  • Clamp calculated download and upload speeds to zero or higher when deriving them from network counters.
  • Ensure formatted bandwidth values never show as negative Mbps by clamping the input rate to zero.

Clamp network speed calculations to zero to prevent negative bandwidth
values when interface counters reset or wrap around.

Closes bluerobotics#3587

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures network bandwidth values are never negative both when computing speeds in the Vuex store and when formatting them for display, clamping raw and formatted values to zero or higher.

Flow diagram for non-negative bandwidth calculation and formatting

flowchart TD
  A[Input network byte counters and previous counters] --> B[Compute dt_seconds]
  B --> C{Previous network sample exists}
  C -- No --> D[Set last_update and skip speed computation]
  C -- Yes --> E[Compute delta_received_B and delta_transmitted_B]
  E --> F[Compute raw_download_speed_bytes_per_second]
  E --> G[Compute raw_upload_speed_bytes_per_second]
  F --> H[Clamp download_speed to non_negative using Math_max_0]
  G --> I[Clamp upload_speed to non_negative using Math_max_0]
  H --> J[Store non_negative_download_speed in Vuex_state]
  I --> K[Store non_negative_upload_speed in Vuex_state]
  J --> L[Pass download_speed_bytes_per_second to formatBandwidth]
  K --> M[Pass upload_speed_bytes_per_second to formatBandwidth]

  subgraph formatBandwidth_function
    L & M --> N[Clamp bytes_per_second_to_non_negative using Math_max_0]
    N --> O[Compute mbps = 8_times_bytes_per_second_div_1024_div_1024]
    O --> P{mbps < 10}
    P -- Yes --> Q[decimal_places = 2]
    P -- No --> R{mbps < 100}
    R -- Yes --> S[decimal_places = 1]
    R -- No --> T[decimal_places = 0]
    Q --> U[Format string using mbps_toFixed_decimal_places]
    S --> U
    T --> U
  end

  U --> V[Display non_negative_bandwidth_string_in_UI]
Loading

File-Level Changes

Change Details Files
Clamp computed network upload/download speeds in the Vuex store to prevent negative values.
  • Wrap download speed calculation in Math.max(0, delta_bytes_received / dt) before assigning to network.download_speed.
  • Wrap upload speed calculation in Math.max(0, delta_bytes_transmitted / dt) before assigning to network.upload_speed.
core/frontend/src/store/system-information.ts
Guard bandwidth formatting against negative byte-per-second inputs.
  • Ensure bytesPerSecond is clamped with Math.max(0, bytesPerSecond) before converting to Mbps.
  • Keep existing decimal place selection logic based on Mbps value while using the clamped value.
core/frontend/src/utils/networking.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#3587 Prevent calculated network upload and download speeds from becoming negative in the system information store.
#3587 Ensure the bandwidth formatting utility does not display negative Mbps values.

Possibly linked issues

  • Negative bandwidth (?) #3587: PR clamps bandwidth calculations to be non-negative, directly fixing the negative bandwidth display reported in the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Member

@joaoantoniocardoso joaoantoniocardoso left a comment

Choose a reason for hiding this comment

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

haha well, I guess that "solves" it. Did you take a look at why it happens? Was it only a frontend thing? I ask that because it might be the backend reporting wrong values.

@patrickelectric
Copy link
Member Author

I'll check it further

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.

Negative bandwidth (?)

2 participants