Skip to content

Prefer BookOrbit's plain EPUB when its media overlay is unavailable - #165

Open
javirln wants to merge 1 commit into
crosspoint-reader:mainfrom
javirln:fix/bookorbit-plain-epub-media-overlay
Open

javirln wants to merge 1 commit into
crosspoint-reader:mainfrom
javirln:fix/bookorbit-plain-epub-media-overlay

Conversation

@javirln

@javirln javirln commented Dec 1, 2026

Copy link
Copy Markdown

Summary

The BookOrbit connector treats any EPUB that has a mediaOverlay field as a read-along EPUB. BookOrbit also reports that field for EPUBs without narration, as { available: false, durationSeconds: null }. When a book has both a plain EPUB and a read-along EPUB, the connector therefore sees two read-along files and falls back to the primary one, which is usually the read-along EPUB.

This PR counts an EPUB as read-along only when mediaOverlay.available === true (or when the filename ends in .readaloud.epub, as before).

Problem

fileId() in src/connectors/bookorbit.ts picks the EPUB the connector syncs against. It skips read-along files, which can be very large because they carry the narration audio:

const isReadAlong = (f: any) => !!f.mediaOverlay || /\.readaloud\.epub$/i.test(String(f.filename ?? ''));

GET /api/v1/books/:id in BookOrbit returns mediaOverlay as an object for every EPUB it has inspected (mediaOverlayCapabilityFromFields in BookOrbit's server/src/modules/reader/epub/epub-media-overlay-capability.ts). For example, the files of a book with a plain EPUB and a read-along EPUB look like this (trimmed):

[
  { "id": 81, "format": "epub", "role": "content", "mediaOverlay": { "available": false, "durationSeconds": null } },
  { "id": 80, "format": "epub", "role": "primary", "mediaOverlay": { "available": true, "durationSeconds": 36000 } }
]

!!{ available: false } is true, so the plain EPUB is classified as read-along. With no plain file left, the pool is every EPUB and the primary one (the read-along file) is chosen.

Effect

Observed with BookOrbit 3.11 and a book that has a plain EPUB (< 1 MB) and a read-along EPUB (813 MB, primary). The device (a CrossPoint reader) holds the plain EPUB, which is what BookOrbit's OPDS feed serves when a plain EPUB exists.

  • The match stores the read-along file as externalEdition.
  • The read-along EPUB is larger than the 200 MiB EPUB download limit, so every XPath <-> CFI conversion against it fails.
  • Pulls arrive as a bare percentage (bookorbit:836572) instead of an XPointer. The device places itself by percentage, which it computes differently from BookOrbit, and lands at a chapter start (80% on the device vs. 84% in BookOrbit).
  • Pushes go out without a CFI, and the device and BookOrbit never settle on the same position.

The bug came in with the read-along EPUB choice in #144. The existing tests modeled the field as mediaOverlay: true, which does not match the shape BookOrbit returns, so they could not catch it.

Fix

const isReadAlong = (f: any) => f.mediaOverlay?.available === true || /\.readaloud\.epub$/i.test(String(f.filename ?? ''));

Tests

  • New test: a book with a read-along primary EPUB ({ available: true }) and a plain EPUB ({ available: false }) resolves to the plain EPUB. It fails on main (expected '80' to be '81') and passes with the fix.
  • The existing read-along fixtures now use the object shape BookOrbit returns instead of mediaOverlay: true.
  • npm test: 88 files, 1279 tests pass. tsc --noEmit is clean.

Notes

Existing matches keep the file they were resolved to when they were created. A match that already stores a read-along file keeps using it until the book is matched again (or until that file returns 404, which already triggers a lookup). Re-resolving read-along editions that were stored before this fix could be a follow-up.

BookOrbit describes the media overlay of every EPUB it has inspected,
including `{ available: false, durationSeconds: null }` for a file
without narration. The connector treated any `mediaOverlay` value as a
read-along EPUB, so a book with both a plain EPUB and a read-along EPUB
looked like it had two read-along files, and the connector fell back
to the primary file, which is usually the read-along one.

That file carries the narration audio and is often larger than the
200 MiB EPUB download limit, so XPath <-> CFI conversion failed. Pulls
arrived as a bare percentage (`bookorbit:<pct>`) and pushes went out
without a CFI. A device reading the plain EPUB then placed itself by
percentage and never settled on the same position as BookOrbit.

Count an EPUB as read-along only when its overlay is available. The
test fixtures now use the object shape BookOrbit returns instead of
`mediaOverlay: true`, and a new test covers a plain EPUB reported with
an unavailable overlay next to a read-along primary.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T08:54:07.098250Z 36ad455 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

BookOrbit now treats an EPUB as read-along only when its media overlay is available or its filename ends in .readaloud.epub. The tests cover matching a plain-text EPUB when another EPUB has an unavailable overlay.

Changes: BookOrbit read-along detection

Layer / File(s) Summary
Overlay detection and matching tests
src/connectors/bookorbit.ts, test/connectors-more.test.ts
Read-along detection now requires mediaOverlay.available === true; the filename check is unchanged. The tests use media-overlay objects and verify that matching selects the plain-text EPUB when the other EPUB has an unavailable overlay.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: itsthisjustin

Merge Risk: Minimal · up to 36ad4

BookOrbit matching now prefers a plain EPUB when the other file's media overlay is unavailable. This avoids selecting an oversized read-along file that could break reading-position conversion. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: the BookOrbit connector now prefers the plain EPUB when its media overlay is unavailable. The raw summary confirms the read-along classification now requires mediaOve…
Description check Passed The description explains the bug, the BookOrbit overlay object shape that caused it, the fix, the new and updated tests, and the follow-up notes. It is directly related to the changeset.
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.
Full details: Title check

Explanation

The title states the main change: the BookOrbit connector now prefers the plain EPUB when its media overlay is unavailable. The raw summary confirms the read-along classification now requires mediaOverlay.available === true, which matches the title.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 84cf4c7c-9b34-4487-a6ef-4c269c9f95cd
Commits

Reviewing files that changed from the base of the PR and between 08f0fda and 36ad455.

Files selected for processing: 2

  • src/connectors/bookorbit.ts
  • test/connectors-more.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Recent review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional comments: 1

src/connectors/bookorbit.ts: 1

251-251: Data Integrity & Integration

The review question asks whether a supported BookOrbit server can return mediaOverlay: true. The head checkout does not support that case. Its code comment, its tests, and the PR's reported observation all describe an object with an available flag. The only evidence for the boolean case would come from an external server schema, and the search did not retrieve one. The concern therefore has no supporting evidence, and it does not present a repository defect.

This branch has not been deployed

No deployments
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