Skip to content

fix(chapterthumbs): tolerate high-latency extraction - #703

Closed
tomislav wants to merge 1 commit into
Silo-Server:mainfrom
tomislav:codex/fix-688-chapter-thumbnail-timeouts
Closed

tomislav wants to merge 1 commit into
Silo-Server:mainfrom
tomislav:codex/fix-688-chapter-thumbnail-timeouts

Conversation

@tomislav

@tomislav tomislav commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #688

Closes #688

Chapter thumbnail extraction used 8-second and 10-second SDR deadlines, plus 20-second and 25-second HDR deadlines. Those limits are too short for valid media on high-latency storage. A production recheck measured 18.5 seconds for the reported SDR capture point and 38.5–42.7 seconds for the reported HDR capture points. A near-end HDR seek took 108.2 seconds on the first run and 72.6 seconds on an immediate repeat.

When exec.CommandContext killed FFmpeg at the deadline, the returned error only exposed signal: killed. Hardware timeouts were therefore classified as hw_killed, and timeout failures did not enter the file-level cooldown.

High-latency storage = Network mounted storage (SMB) under heavy load.

Approach

  • Use fixed per-attempt ceilings of 60 seconds for SDR and 180 seconds for HDR. Hardware and CPU fallback attempts receive separate deadlines.
  • Keep the remote request timeout derived from the same attempt budgets, plus the existing probe and transport overhead.
  • Preserve both the context deadline and the process exit error when FFmpeg is killed, then classify a deadline before the generic killed-process case.
  • Treat hw_timeout and cpu_timeout as file-level failures. The worker stops the current chapter batch after the first timeout and uses the existing 15-minute, 1-hour, 6-hour, and 24-hour retry cooldown.

The ceilings stay fixed across retries. Increasing the attempt deadline on each retry would intentionally fail valid high-latency files once or more before giving them enough time, while the existing cooldown already supplies exponential retry timing.

Validation

Production reproduction and re-verification:

  • The reported SDR frame extracted successfully in 18.515 seconds.
  • The reported HDR frames extracted successfully in 38.476 and 42.695 seconds.
  • A near-end HDR seek took 108.194 seconds, followed by 72.618 seconds on an immediate repeat. Production caches were not flushed, so these are observed timings rather than a controlled cold-cache benchmark.

Passing checks:

go test ./internal/chapterthumbs/... -count=1
go test -race ./internal/chapterthumbs/... -count=1
make embed-stub
go build ./...
gofmt -l .
go vet ./...
golangci-lint run --new-from-merge-base=origin/main ./...
pnpm install --frozen-lockfile
pnpm run lint
pnpm run format:check
pnpm run build
make test-web
make verify-settings-bindings-all
make verify-playback-fixtures
make verify-local-paths
git diff --check

pnpm run lint completed with 154 inherited warnings and no errors. make test-web passed 2,021 tests across 283 files.

make test-go did not pass because of failures reproduced on an untouched main checkout:

  • internal/jellycompat: TestBeginWebOperationRecoversDeadProcessLock and TestBeginWebOperationRejectsLiveProcessLock
  • internal/playback: existing NVENC/GPU probe tests terminated with signal: killed

internal/transcodenode also had one asynchronous tracking failure under full-suite load; that test passed when rerun on this branch and on untouched main.

The installed codex review command could not initialize because its state database is read-only in the workspace. I reviewed the complete diff manually against main, including timeout propagation through local and remote extraction, error-chain classification, batch termination, and file retry state. No concrete issue was found.

Risks

Slow or stalled files can occupy an extraction slot longer: up to 60 seconds per SDR attempt or 180 seconds per HDR attempt. Hardware-to-CPU fallback can consume both budgets. The first timeout stops the file's current batch and applies the existing cooldown, limiting repeated work.

No API, schema, migration, client, or jellycompat behavior changes.

AI Disclosure

  • Tool(s): OpenAI Codex
  • Model(s): GPT-5
  • Involvement: AI-assisted
  • Adversarial review: Reviewed the complete diff against main, focusing on local and remote timeout propagation, preservation and classification of context-killed FFmpeg errors, and file-level batch termination and retry state. The automated codex review command could not initialize because its state database was read-only, so the review was performed manually. No concrete findings remained.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of hardware and CPU extraction timeouts for SDR and HDR content.
    • Increased extraction timeout windows to better accommodate high-latency processing.
    • Preserved meaningful timeout details when extraction processes are terminated.
    • Timeout failures now stop further chapter processing and apply file-level backoff consistently.

@coderabbitai

coderabbitai Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e961d6f2-50b9-48b5-bc2e-8a980c8f2041

📥 Commits

Reviewing files that changed from the base of the PR and between 78b5d39 and 7cf4fc6.

📒 Files selected for processing (4)
  • internal/chapterthumbs/extractor.go
  • internal/chapterthumbs/extractor_test.go
  • internal/chapterthumbs/service.go
  • internal/chapterthumbs/service_test.go

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Extraction now preserves context deadline errors when FFmpeg is killed, classifies deadline failures as timeouts, and uses longer SDR/HDR budgets for hardware and CPU attempts. Timeout failures now update file failure state, apply cooldowns, and stop later chapter processing. Tests cover these behaviors.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 7cf4f

The change extends chapter-thumbnail extraction deadlines and classifies timeouts for cooldown handling; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant ProcessRequest
  participant Extractor
  participant FFmpeg
  participant FileFailureState
  ProcessRequest->>Extractor: start chapter extraction
  Extractor->>FFmpeg: run with content timeout budget
  FFmpeg-->>Extractor: deadline and process-kill errors
  Extractor-->>ProcessRequest: return timeout reason
  ProcessRequest->>FileFailureState: record failure and cooldown
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: improving chapter thumbnail extraction for high-latency storage.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

[bug] Chapter thumbnail extraction times out on high-latency media

1 participant