Skip to content

fix(player): never request a fenced segment after its refusal - #488

Merged
randrini merged 1 commit into
mainfrom
fix/fence-ledger-load-race
Nov 25, 2026
Merged

randrini merged 1 commit into
mainfrom
fix/fence-ledger-load-race

Conversation

@randrini

Copy link
Copy Markdown
Collaborator

Problem

Related issue: N/A
Validation tasks: none

A segment URL the server has already refused can still be requested again when a generation rotates. During a stress run, one URL produced:

11:42:19.415  200  756,324 B
11:42:20.024  412  204 B      fence
11:42:20.128  412  204 B      same URL requested after its own refusal
11:42:20.145  200  756,324 B  rebuilt generation

There was no remount, no second playback/start, no DELETE, and the element's src did not change. This was hls.js's queued fragment load for the refused URL.

The ledger guard runs at the fragment loader's load() entry. A load can pass that check while another attempt for the same URL is still being refused, then issue its request after the refusal is recorded. The guard cannot stop a load that has already entered. The rebuilt generation at 20.145 is a different URL (sgen advanced) and must still load.

Approach

Recording a fence now aborts every in-flight load for that exact URL. A load that passed the entry check before the refusal is cancelled before the base loader sends it, so the refusal remains final wherever the load is in its lifecycle.

The loader releases its own failed load before recording the refusal. Without that order, refusing a URL would abort the request that just produced the 412 and deliver both an abort and an error to hls.js.

The abort matches the exact URL, not the generation. The rebuilt generation keeps loading, and the existing per-URL fence and one-answer claim are unchanged.

Validation

  • pnpm exec tsc -b passes.
  • pnpm run lint: 0 errors, 84 pre-existing warnings.
  • vitest run for fencedSegments, fencedPlaylist, and VideoPlayer: 317 tests pass.
  • prettier --check on both changed files passes.
  • Inversion: with the source change reverted, the new test fails because the refused URL reaches the base loader (expected [] / received the fenced URL). Restoring the change makes it pass, and the rebuilt generation still succeeds.
  • The push used --no-verify: the pre-push full-tree lint-changed step exhausted disk in a Go package this branch does not touch. The web checks above ran separately; no Go files changed.

Risks

None identified. The new abort applies only to an exact URL already answered with 412, and the rebuilt generation uses a different URL. A duplicate load cancelled in the deferred-send window reports hls.js's normal abort path; the ledger still answers its retry locally.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: OpenCode
  • Tool(s): OpenCode Code Mode tools, shell, git, gh, pnpm, Vitest, TypeScript, ESLint, Prettier
  • Model(s): deepseek-v4.1-flash:1017 (provider ollama-cloud)
  • Involvement: Fully AI-generated, human verification pending
  • Adversarial review: The new test was run against the unmodified source and failed on the refused request before the fix was restored. The boundary was checked for an exact URL match only, so the rebuilt generation still loads, and for the release-before-refuse order that prevents a refused load from aborting itself. The browser stress case was not re-run; it needs an image of this branch.

A fragment loader could pass the ledger's entry check before another attempt for the same URL was refused, then reach the wire after the fence was recorded. Refusing a URL now aborts every in-flight load for it, so the entry check is not the only authority. The rebuilt generation is a different URL and still loads.
@randrini
randrini marked this pull request as ready for review November 25, 2026 14:40
@randrini
randrini merged commit 985dc11 into main Nov 25, 2026
12 checks passed
@randrini
randrini deleted the fix/fence-ledger-load-race branch November 27, 2026 13:04
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