T1.4: Add v2 MiniHeader with seq_delta

This commit is contained in:
Siavash Sameni
2026-05-11 11:17:42 +04:00
parent 8c6e88ea68
commit e8866c6632
4 changed files with 273 additions and 11 deletions

View File

@@ -437,6 +437,47 @@ cargo test -p wzp-proto
---
## T1.2.1 — Add rustdoc on `MediaType` variants and methods
- **Parent:** T1.2 (Approved)
- **PRD:** `PRD-wire-format-v2.md`
- **Effort:** 10 min
- **Files:**
- `crates/wzp-proto/src/media_type.rs`
### Context
T1.2 created `MediaType` with a one-line top-level doc comment but no `///` rustdoc on the variants (`Audio`, `Video`, `Data`, `Control`) or methods (`to_wire`, `from_wire`). Coding standard #9 — public items need rustdoc. Same shape of follow-up as T1.1.1.
### Steps
1. Open `crates/wzp-proto/src/media_type.rs`.
2. Add a `///` doc comment to each variant. Examples (do not just copy — pick what's accurate):
```rust
pub enum MediaType {
/// Encoded speech / music (Opus, Codec2, ComfortNoise).
Audio = 0,
/// Encoded video access unit (H.264, H.265, AV1; PRD-video-multicodec).
Video = 1,
/// Opaque payload not interpreted by the relay (reserved).
Data = 2,
/// In-band control message carried on the media plane (reserved).
Control = 3,
}
```
3. Add a `///` doc on `to_wire` and `from_wire`. One line each is fine — explain the wire byte mapping and the `None` case.
### Verify
```bash
cargo doc -p wzp-proto --no-deps 2>&1 | grep -i "missing" || echo "no missing-doc warnings"
cargo clippy -p wzp-proto --all-targets -- -D warnings -W missing_docs
```
### Done when
- All variants and methods on `MediaType` carry `///` doc comments.
- `cargo doc -p wzp-proto --no-deps` emits no "missing documentation" warnings for `MediaType`.
---
## T1.3 — Widen `CodecId` wire representation to u8
- **PRD:** `PRD-wire-format-v2.md` (resolves audit W9)
@@ -1163,9 +1204,10 @@ Statuses (in order of progression):
| T1.1 | Approved | Kimi Code CLI | 2026-05-11T06:09Z | 2026-05-11T06:54Z | [report](reports/T1.1-report.md) | Approved 2026-05-11. Spawned T1.1.1 (field rustdoc) and T1.1.2 (refresh stale test-count). |
| T1.1.1 | Open | — | — | — | — | Spawned from T1.1 review; non-blocking, claim after current in-flight |
| T1.1.2 | Open | — | — | — | — | Spawned from T1.1 review; non-blocking, claim after current in-flight |
| T1.2 | Pending Review | Kimi Code CLI | 2026-05-11T06:55Z | 2026-05-11T07:08Z | reports/T1.2-report.md | |
| T1.3 | In Progress | Kimi Code CLI | 2026-05-11T07:10Z | — | — | — |
| T1.4 | Open | — | — | — | — | — |
| T1.2 | Approved | Kimi Code CLI | 2026-05-11T06:55Z | 2026-05-11T07:08Z | [report](reports/T1.2-report.md) | Approved 2026-05-11. Spawned T1.2.1 (rustdoc on MediaType variants/methods). Agent also resolved the T1.2 TODO inside MediaHeaderV2 — good call. |
| T1.2.1 | Open | — | — | — | — | Spawned from T1.2 review; non-blocking |
| T1.3 | Approved | Kimi Code CLI | 2026-05-11T07:10Z | 2026-05-11T07:11Z | [report](reports/T1.3-report.md) | Approved 2026-05-11. No follow-ups; docs-and-test-only change. |
| T1.4 | Pending Review | Kimi Code CLI | 2026-05-11T07:12Z | 2026-05-11T07:16Z | reports/T1.4-report.md | — |
| T1.5 | Open | — | — | — | — | — |
| T1.6 | Open | — | — | — | — | — |
| T1.7 | Open | — | — | — | — | — |
@@ -1205,5 +1247,7 @@ Statuses (in order of progression):
Items currently waiting on the reviewer:
- T1.2 — Add MediaType enum — report: reports/T1.2-report.md
- T1.3 — Widen CodecId wire representation to u8 — report: reports/T1.3-report.md
- T1.4 — Add v2 MiniHeader with seq_delta — report: reports/T1.4-report.md
Once a task moves to `Pending Review`, add a line here so the reviewer sees it: `- T<id> — <one-line summary> — report: reports/T<id>-report.md`. The reviewer removes the line when they mark it `Approved` (or moves it back to the agent on `Changes Requested`).

View File

@@ -0,0 +1,92 @@
# T1.4 — Add v2 `MiniHeader` with `seq_delta`
**Status:** Pending Review
**Agent:** Kimi Code CLI
**Started:** 2026-05-11T07:12Z
**Completed:** 2026-05-11T07:16Z
**Commit:** see git log
**PRD:** ../PRD-wire-format-v2.md
## What I changed
- `crates/wzp-proto/src/packet.rs:580-611` — renamed `MiniHeader``MiniHeaderV1`, kept all impls intact
- `crates/wzp-proto/src/packet.rs:613` — added `pub type MiniHeader = MiniHeaderV1;` backward-compat alias
- `crates/wzp-proto/src/packet.rs:616-640` — added new `MiniHeaderV2` struct (5 bytes: `seq_delta` + `timestamp_delta_ms` + `payload_len`) with `write_to`/`read_from`
- `crates/wzp-proto/src/packet.rs:642-666` — renamed `MiniFrameContext``MiniFrameContextV1`, kept all impls intact
- `crates/wzp-proto/src/packet.rs:668` — added `pub type MiniFrameContext = MiniFrameContextV1;` backward-compat alias
- `crates/wzp-proto/src/packet.rs:670-695` — added new `MiniFrameContextV2` tracking `MediaHeaderV2` baseline, with `update` and `expand` using explicit `seq_delta`
- `crates/wzp-proto/src/lib.rs:31` — re-exported `MiniHeaderV1`, `MiniHeaderV2`, `MiniFrameContextV1`, `MiniFrameContextV2`
- `crates/wzp-proto/src/packet.rs:1968-2014` — added 3 v2 tests: `mini_header_v2_roundtrip`, `mini_frame_context_v2_expand`, `mini_frame_context_v2_no_baseline`
## Why these choices
Same naming collision as T1.1: Rust does not allow a type alias and a struct with the same name in the same module. The new structs are named `MiniHeaderV2` and `MiniFrameContextV2` with temporary aliases preserving the old names; T1.5 will delete the v1 types and rename.
The v2 `MiniFrameContextV2::expand` uses `base.seq.wrapping_add(m.seq_delta as u32)` instead of the hard-coded `wrapping_add(1)` from v1, which resolves audit W4 (a missed full header no longer desyncs the sequence).
## Deviations from the task spec
1. **Step 2 / Step 3 (struct names):** The new mini struct is `MiniHeaderV2` and the new context is `MiniFrameContextV2` instead of `MiniHeader` / `MiniFrameContext`. Required because `pub type MiniHeader = MiniHeaderV1;` and `pub type MiniFrameContext = MiniFrameContextV1;` occupy the base names. T1.5 will resolve.
## Verification output
```bash
$ cargo test -p wzp-proto mini
running 12 tests
test packet::tests::full_vs_mini_size_comparison ... ok
test packet::tests::mini_frame_context_expand ... ok
test packet::tests::mini_frame_context_no_baseline ... ok
test packet::tests::mini_frame_context_v2_expand ... ok
test packet::tests::mini_frame_context_v2_no_baseline ... ok
test packet::tests::mini_frame_disabled ... ok
test packet::tests::mini_frame_encode_decode_sequence ... ok
test packet::tests::mini_frame_periodic_full ... ok
test packet::tests::mini_header_encode_decode ... ok
test packet::tests::mini_header_v2_roundtrip ... ok
test packet::tests::mini_header_wire_size ... ok
test packet::tests::candidate_update_minimal_roundtrip ... ok
test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 100 filtered out; finished in 0.00s
```
```bash
$ cargo build -p wzp-proto -p wzp-codec -p wzp-fec -p wzp-crypto -p wzp-transport -p wzp-relay -p wzp-client -p wzp-web -p wzp-native
Finished `dev` profile [unoptimized + debuginfo] target(s) in 15.71s
```
```bash
$ cargo test -p wzp-proto -p wzp-codec -p wzp-fec -p wzp-crypto -p wzp-transport -p wzp-relay -p wzp-client -p wzp-web -p wzp-native --no-fail-fast
...
test result: ok. 571 passed; 0 failed; ...
```
```bash
$ cargo clippy -p wzp-proto --all-targets -- -D warnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s
```
```bash
$ cargo fmt --all -- --check
# (clean)
```
## Test summary
- Tests added: 3 (`mini_header_v2_roundtrip`, `mini_frame_context_v2_expand`, `mini_frame_context_v2_no_baseline`)
- Tests modified: 0
- Workspace test count before: 568 pass / 0 fail (non-Android subset)
- Workspace test count after: 571 pass / 0 fail (non-Android subset)
- `cargo clippy -p wzp-proto --all-targets -- -D warnings`: pass
- `cargo fmt --all -- --check`: pass
## Risks / follow-ups
- `MiniHeaderV2` / `MiniFrameContextV2` must be renamed to `MiniHeader` / `MiniFrameContext` in T1.5 after v1 types are deleted.
## Reviewer checklist (filled in by reviewer)
- [ ] Code matches PRD intent
- [ ] Verification output is real (re-run if suspicious)
- [ ] No backward-incompat surprises
- [ ] Tests cover the new behavior
- [ ] Approved