Skip to content

fix(moq-ffi,libmoq,bindings): route watch through run, keep finished windows, roll back dropped listens, export every enum, guard timestamps - #9341

Merged
kixelated merged 11 commits into
mainfrom
quest/m1/precut-audit/ffi-and-bindings-fixes
Nov 22, 2026
Merged

kixelated merged 11 commits into
mainfrom
quest/m1/precut-audit/ffi-and-bindings-fixes

Conversation

@kixelated

@kixelated kixelated commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m1/precut-audit/ffi-and-bindings-fixes.md.

Summary

  • moq-ffi: every async entry point runs inside ffi::run. Background::watch now wraps its call in run, so the ten exported methods behind it get panic isolation, stopped() cancellation, shutdown poll accounting, and the runtime context, like every other entry point. MoqMediaCatalogConsumer::subscribe goes through watch too. A new Background::supervise is the owner-failure select without run, for MoqSession::watch, which nests two owners. Task::run and MoqServer::accept drop their now-redundant inner run.
  • moq-ffi: a finished JSON window outlives its handles. MoqTrackProducer::adopt hands the typed writer its broadcast's Children. MoqJsonWindowProducer::finish keeps the moq_json::window::Finished there, as media producers already do, so a late subscriber still finds the window until the broadcast closes. Snapshot and stream producers stay as they are: moq-mux retires their catalog entry on finish on purpose.
  • moq-ffi: a dropped MoqServer::listen rolls back. A new Phase::Starting holds the loop until its address arrives, and a Rollback drop guard turns a dropped or failed listen back into Idle. It stops the loop without blocking and keeps it as Idle::stopping. The next listen or cancel waits for the loop to release its sockets, so the same address binds again. Before this, a listen dropped mid-start left Listening in place, and every later listen failed with "already listening".
  • libmoq: moq.h declares every enum. build.rs now builds cbindgen's include list by scanning src/ for pub enum moq_* instead of keeping a hand list. That adds moq_order and moq_refresh, plus moq_announce_kind, moq_connection_phase, moq_decode_read_kind, moq_follow_event, and moq_json_window_kind, which signatures already reached. A future enum can't be forgotten.
  • Bindings: timestamp guards.
    • Kotlin toDuration(): errors on a zero scale, and on a seconds quotient past a Long that used to wrap negative (Timestamp(ULong.MAX_VALUE, 1) gave -1 s).
    • Kotlin toTimestamp(): rejects Duration.INFINITE, and builds the nanosecond count from exact toComponents parts instead of the saturating inWholeNanoseconds. It accepts anything that fits in 64 bits of nanoseconds (about 584 years) and errors past that.
    • Python to_timedelta(): raises ValueError on a scale that isn't positive.
    • Dart toDuration(): throws ArgumentError on a zero scale, and reads value and scale as the unsigned u64 they are. A Dart int past 2^63 holds them as negative.

Choices made without asking (for review)

  • Kotlin range: toTimestamp accepts up to 2^64 ns, not just up to 292 years as the quest's Plan said. Every value in that range converts exactly, and moq-net's write still refuses one past its own bound with TimeOverflow.
  • Dart unsigned: the Dart guard reads both fields as unsigned instead of the Plan's scale <= 0 check. A "negative" Dart scale is a valid huge u64.
  • Window demand: a finished window's demand now ends when its broadcast closes, not at finish. That matches media producers (demand_handle_outlives_finish). json_window_demand is updated to match.
  • Poisoned lock: the Rollback drop guard takes a poisoned phase lock rather than panicking, since it may run while listen unwinds (Pullfrog's finding).
  • Reported panic: a listen that waits for a dropped loop reports that loop's panic, if it had one.

Public API

Additive only. moq.h now declares seven more enums. The Kotlin, Python, and Dart timestamp conversions throw on inputs that used to give wrong values. The window producer's finish keeps the track until the broadcast closes. No breaking API change. Wire: none.

Validation

  • just rs test -p moq-ffi: 327 passed. New tests:
    • watch_isolates_a_panic_and_enters_the_runtime, with and without an owner.
    • json_window_finish_serves_a_late_subscriber.
    • server_listen_dropped_mid_start_rolls_back.
  • Reverted each fix locally: json_window_finish_serves_a_late_subscriber and server_listen_dropped_mid_start_rolls_back both failed without their fix.
  • just rs test -p libmoq: 208 passed, including the new header_declares_every_enum. I also checked the generated moq.h by hand: all 20 pub enum moq_* in src/ are declared.
  • just py test (128 passed), just dart check (all tests passed), just kt check (:moq:jvmTest ran and passed), each with new cases for the guards above.
  • just rs check passes. The full just check passed every language check except rs, which failed on formatting; after cargo fmt, just rs check passes.

Caused by

  • moq-dev/moq#5562: added Background::watch polled only through host, outside ffi::run (found by reviewer: precut audit).
  • moq-dev/moq#8907: MoqMediaCatalogConsumer::subscribe builds its consumer outside run (found by reviewer: precut audit).
  • moq-dev/moq#8395: MoqJsonWindowProducer::finish drops the new Finished handle, releasing the track (found by reviewer: precut audit).
  • moq-dev/moq#5172: listen waits for its address with no rollback if it is dropped (found by reviewer: precut audit).
  • moq-dev/moq#5732 and moq-dev/moq#9054: added moq_order and moq_refresh without adding them to the header's enum list (found by reviewer: precut audit).
  • moq-dev/moq#6946: the binding timestamp conversions it added have no zero-scale or overflow guards (found by reviewer: precut audit).

Follow-ups

None.

Models

Size: M
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm A)
Implementer: Claude Code, claude-opus-5-5, unknown effort (iterate, XS, arm A)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 82b0184

  • Base: origin/main at f1b6e06

  • Risk: medium, FFI runtime routing, server cancellation, finished-window retention, timestamp conversions, and additive C enum exports change behavior binding consumers rely on, but introduce no API or wire break and can be fully undone by reverting.

  • Classified: medium by Codex, gpt-6.1-sol, low effort, session 01a201d4-49fd-7e03-a431-bb48ba48fba6

  • Reviewer: Codex, gpt-6.1-sol, high effort

  • Session: 01a2018a-b02d-7d63-80fa-2b4286a652c8, round 3

  • Score: 10/10, The incremental change safely recovers a poisoned lock during rollback cleanup, with no new issues found by code review; builds and tests were not run as instructed.

  • Rounds: 3; first round 1 (medium 1); findings 1 (medium 1): fixed 1, refuted 0, open 0

  • Findings: none

kixelated and others added 9 commits November 21, 2026 20:03
…roll back cancelled listens, export every enum

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ps, and saturation; test the moq-ffi fixes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Fix moq-ffi async runtime routing, window finish retention, libmoq enum exports, and timestamp guards fix(moq-ffi,libmoq,bindings): route watch through run, keep finished windows, roll back dropped listens, export every enum, guard timestamps Nov 22, 2026
… mid-start

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 22, 2026 04:40
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 069bd93d-c468-470f-bf66-533140010692
Commits

Reviewing files that changed from the base of the PR and between e140dae and 82b0184.

Files selected for processing: 16

  • dart/moq/lib/src/timestamp.dart
  • dart/moq/test/moq_test.dart
  • kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Timestamp.kt
  • kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt
  • py/moq-rs/moq/_records.py
  • py/moq-rs/tests/test_data_timestamps.py
  • quest/m1/precut-audit/ffi-and-bindings-fixes.md
  • rs/libmoq/build.rs
  • rs/libmoq/src/test.rs
  • rs/moq-ffi/src/ffi.rs
  • rs/moq-ffi/src/json.rs
  • rs/moq-ffi/src/media.rs
  • rs/moq-ffi/src/producer.rs
  • rs/moq-ffi/src/server.rs
  • rs/moq-ffi/src/session.rs
  • rs/moq-ffi/src/test.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@kixelated
kixelated enabled auto-merge November 22, 2026 04:41

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor suggestion inline.

Approach: sound — each fix lands where its bug comes from: watch itself now enters run, the window producer keeps its finished track through the broadcast's existing Children::keep path, and a drop guard handles listen's rollback.

Reviewed changes

Reviewed all 16 files across the 10 commits: the moq-ffi runtime routing, window retention, and server lifecycle changes, the libmoq header generation, and the three binding timestamp helpers.

  • Background::watch / supervise: every watch caller now gets run's panic isolation, shutdown accounting, and runtime context. supervise keeps MoqSession::watch from nesting twice. MoqSession::closed and state_changed still nest two runs through Task::run, but nesting Polling and host is harmless.
  • MoqJsonWindowProducer::finish: it keeps Finished in the broadcast's Children, as audio and video producers already do. Family::Released drops the strong broadcast, so this creates no cycle.
  • MoqServer Phase::Starting + Rollback: I traced a failed bind, a concurrent cancel, a drop before the first poll, and a drop mid-start. Each one ends in Idle or Cancelled as intended. settle blocks under the phase lock the same way cancel already did.
  • libmoq build.rs: cbindgen's include list now comes from scanning src/ for pub enum moq_*. The new test checks four of those names.
  • Kotlin/Python/Dart timestamps: added zero-scale guards, the Kotlin Long quotient check, exact BigInteger nanoseconds in toTimestamp, and unsigned u64 reads in Dart. I checked the arithmetic in the new test cases.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

Comment thread rs/moq-ffi/src/server.rs Resolved
@moq-bot
moq-bot Bot disabled auto-merge November 22, 2026 04:45
@moq-bot

moq-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

quest land watch: ended this pull request's pick, disarming its auto-merge, since its head 8686830 is held by finding by pullfrog[bot]: If the phase lock is poisoned, this unwrap aborts the host process. Here's how: listen's own `self.phase.lock().unwr (#9341 (comment)). Push a fix, or answer each by a thread reply or a comment linking its review or decision, then land it again.

(written by quest land watch)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

Reviewed the single commit since the prior pullfrog review.

  • Rollback::drop poison tolerance: the drop guard now takes the phase lock with unwrap_or_else(PoisonError::into_inner), so a panic unwinding through listen can no longer double-panic and abort. This resolves the earlier finding.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 98ca024 Nov 22, 2026
5 checks passed
@kixelated
kixelated deleted the quest/m1/precut-audit/ffi-and-bindings-fixes branch November 22, 2026 06:15
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