[codex] expose moq-rtc session runner#1931
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
AcceptedSession::run, the earlyOk(())returns when any ofsession,registration, orcancelisNonewill silently hide logic bugs; consider treating missing state as an internal error (or at least logging/warning) so accidental double-runs or construction issues surface instead of being silently ignored. - In the WHIP/WHEP HTTP handlers, cloning
resource_idandanswerfromResponsejust to move the original into the spawned task adds extra allocations; you could instead restructure the API (e.g., a method that consumesResponseand returns(resource_id, answer, runner)or splits out aSessionRunnertype) to avoid these clones while still allowing the session to be driven asynchronously.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `AcceptedSession::run`, the early `Ok(())` returns when any of `session`, `registration`, or `cancel` is `None` will silently hide logic bugs; consider treating missing state as an internal error (or at least logging/warning) so accidental double-runs or construction issues surface instead of being silently ignored.
- In the WHIP/WHEP HTTP handlers, cloning `resource_id` and `answer` from `Response` just to move the original into the spawned task adds extra allocations; you could instead restructure the API (e.g., a method that consumes `Response` and returns `(resource_id, answer, runner)` or splits out a `SessionRunner` type) to avoid these clones while still allowing the session to be driven asynchronously.
## Individual Comments
### Comment 1
<location path="rs/moq-rtc/src/server/mod.rs" line_range="87-94" />
<code_context>
+}
+
+impl AcceptedSession {
+ async fn run(mut self) -> Result<()> {
+ let Some(session) = self.session.take() else {
+ return Ok(());
+ };
+ let Some(registration) = self.registration.take() else {
+ return Ok(());
+ };
+ let Some(cancel) = self.cancel.take() else {
+ return Ok(());
+ };
</code_context>
<issue_to_address>
**issue (bug_risk):** Silently returning Ok(()) when session, registration, or cancel are None can hide broken invariants.
Given these fields should always be `Some` after construction, hitting any of these `None` branches indicates a logic error elsewhere. Instead of silently returning, please at least log a debug message or use `expect` with a clear message so unexpected states are surfaced and session lifecycle issues are easier to diagnose.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
WalkthroughThe PR changes the session lifecycle so 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rs/moq-rtc/src/server/whep.rs`:
- Around line 27-41: The WHEP handler builds the Location header from the
extracted `path`, which loses the mounted `/whep` prefix when the router is
nested. Update `handle` in `whep.rs` to derive the session URI from the original
request target instead of `path.0`, using `OriginalUri` or another preserved
full request URI source. Keep the existing `accept_offer` flow and
`response.resource_id` usage, but construct the Location value from the actual
mounted request path so it points to the correct session resource.
In `@rs/moq-rtc/src/server/whip.rs`:
- Around line 35-46: The Location header is being built from the wildcard `path`
in `whip.rs`, which loses the router mount prefix when the handler is mounted
under a route like `/whip`. Update the response construction in `whip::handle`
to derive the Location value from the original request URI path instead of
`path`, and apply the same change in the matching WHEP handler so both return
the full mounted path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fdf2d00b-6e4d-413b-badf-5b50d3250ba8
📒 Files selected for processing (7)
rs/moq-rtc/src/client/whep.rsrs/moq-rtc/src/client/whip.rsrs/moq-rtc/src/lib.rsrs/moq-rtc/src/server/mod.rsrs/moq-rtc/src/server/whep.rsrs/moq-rtc/src/server/whip.rsrs/moq-rtc/src/session.rs
Summary
moq_rtc::server::Responseinto an owned session runner withResponse::run().Locationheaders fromOriginalUriso nested routers preserve their mount prefix.Root Cause
whip::acceptandwhep::acceptpreviously spawnedSession::run()internally and returned only the SDP response data. The WebRTC task knew when the peer disconnected, but embedders had no handle to await, so external session accounting had to guess.The bundled handlers also built
Locationfrom the wildcard path, which dropped route mount prefixes such as/whipor/whep.Public API Changes
moq_rtc::server::Responseis no longerClone.moq_rtc::server::Responseadds publicasync fn run(self) -> Result<()>.whip::acceptandwhep::acceptnow return aResponsethat must be run by the caller to drive the negotiated media session.This is a breaking API change in
rs/moq-rtc, butmoq-rtcis currently version0.0.1and not listed in the branch-targeting breaking-change set.Validation
cargo test -p moq-rtccargo check -p moq-rtcgit diff --check(Written by Claude)