Repository navigation
Conversation
Portrait outputs were matched to the tier of their long side, so a 1080x1920 output got the 1440p cap. Tiers now meet at geometric midpoints, as the HLS ladder's rungs do.
result.mp4 and its screenshot are rewritten in place by admin reprocess and replacement, so a year-long immutable header would keep serving the old bytes. Only generation-unique desktop outputs and ladder files are marked immutable.
The ladder ran inline at the end of the processing and finalize workflows, holding them (and prefetch cleanup) for up to three hours, and wrote to a fixed key next to result.mp4 that went stale when the MP4 was replaced or loudness-levelled. Processing and finalize now queue a separate workflow. It waits out the audio-levelling window, encodes from the MP4 viewers actually play, and writes under a prefix derived from that MP4's key and ETag, so ladder files are immutable. hlsMasterKey is only recorded once the job is complete and the MP4 is unchanged; any failure leaves the video on its progressive MP4. Short clips, single-rung sources and non-S3 storage are skipped.
Edits publish a new MP4 while spreading the old source, and duplicates copy the source verbatim, so both carried an hlsMasterKey for other content. Edits clear it and queue a fresh ladder; duplicates start on their MP4.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
| await tx | ||
| .update(videos) | ||
| .set({ source: { ...video.source, hlsMasterKey: target.masterKey } }) | ||
| .where(eq(videos.id, Video.VideoId.make(videoId))); |
There was a problem hiding this comment.
Ladder completion breaks active edits
Publishing hlsMasterKey changes the whole source while an active edit still expects its saved value. matchesEditOperation then rejects edit callbacks and throws “Edit operation has been replaced.” Failed-edit cleanup uses the same comparison, so the recording can remain stuck as processing.
Skip ladder publication while an edit is active, or make the edit checks ignore ladder-only changes.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/workflows/share-hls-ladder.ts
Line: 354-357
Comment:
**Ladder completion breaks active edits**
Publishing `hlsMasterKey` changes the whole `source` while an active edit still expects its saved value. `matchesEditOperation` then rejects edit callbacks and throws “Edit operation has been replaced.” Failed-edit cleanup uses the same comparison, so the recording can remain stuck as processing.
Skip ladder publication while an edit is active, or make the edit checks ignore ladder-only changes.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Note
🤖 claude-opus-5-5 on behalf of Aatman AJ Jain
Fixed in 8b30279. persistShareHlsLadder now checks video_uploads inside the same FOR UPDATE transaction, and an active edit always has that row. While the row exists it returns busy and leaves source untouched. The workflow re-checks every 60 s for up to an hour. When the edit commits, it has already replaced the MP4, cleared hlsMasterKey and queued its own ladder, so a ladder that waited behind it is dropped instead of re-encoded. Tests: waits for an edit holding the video… and leaves a ladder to the edit that replaced the MP4… in share-hls-ladder.test.ts.
| if ( | ||
| started.status === "busy" || | ||
| started.status === "unreachable" || | ||
| started.status === "unconfirmed" | ||
| ) | ||
| return { status: "retry" }; |
There was a problem hiding this comment.
Retries overwrite immutable ladder files
An unconfirmed start can mean the server accepted the job but its response was lost. Retrying creates another job with the same upload keys. Both encoders can then overwrite playlists and media independently, even after one job finishes.
The results can differ, including when NVENC falls back to libx264. Cached playlists can then point at the wrong byte ranges. Do not resend an uncertain start without a way to recover or deduplicate the accepted job.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/workflows/share-hls-ladder.ts
Line: 304-309
Comment:
**Retries overwrite immutable ladder files**
An `unconfirmed` start can mean the server accepted the job but its response was lost. Retrying creates another job with the same upload keys. Both encoders can then overwrite playlists and media independently, even after one job finishes.
The results can differ, including when NVENC falls back to `libx264`. Cached playlists can then point at the wrong byte ranges. Do not resend an uncertain start without a way to recover or deduplicate the accepted job.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Note
🤖 claude-opus-5-5 on behalf of Aatman AJ Jain
Fixed in 8b30279. Only busy (a 503 refusal) and unreachable (the connection never opened) are retried now. unconfirmed ends the run and the video stays on its MP4, so two jobs can never write the same prefix. Test: does not resend a start the media server may have accepted (one /video/ladder call, no hlsMasterKey).
There was a problem hiding this comment.
Note
🤖 claude-opus-5-5 on behalf of Aatman AJ Jain
Follow-up in 3ac8cd9 for the proxy case your summary raised: a start answered 502/503/504 may still have been accepted. Every start now uploads under its own share-hls/<source-fingerprint>/<random-run-id>/ directory (shareHlsRunPrefix). A retried start can no longer touch a running job's files, and hlsMasterKey names the files of the job that was actually polled to completion. unconfirmed starts are still not retried. Test: gives every start its own prefix so a refused start cannot share files.
There was a problem hiding this comment.
This resolves the overwrite concern. Each start attempt gets a distinct shareHlsRunPrefix, so even if a 502/503/504 response masks an accepted job, that job cannot overwrite files from a later attempt. The workflow persists only the master key for the job it actually polls to completion, and still does not retry unconfirmed starts. The new test covers the distinct-prefix behavior.
| } finally { | ||
| for (const jobId of held) jobManager.deleteJob(jobId); | ||
| } | ||
| }, 180_000); |
There was a problem hiding this comment.
New timeout exceeds frozen allowance
The new test adds a 180_000 per-test timeout. AGENTS.md forbids new raised per-test timeouts and says existing allowances may only decrease. This file already has six allowed occurrences in scripts/test-lint/oxlintrc.json; the added test makes seven.
Split the fast admission/header checks from encoding, or wait for a completion signal without another raised timeout. This repository requirement must be satisfied before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/media-server/src/__tests__/lib/hls-ladder-route.integration.test.ts
Line: 338
Comment:
**New timeout exceeds frozen allowance**
The new test adds a `180_000` per-test timeout. `AGENTS.md` forbids new raised per-test timeouts and says existing allowances may only decrease. This file already has six allowed occurrences in `scripts/test-lint/oxlintrc.json`; the added test makes seven.
Split the fast admission/header checks from encoding, or wait for a completion signal without another raised timeout. This repository requirement must be satisfied before merging.
**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Note
🤖 claude-opus-5-5 on behalf of Aatman AJ Jain
Fixed in acbb6ab. The route integration suite is back to its origin/main contents. The bulk-admission 503 check and the Cache-Control upload-header checks now live in ladder-bulk-admission.test.ts. That file does no encode and raises no timeouts. node scripts/test-lint/run.mjs passes (950 files).
…e suite Editing the route integration suite made test lint check its existing raised timeouts. The bulk admission and Cache-Control checks need no encode, so they live in a fast file of their own.
An edit fences the video on its starting source, so recording the ladder mid-edit made the edit's callbacks reject. The ladder now waits while an upload row holds the video and leaves the result to the edit if it replaced the MP4. An unconfirmed start may be running; resending it could have two jobs write the same immutable files, so it is no longer retried.
|
Note 🤖 All three Greptile findings are fixed on
Also fixed: the Contract with #4832 is unchanged: Verified: @greptileai review |
A start the proxy answered with 502/503/504 may still have been accepted. Each start now writes under a fresh run directory below the source fingerprint, so a retried start can never overwrite files of a job that is still running, and the recorded key names the files of the job that was polled.
|
@AatmanAJ is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
|
Note 🤖 Pushed 3ac8cd9 for the remaining point in the 4/5 summary (a retry after a proxy error hiding an accepted job). Each ladder start now writes under its own run directory, so retried starts never share or overwrite files. The PR body has the updated Re-verified: @greptileai review |
Problem
Share links play one progressive MP4. Desktop uploads are muxed with
-c copyand web uploads are transcoded without a bitrate cap or keyframe interval. A viewer on a slow link, or watching at 1.25x, waits at the start and stalls partway through, and nothing can step quality down. The media server already has an fMP4 HLS ladder with separate AAC audio (hls-ladder.ts/hls-ladder-encode.ts), but only the developer API uses it.Change
workflows/share-hls-ladder.ts): once processing (process-video), desktop finalization or an edit finishes, a separate workflow is queued. It calls the existing/video/ladderendpoint withmaxTier: "1080p", rungs 1080p/720p/360p (only up to the source size),includeAudio: true(one AAC track that every rung shares) andpriority: "bulk".hlsMasterKeyis written only after the job completes, and only if the MP4 it was encoded from is still the one viewers get. If anything fails (start rejected, server busy for ~20 min, job error, timeout, MP4 replaced twice), the video stays on its progressive MP4.resolveRecordingObjectKey, which includes loudness-levelled audio). For videos the media server may still level (3 to 900 s), it first waits out the levelling window (≤150 s) so the ladder audio matches the MP4.hlsMasterKeyand queue a new ladder. Duplicates drop it. Admin reprocess and replacement already resetsource.priority: "bulk"jobs only while at least one slot stays free./video/processtranscodes now get-maxrate/-bufsizecaps based on the output's short side (matching the ladder tiers) and a 2 s keyframe interval (-g) on both libx264 and NVENC. Upload helpers acceptcacheControland send it as a header (S3 does not signCache-Control, so older workers keep working).public, max-age=31536000, immutable. Webresult.mp4and its screenshot are rewritten in place by reprocess and replacement, so they are left as they were.Contract with #4832
source.hlsMasterKey=<ownerId>/<videoId>/.recording/outputs/share-hls/<24-hex>/<32-hex>/master.m3u8. The first hex issha256(sourceKey + "\n" + ETag), and the second is a random id for each start, so no two jobs ever write the same files. It starts with the<ownerId>/<videoId>/prefix, uses only[A-Za-z0-9_./-]and has no..or empty segments, asgetHlsMasterKeyrequires.master.m3u8:audio.m3u8,audio.m4s,{1080p,720p,360p}.m3u8,{…}.m4s. The master playlist references<rung>.m3u8andURI="audio.m3u8"as bare relative names (HLS_PLAYLIST_FILE_PATTERN). The rendition playlists are single-file byte-range playlists whose segment andEXT-X-MAPURIs are<rung>.m4s(HLS_MEDIA_FILE_PATTERN). These names come unchanged fromencodeHlsLadder.hlsMasterKey: Schema.optional(Schema.String)field toVideo.sourceinpackages/web-domain/src/Video.ts. The edit is identical to the one in this PR, so whichever merges second rebases without a conflict.Audit items #1, #15, #23 (workflow uploads) and #30.
Verification
bun run typecheck,biome checkon the changed filesvitest run __tests__/unit(746 files pass), including the newshare-hls-ladder.test.ts: publish, failure fallback, unavailable or busy media server, audio-level wait, MP4 replaced during the encode, skip cases. Also updated finalize, media-processing, duplicate and edit-replacement tests.bun testmedia-server:nvenc-encoder(VBV tiers, portrait cap,-g),hls-ladder,media-video.integration, and a newladder-bulk-admissiontest for bulk admission and theCache-Controlupload header;lint:testspassesConfidence Score: 5/5

The PR appears safe to merge; the latest changes prevent retries from sharing ladder files.Summary
Adds HLS generation after video processing, desktop finalization, and edits, while keeping the progressive MP4 as the fallback.
All three previous findings are addressed. No new actionable issues were found in the latest changes.
Reviews (3) · Last reviewed commit: "fix(web): give every share ladder start ..." · Reviewed by Greptile