Skip to content

Verify HLS adaptive bitrate end-to-end#98

Open
aloewright wants to merge 2 commits into
mainfrom
conductor/alo-142-verify-hls-adaptive-bitrate-end-to-end
Open

Verify HLS adaptive bitrate end-to-end#98
aloewright wants to merge 2 commits into
mainfrom
conductor/alo-142-verify-hls-adaptive-bitrate-end-to-end

Conversation

@aloewright
Copy link
Copy Markdown
Owner

Closes ALO-142.

Adds an end-to-end verification path for Cloudflare Stream HLS adaptive bitrate:

  • scripts/verify-hls-abr.mjs — fetches a Stream master manifest (URL or bare video id), parses EXT-X-STREAM-INF entries, and exits non-zero unless the manifest exposes ≥2 variants and the throttle ladder (10 Mbps → 250 kbps using the same "highest variant ≤ ceiling" rule as hls.js) steps down monotonically.
  • docs/runbooks/hls-abr-verification.md — runbook covering the script and the manual Chrome DevTools throttle procedure for confirming hls.js switches renditions without stalls.

Existing unit coverage in src/frontend/lib/hls-manifest.test.ts already validates the parser + ABR ladder simulation; this PR adds the runtime/manual leg to round out the verification.

Test plan

  • npm test (491 passed)
  • npm run lint
  • Run node scripts/verify-hls-abr.mjs <ready stream_video_id> against a real Stream-encoded clip in staging and confirm OK: exit.
  • Manual DevTools throttle sweep per runbook on the Watch page.

Adds scripts/verify-hls-abr.mjs to fetch a Cloudflare Stream master
manifest and assert >=2 ABR variants with a monotonic throttle ladder,
plus a runbook documenting the manual DevTools throttle procedure.
Copilot AI review requested due to automatic review settings May 8, 2026 14:41
@aloewright aloewright added the conductor Conductor-managed PR label May 8, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

Warning

Rate limit exceeded

@aloewright has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 40 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6bdb7785-e5e5-4738-b1c5-b4f7298bfe10

📥 Commits

Reviewing files that changed from the base of the PR and between 4d3c13f and 2b8b759.

📒 Files selected for processing (2)
  • docs/runbooks/hls-abr-verification.md
  • scripts/verify-hls-abr.mjs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch conductor/alo-142-verify-hls-adaptive-bitrate-end-to-end

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 and usage tips.

@ecc-tools
Copy link
Copy Markdown
Contributor

ecc-tools Bot commented May 8, 2026

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new runbook and a Node.js script for verifying HLS adaptive bitrate (ABR) functionality. The script fetches a master manifest, parses its variants, and simulates a bandwidth throttle ladder to ensure that resolution steps down monotonically. Feedback focuses on cleaning up unrelated metadata changes in package-lock.json likely caused by npm version mismatches, as well as technical improvements to the script such as handling UTF-8 Byte Order Marks (BOM) in manifests and resolving variable shadowing for better code clarity.

Comment thread package-lock.json Outdated
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz",
"integrity": "sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==",
"dev": true,
"devOptional": true,
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.

medium

The package-lock.json contains a large amount of metadata changes (e.g., dev: true being replaced by devOptional: true or removed) that appear unrelated to the actual code changes. This typically happens when using a different version of npm than the one used to generate the original lockfile. To keep the pull request clean and avoid potential environment-specific dependency resolution issues, consider reverting these changes unless a lockfile format upgrade is intended.


function parseHlsMaster(text) {
const lines = text.split(/\r?\n/);
if (lines.length === 0 || !lines[0].startsWith('#EXTM3U')) return [];
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.

medium

HLS manifests can sometimes include a UTF-8 Byte Order Mark (BOM) at the beginning of the file. fetch().text() does not automatically strip this, which would cause the startsWith('#EXTM3U') check to fail even for valid manifests. It is safer to strip the BOM before checking.

Suggested change
if (lines.length === 0 || !lines[0].startsWith('#EXTM3U')) return [];
if (lines.length === 0 || !lines[0].replace(/^\uFEFF/, '').startsWith('#EXTM3U')) return [];

Comment thread scripts/verify-hls-abr.mjs Outdated
Comment on lines +98 to +99
const res = v.resolution ? `${v.resolution.width}x${v.resolution.height}` : '?';
console.log(` ${(v.bandwidth / 1000).toFixed(0).padStart(6)} kbps ${res.padEnd(10)} ${v.uri}`);
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.

medium

The variable name res is shadowing the Response object returned by fetch on line 85. While the original res is not used later in the function, renaming this to something more descriptive like resolutionStr improves readability and avoids confusion.

Suggested change
const res = v.resolution ? `${v.resolution.width}x${v.resolution.height}` : '?';
console.log(` ${(v.bandwidth / 1000).toFixed(0).padStart(6)} kbps ${res.padEnd(10)} ${v.uri}`);
const resolutionStr = v.resolution ? `${v.resolution.width}x${v.resolution.height}` : '?';
console.log(` ${(v.bandwidth / 1000).toFixed(0).padStart(6)} kbps ${resolutionStr.padEnd(10)} ${v.uri}`);

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73e1ce0c36

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/verify-hls-abr.mjs Outdated
Comment on lines +71 to +72
if (/^[a-f0-9]{20,}$/i.test(arg)) {
return `https://videodelivery.net/${arg}/manifest/video.m3u8`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Expand bare Stream IDs regardless of character set

The runbook says this script accepts a bare stream_video_id, but resolveUrl only expands IDs that match a 20+ hex pattern. Any valid opaque ID outside that regex (for example cf-uid) is passed straight to fetch, which throws ERR_INVALID_URL before verification runs. This makes the advertised CLI mode unreliable unless callers already know the hidden hex-only constraint.

Useful? React with 👍 / 👎.

Comment thread scripts/verify-hls-abr.mjs Outdated
const r = v?.resolution ? `${v.resolution.height}p` : '?';
console.log(` ceiling ${(c / 1_000_000).toFixed(2)} Mbps -> ${r} @ ${v?.bandwidth ?? 0} bps`);
}
const heights = picks.map((p) => p.v?.resolution?.height ?? 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject manifests with unknown rendition resolutions

The monotonic ABR check converts missing RESOLUTION values to 0, so a manifest with multiple variants but no resolution metadata still prints OK even though no resolution step-down was actually verified. That is a false positive for the script’s stated goal (checking rendition downshifts under throttling); it should fail (or explicitly mark inconclusive) when picked variants lack resolution heights.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

- Strip UTF-8 BOM in parseHlsMaster so manifests with a leading BOM don't
  silently fail the #EXTM3U tag check.
- Rename inner `res` → `resolutionStr` so it no longer shadows the fetch
  Response on the surrounding scope.
- Loosen `resolveUrl` to expand any opaque-looking token (>=8 chars,
  [a-z0-9_-]) to the canonical Stream URL — Cloudflare Stream UIDs are
  documented as opaque, so the previous hex-only regex rejected valid
  ids and broke the advertised CLI mode.
- Fall back to BANDWIDTH for the monotonic check (with an explicit WARN)
  when any picked variant lacks RESOLUTION metadata, so a manifest with
  no rendition heights doesn't silently exit OK.
- Revert package-lock.json metadata churn that was unrelated to ALO-142
  and only appeared because the PR was generated under a different npm.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conductor Conductor-managed PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants