Skip to content

feat(server): Split bandwidth metering into ingress and egress#296

Closed
lcian wants to merge 4 commits intomainfrom
ref/split-bandwidth-ingress-egress
Closed

feat(server): Split bandwidth metering into ingress and egress#296
lcian wants to merge 4 commits intomainfrom
ref/split-bandwidth-ingress-egress

Conversation

@lcian
Copy link
Member

@lcian lcian commented Feb 12, 2026

Split MeteredPayloadStream into Ingress and Egress variants so upload
and download bandwidth are tracked independently. BandwidthRateLimiter now
maintains separate accumulators and EWMA estimates for each direction, emitting
server.bandwidth.ingress.ewma and server.bandwidth.egress.ewma metrics.
Rate limiting still compares the total (ingress + egress) against the configured
global_bps, preserving current behavior.

Also separates BandwidthRateLimiter construction from background task spawning
via a new start() method, called from Services::spawn.

Stacked on #293.

@lcian lcian requested a review from a team as a code owner February 12, 2026 14:17
@lcian lcian changed the title ref(server): Split bandwidth metering into ingress and egress feat(server): Split bandwidth metering into ingress and egress Feb 12, 2026
Base automatically changed from ref/metered-body-extractor to main February 12, 2026 14:36
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

let egress = self
.egress_estimate
.load(std::sync::atomic::Ordering::Relaxed);
ingress <= bps && egress <= bps
Copy link

Choose a reason for hiding this comment

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

Rate limit checks directions independently, not total

High Severity

The check() method uses ingress <= bps && egress <= bps, which compares each direction independently against global_bps. The PR description explicitly states "Rate limiting still compares the total (ingress + egress) against the configured global_bps, preserving current behavior." The old code had a single combined accumulator, so the previous behavior was effectively limiting total bandwidth. The new logic allows up to 2× the configured global_bps in aggregate, breaking the intended rate limiting guarantee. The check needs to compare ingress + egress (or ingress.saturating_add(egress)) against bps.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

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

This is true, thinking about how this should behave/be configured

@lcian lcian marked this pull request as draft February 12, 2026 14:38
lcian and others added 4 commits February 12, 2026 15:43
Convert MeteredPayloadStream from a struct to an enum with Ingress and
Egress variants so upload and download bandwidth are tracked separately.
BandwidthRateLimiter now maintains independent accumulators and EWMA
estimates for each direction, emitting server.bandwidth.ingress.ewma and
server.bandwidth.egress.ewma metrics. Rate limiting still uses the total
of both directions. Also separate BandwidthRateLimiter construction from
task spawning via a new start() method.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Apply global_bps as a cap on ingress and egress independently rather
than on their sum, matching the physical network constraints where each
direction has its own limit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lcian lcian force-pushed the ref/split-bandwidth-ingress-egress branch from 0b09b72 to 054007c Compare February 12, 2026 14:44
@lcian lcian closed this Feb 12, 2026
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