T2.3-T2.6: BWE guard, relay conformance Tier A/B/C, Prometheus metrics

This commit is contained in:
Siavash Sameni
2026-05-11 20:50:01 +04:00
parent 3de56cf1f9
commit 54c1a35186
16 changed files with 977 additions and 38 deletions

View File

@@ -0,0 +1,68 @@
# T2.3 — Plumb BWE into `AdaptiveQualityController`
**Status:** Pending Review
**Agent:** Kimi Code CLI
**Started:** 2026-05-11T17:13Z
**Completed:** 2026-05-11T17:20Z
**Commit:** 846c98e
**PRD:** ../PRD-transport-feedback-bwe.md
## What I changed
- `crates/wzp-proto/src/quality.rs``AdaptiveQualityController`:
- Added `bwe: Option<Arc<BandwidthEstimator>>` field.
- Added `set_bandwidth_estimator(&mut self, bwe: Arc<BandwidthEstimator>)` setter.
- Added `tier_ceiling_bps(tier: Tier) -> u64` helper using `QualityProfile::total_bitrate_kbps()`.
- In `try_transition()`, before upgrading to a higher tier, check BWE headroom:
```rust
if let Some(ref bwe) = self.bwe {
let required = (Self::tier_ceiling_bps(next_tier) * 130) / 100;
if bwe.target_send_bps() < required {
self.consecutive_up = 0;
return None;
}
}
```
This requires `target_send_bps() >= 130%` of the next tier's bitrate ceiling (including FEC overhead).
## Why these choices
The 130% headroom factor is a safety margin: we only upgrade if the bandwidth estimate comfortably exceeds the target tier's requirement, preventing flapping when BWE is borderline. Resetting `consecutive_up` to 0 on BWE block gives the estimator time to converge before the next upgrade attempt.
Checking the *next* tier's ceiling (not the current tier) is correct: the guard answers "can we afford the tier we're trying to move into?"
## Deviations from the task spec
None.
## Verification output
```bash
$ cargo test -p wzp-proto quality
running 24 tests
...(all 24 pass)...
test result: ok. 24 passed; 0 failed; 0 ignored; 0 measured; 95 filtered out; finished in 0.10s
```
## Test summary
- Tests added: 1
- `bwe_guard_blocks_upgrade_when_bandwidth_insufficient` — verifies low BWE blocks upgrade, high BWE allows it after counter reset
- Tests modified: 0
- `wzp-proto` test count: 119 (was 118 before T2.3)
- `cargo clippy -p wzp-proto --all-targets -- -D warnings`: pass
- `cargo fmt --all -- --check`: pass
## Risks / follow-ups
- `BandwidthEstimator` is attached via `set_bandwidth_estimator()`; call sites in `wzp-client` (send/recv loops) will create and wire it in a future task.
- The BWE guard only applies to upgrades. Downgrades are unchanged — they react quickly to quality reports regardless of BWE.
## Reviewer checklist (filled in by reviewer)
- [ ] Code matches PRD intent
- [ ] Verification output is real
- [ ] No backward-incompat surprises
- [ ] Tests cover the new behavior
- [ ] Approved