Skip to content

moq repair refuses a recording still being written - #8823

Merged
kixelated merged 5 commits into
mainfrom
quest/m1/mp4-repair-lock
Nov 17, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m1/mp4-repair-lock

Conversation

@kixelated

@kixelated kixelated commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

moq export mp4 --output now holds an exclusive file lock (advisory on Unix, mandatory on Windows) on its output while it records, and moq repair mp4 refuses a file it can't lock, with a message saying a recorder still has it open. Finishes quest/m1/mp4-repair-lock.md (deleted here), found by moq-dev/moq#7560.

Summary

  • Recorder (rs/moq-cli/src/subscribe.rs): after create_new, takes File::try_lock and holds it until the file closes. If it can't lock (no lock support), it removes the file it just created and fails: a recording that could never be repaired safely isn't started. The OS drops the lock with a killed recorder, so a SIGKILLed recording stays repairable.
  • Repair (rs/moq-cli/src/repair.rs): takes the same lock non-blocking before scanning and holds it through the rewrite. Any try_lock failure, held or unsupported, refuses with that error (its Display says whether the file is in use), without repairing unlocked.
  • moq-mux::repair is untouched (still impl Read + Seek).
  • Docs: doc/bin/cli.md, including that on Windows the lock also blocks other programs from reading the recording until it finishes.

Public API

None: CLI behavior only. Wire: none.

Validation

  • New export::repair_refuses_a_locked_recording (fast, no relay, runs in the normal gate): the test process holds the lock, the built moq repair mp4 binary exits non-zero with the lock message and leaves the file byte-identical; after release it proceeds to scan.
  • Extended nightly export::a_killed_mp4_recording_is_repaired (just rs cli-export, ran locally, all 16 pass): repair mid-recording against the real export mp4 process refuses and does not rewrite the file; after SIGKILL the same repair succeeds (the lock died with the process).
  • Not exercised: a filesystem without lock support (no such mount available); that path is the TryLockError::Error arm and the recorder's remove-and-fail.
  • just check passes.

Choices for review

  • No error is matched (AGENTS.md "Never match on errors", per the coordinator): repair refuses on any try_lock failure and reports the error itself, so held and unsupported share one message ("failed to lock FILE, so it may still be open by a recorder").
  • repair takes the exclusive lock too, so two concurrent repairs also refuse each other .
  • Race: the recorder creates the file, then locks, so a repair in that instant sees a just-created empty file and fails to scan it rather than corrupting anything. Not worth closing (would need creating under a lock).
  • No CHANGELOG edit; I left release notes to the release cut.

Decisions

  • Windows (Pullfrog's note): kept the exclusive lock and documented that it blocks other readers on Windows, instead of the suggested shared recorder lock. Per Microsoft's byte-range locking docs, a shared LockFileEx lock denies writes to every handle including the one holding it, so the recorder could no longer write its own file. Locking a byte range past EOF would let readers in, but needs windows-sys and unsafe FFI in moq-cli for an edge case nothing here tests; not worth its weight now.

Follow-ups

None.

Review

Rewritten by quest review after each round.

  • Head: 22b42f8

  • Base: origin/main at 1399add

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

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

  • Session: 01a1e997-281f-7790-8076-abe998e10f88, round 1

  • Score: 9/10, No actionable defects were found: recorder and repair retain the lock through their writes, with refusal and crash-recovery coverage, though builds and tests were not run as instructed.

  • Rounds: 3; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

Models

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

kixelated and others added 2 commits November 15, 2026 04:33
export mp4 holds an exclusive file lock on its output while it records, and
repair mp4 refuses a file it cannot lock. Neither runs on a filesystem
without locks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 15, 2026 12:44
@coderabbitai

coderabbitai Bot commented Nov 15, 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 23 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: 910441b8-6901-4b26-b9bb-9f041d506184
Commits

Reviewing files that changed from the base of the PR and between 1399add and 22b42f8.

Files selected for processing: 5

  • doc/bin/cli.md
  • quest/m1/mp4-repair-lock.md
  • rs/moq-cli/src/repair.rs
  • rs/moq-cli/src/subscribe.rs
  • rs/moq-cli/tests/integration/export.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

@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 blocking issues. One Windows-specific rough edge is noted inline.

Reviewed changes

I reviewed the advisory lock that moq export mp4 now holds on its output, and the matching lock check in moq repair mp4.

  • Recorder lock: run_mp4 takes File::try_lock right after create_new and keeps the lock until the file closes. If it can't lock, it deletes the new file and fails.
  • Repair refusal: Mp4::run locks before it scans. WouldBlock gets a clear "still open by a recorder" message, and any other lock error stops the repair instead of letting it run unlocked.
  • Tests: a new fast test holds the lock from the test process. The nightly a_killed_mp4_recording_is_repaired test now tries a repair mid-recording, and a helper moq_repair replaces the inline command it used before.
  • Docs: doc/bin/cli.md describes the lock and the refusal.

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

Comment thread rs/moq-cli/src/subscribe.rs Resolved
…error

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kixelated
kixelated enabled auto-merge November 15, 2026 18:01

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated review by review (OpenAI)

Reviewed commit: 563dbaf74e0734b7f57db7698b3d6ceb48bee5de.

No new actionable code defects found in this static pass. Checked that recording takes the exclusive lock immediately after creating the output, lock failure removes the new file, and repair obtains the same lock before scanning or writing. The file handle carries the lock through recording/repair, including the async conversion. Reviewed the live-recording refusal and post-kill repair test changes.

Verification limits: GitHub-only static review of the diff and relevant source/tests. I did not build, run tests, execute the model checker, or reproduce the reported integration results. This is a COMMENT review, not an approval or a CI/merge-readiness assertion.

@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

Since the last Pullfrog review, the PR adds documentation about the Windows lock and merges main.

  • Windows lock docs: doc/bin/cli.md now says that on Windows the recorder's lock also stops other programs from reading the recording until it finishes.
  • Code comment: rs/moq-cli/src/subscribe.rs explains why a shared lock is no fix: on Windows a shared lock also blocks writes through the handle that holds it, so the recorder couldn't write its own file. This settles the earlier Windows thread.

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

@kixelated
kixelated added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 036b978 Nov 17, 2026
9 checks passed
@kixelated
kixelated deleted the quest/m1/mp4-repair-lock branch November 17, 2026 13:06
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