Skip to content

fix(mux): reassemble PES headers with bounded staging - #5618

Merged
kixelated merged 3 commits into
mainfrom
quest/m1/ts-reliability/pes
Oct 16, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/m1/ts-reliability/pes

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Problem

A legal clear PES header split across TS packets was discarded as truncated. PES payloads and sections awaiting a clock could also retain input indefinitely, and short declared video payloads could escape as complete access units.

Approach

Assemble only incomplete headers before parsing; preserve the complete-header fast path and special stream-ID layouts. Honor declared payload lengths and reset assembly on loss, discontinuity, remapping, new starts, and EOF. Damaged audio can salvage complete units while incomplete tails are discarded.

PES payloads and untimed sections share a program-wide 16 MiB retention budget, derived from half a MoQ group's byte limit; held sections also share a 4,096-unit ceiling. Ownership accounting releases reservations on flush, damage, remapping, and drop. Following the approved policy, SCTE-35 sections without a source-local media anchor fail at EOF or a clock break, including when a shared timebase already has an offset. Three previous success fixtures now supply anchors.

Regressions cover every legal header split, special IDs, malformed lengths/prefixes, duplicate/lost packets, declared truncation, shared retention and rollback, and missing clocks. An automated fixture moves generated audio/video header splits into following null slots while preserving packet count and PCR position; it runs in the TS workflow. The 18-case PID/payload/fragmentation benchmark is wired nightly. The completed quest and its reference are removed.

Impact

  • No exported API, configuration, catalog, or wire-format change.
  • TS import now refuses exhausted staging and unanchored section EOF/clock breaks instead of growing memory or inventing timestamp zero.
  • Short declared access units are treated as damaged; legal fragmented clear headers now import successfully.
  • User-facing import documentation describes the stricter timing and retention contract.

Validation

just check and just ci check pass on current main: 3,130 default native tests, 466 capture tests, 192 playback tests, and the 97/10 minimal media lanes, plus scoped compile/feature, documentation, quest, shell, workflow, and JS checks. just test interop --all passes.

All 180 focused importer/parser tests pass. Removing the EOF and clock-break guards makes both new refusal regressions fail. The 20-second generated fragmented-header round trip passes independent FFmpeg content/decoding and TSDuck continuity, T-STD, scheduling, and PCR checks: 500 video and 842 audio header splits; all 744 PCR accuracy intervals within ±500 ns. Fixture controls and the 18-case benchmark also pass.

Alternatives

Retaining the previous section-only timestamp-zero EOF contract was considered; the maintainer chose explicit refusal. A public resource-limit API was unnecessary because the existing group limits express a bounded private policy.

Follow-ups

No new quest was needed. The separate PES timing/header semantics quest remains out of scope. An initial broader validation invocation was stopped before tests to release compiler-cache locks during resource coordination; the final current-main scoped invocation passed and selects no io_uring test package.

(Written by GPT-6)

kixelated and others added 3 commits October 15, 2026 11:35
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 <noreply@openai.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Outcome: the full PES quest is implemented and removed with its reference. Legal fragmented clear headers assemble correctly; retention is bounded across PIDs, damage cannot concatenate units, and the approved unanchored-section EOF/clock-break policy is enforced.

Validation passes: required scoped check and CI gates; 3,130 default native tests, 466 capture, 192 playback, 97/10 minimal media lanes; 180 focused parser/importer cases; all-language interop; generated 20-second fragmented-header round trip and independent FFmpeg/TSDuck checks. All 744 PCR accuracy intervals are within ±500 ns. The two new clock refusal regressions fail when their guards are removed. The final branch merges cleanly with current main and the worktree is clean; all owned validation processes are terminal.

Public API/wire: no new export/configuration/catalog field or wire-format change. Input acceptance becomes stricter for exhausted staging, incomplete declared access units, and SCTE-35 sections without an anchor. No follow-up quest was created; the existing separate PES timing semantics work remains independent.

Recommended disposition: leave this draft for the normal review/merge workflow; no further maintainer policy decision is pending here.

(Written by GPT-6)

@kixelated
kixelated marked this pull request as ready for review October 15, 2026 23:31
@kixelated
kixelated marked this pull request as draft October 16, 2026 00:32
@kixelated
kixelated marked this pull request as ready for review October 16, 2026 00:32
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T00:36:42.800305Z 93cc519 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 93cc519.

No actionable bugs found. Header staging preserves the complete-header fast path, handles split/special-ID layouts, and clears damaged state across loss, new starts, remaps and EOF. Shared byte/unit reservations release consistently, including rollback; unanchored-section refusal correctly depends on this source's clock rather than a shared offset alone.

Direction: bounded private staging and explicit damaged-input handling are proportionate. Tests cover the important ownership and parser boundaries without weakening the existing quality budgets.

Verification: static GitHub review plus TS job 116694733609 in run 38814226938, whose checkout identifies this head/base merge. Those logs show fragmented-header controls, decoded-content comparison and transport/T-STD/PCR checks succeeding. That fixture covers generated closed-GOP H.264/AAC and permits startup acquisition loss; I did not independently run tests or benchmarks.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merge summary: no code changes from the merge pass.

  • Head 93cc519 merges cleanly with current main; all PR checks are green, including the new fragmented-PES TS validation step.
  • Reviews on this head: the OpenAI reviewer found no actionable bugs, and Codex finished with no findings.
  • Decisions carried in the PR: staging is bounded by a private program-wide budget derived from the existing MoQ group limits (no new public knob), and SCTE-35 sections with no media anchor are refused at EOF or a clock break instead of being stamped at zero, per the earlier maintainer choice.
  • The open TS-export PRs fix(ts)!: run the export one delay behind its source #5553 and fix(ts): keep the program tables within TBsys and Bsys #5606 touch neighbouring files (test/ts/README.md, test/ts/run.sh, test/justfile, doc/bin/cli.md) but not the importer; whichever lands second may need a trivial rebase.

Enabling auto-merge on this head.

(Written by Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 16, 2026
@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e146872c-5678-4954-8577-ccbf7c256588
📥 Commits

Reviewing files that changed from the base of the PR and between 810f7cd and 93cc519.

📒 Files selected for processing: 12
  • .github/workflows/ts.yml
  • doc/bin/cli.md
  • quest/m1/ts-reliability/README.md
  • quest/m1/ts-reliability/pes.md
  • rs/moq-mux/src/container/ts/import.rs
  • rs/moq-mux/src/container/ts/psi.rs
  • sh/gh/nightly.sh
  • test/justfile
  • test/ts/README.md
  • test/ts/fragment_pes.py
  • test/ts/fragment_pes.test.py
  • test/ts/run.sh
💤 Files with no reviewable changes: 2
  • quest/m1/ts-reliability/pes.md
  • quest/m1/ts-reliability/README.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

Walkthrough

The importer now assembles PES headers across TS packets, applies shared limits to retained PES and section data, and requires media timestamps before releasing held sections. The TS test harness adds a mode that generates fragmented audio and video PES headers and runs transport and content checks.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 93cc5

The change adds fragmented PES header handling with bounded staging, and no concrete merge-blocking risk was identified. Callers now receive errors for unanchored SCTE-35 sections at end of input, which is documented and intended.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 62.07% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 58 functions across 6 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main changes: PES header reassembly and bounded staging in the mux.
Description check Passed The description directly explains the problem, implementation, impact, validation, and follow-ups for the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 62.07% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 58 functions across 6 files. (4 skipped: 4 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 Clippy (1.98.1)

Clippy execution timed out

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

Comment @coderabbitai help to get the list of available commands.

Merged via the queue into main with commit a5b4859 Oct 16, 2026
14 checks passed
@kixelated
kixelated deleted the quest/m1/ts-reliability/pes branch October 16, 2026 00:59
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