← Back to Pull requests

Treat files without chapters as one chapter in the chapters feed #120

Closed
unknown closed this pull request without merging on Oct 17, 2026 21:04 UTC
View on GitHub
unknown unknown commented on Oct 17, 2026 18:29 UTC
Author

The chapters feed (/rss/derived/<id>-chapters.xml) returned a 500 for books without chapter metadata:

pages.py:322 derived_rss_feed -> renderer.trigger_rendering()
media_renderer.py:165 trigger_rendering -> m4btools.chapter_split_jobs(...)
m4btools.py:371 chapter_split_jobs -> max_chapter = max(chapter.num for _, chapter in chapter_info)
ValueError: max() iterable argument is empty

chapter_split_jobs asked get_multipath_chapter_info for chapters with fall_back_to_durations=False, which returns nothing when no file has usable chapters, while the single-file and segmented feeds already use fall_back_to_durations=True. With the fallback, a file without usable chapter information counts as one chapter. For a book with no usable chapters at all, every rendered file is then a copy of an original one, so the existing logic redirects to the book's original feed, as it already did for e.g. Dracula in the test library, whose first file is a single chapter and whose second file has a chapter that starts after the end of the file.

I went with the redirect rather than a 404 since it's what the other rendered feeds already do when they'd be the same as the original, and it keeps old links and subscriptions working if a book's chapter information goes away. It also didn't need a separate check in the route that would have to agree with has_chapter_info.

"Usable" is doing some work there: get_multipath_chapter_info falls back for any file whose chapter information it can't use, which means files with no chapters and files with bad chapter metadata (a chapter starting after the end of the file). When only some of a book's files have usable chapters, the others used to be silently left out of the chapters feed, and are now included as one chapter each. That's a bit broader than "files without chapter information", but it's what the segmented feed already does with these files, and it seems strictly better than losing the audio.

The segmented feed wasn't affected, since it already used the fallback. The new tests request every rendered feed for every test book and check that each one either renders or redirects to the original feed, and none of them errors; they also check the redirects for the books without chapters, and the chapter-splitting jobs for files without (or with only some) chapter information. They fail without the fix.

The second commit adds a small warning sign to the "Chapters" button in the book list when some of a book's chapter information is broken, with a tooltip (an SVG <title>, which is also its accessible name) saying "Some of this book's chapter information is broken, so those files are one chapter each". It's coloured with --exclude, so the themes all pick it up. To keep the list and the feed from disagreeing about what counts as broken, the check that get_multipath_chapter_info did inline is now file_probe.has_broken_chapters, which the renderer uses as broken_chapter_info. It only looks at the file_metadata stored on the entry, so it doesn't add any I/O to rendering the list. Files with no chapter information at all don't get the warning, since that's perfectly normal.

Broken chapter information still counts for has_chapter_info, so a book whose chapter information is broken in every file still links to the chapters feed (which redirects to the original one), with the warning. I think that's more useful than hiding the button, since the warning is the only sign that the book's chapter metadata needs fixing, and it means the warning can't show up without the button.

Fixes #118.

Diff: 449 lines (+336 / -113) across 5 files Reviewer: pganssle Review duration: 155m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 449 lines diff across 5 files
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.366
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #120"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45.4% (MEDIUM) · Higher = larger blast radius
45.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.9% · Safe to merge
17.9%