docs(kobo): record entitlement semantics from upstream packet captures #32

Open
arne wants to merge 4 commits from kobo-api-entitlement-semantics into main
Owner

Research pass over the published Kobo reverse-engineering, folded into docs/kobo-api.md. Doc-only; no behaviour change.

Why

v0.1.9 left one question open: the server now offers a changed book, but the device didn't re-download it. That question has a published answer.

The finding

From packet captures in calibre-web#3133: ChangedEntitlement invalidates the device's local copy and stops there. The only observed automatic re-download trigger is a changed BookEntitlement.Accessibility inside a NewEntitlement — and even that covers only the first 5 new books of a sync request.

Offering a change and fetching it are separate mechanisms. v0.1.9 fixed the first. The second has no clean protocol affordance.

Also recorded

Three things we already do correctly, now with the reasoning attached so they don't get "improved" later:

  • RevisionId stays equal to EntitlementId. Nickel keys entitlements on EntitlementId and ignores RevisionId, so a versioned <uuid>-v<n> files a second copy rather than replacing the book. Upstream shipped versioned revisions and reverted them after an on-device retest (xdoubleu#1756 → #1847).
  • ChangedEntitlement carries no ReadingState. That block seeds device state and can overwrite live progress.
  • Never-delivered books go out as New. ChangedEntitlement for a book the device doesn't hold is dropped without trace (calibre-web#3649).

Two new hazards:

  • A mass file rewrite re-announces the library. The session fingerprint includes file_hash, and Nickel marks a re-offered book as not downloaded. Upstream treats this class as release-blocking (Calibre-Web-NextGen#2207).
  • social_host still points at social.kobobooks.com, which no longer resolves. On firmware 4.38–4.45 the resulting WebRequestErr can mark an otherwise-clean sync as failed (bookorbit#1550). Not observed on our 4.45 Libra Colour, so it's filed as a hypothesis with a fix sketch, not a change.

Deliberately not implemented

The two-phase Preview → Full sequence (calibre-web#3394, open and unmerged) does force a re-download: ChangedEntitlement with Accessibility: "Preview", clear the delivered flag, X-Kobo-sync: continue, then NewEntitlement with Full. We already have every primitive it needs. It's documented rather than shipped because it rests on undocumented firmware behaviour and an upstream patch nobody has merged.

Note on sources

No official Kobo documentation exists; this is a private API. Every claim added here is attributed to the issue or PR it came from, with its verification status stated — several upstream sources explicitly say they were never confirmed on hardware.

🤖 Generated with Claude Code

Research pass over the published Kobo reverse-engineering, folded into `docs/kobo-api.md`. Doc-only; no behaviour change. ## Why v0.1.9 left one question open: the server now offers a changed book, but the device didn't re-download it. That question has a published answer. ## The finding From packet captures in [calibre-web#3133](https://github.com/janeczku/calibre-web/issues/3133): **`ChangedEntitlement` invalidates the device's local copy and stops there.** The only observed automatic re-download trigger is a changed `BookEntitlement.Accessibility` inside a `NewEntitlement` — and even that covers only the first 5 new books of a sync request. Offering a change and fetching it are separate mechanisms. v0.1.9 fixed the first. The second has no clean protocol affordance. ## Also recorded Three things we already do correctly, now with the reasoning attached so they don't get "improved" later: - **`RevisionId` stays equal to `EntitlementId`.** Nickel keys entitlements on `EntitlementId` and ignores `RevisionId`, so a versioned `<uuid>-v<n>` files a *second copy* rather than replacing the book. Upstream shipped versioned revisions and reverted them after an on-device retest ([xdoubleu#1756](https://github.com/xdoubleu/tools.xdoubleu.com/pull/1756) → [#1847](https://github.com/xdoubleu/tools.xdoubleu.com/pull/1847)). - **`ChangedEntitlement` carries no `ReadingState`.** That block seeds device state and can overwrite live progress. - **Never-delivered books go out as `New`.** `ChangedEntitlement` for a book the device doesn't hold is dropped without trace ([calibre-web#3649](https://github.com/janeczku/calibre-web/issues/3649)). Two new hazards: - **A mass file rewrite re-announces the library.** The session fingerprint includes `file_hash`, and Nickel marks a re-offered book as not downloaded. Upstream treats this class as release-blocking ([Calibre-Web-NextGen#2207](https://github.com/new-usemame/Calibre-Web-NextGen/pull/2207)). - **`social_host` still points at `social.kobobooks.com`, which no longer resolves.** On firmware 4.38–4.45 the resulting `WebRequestErr` can mark an otherwise-clean sync as failed ([bookorbit#1550](https://github.com/bookorbit/bookorbit/issues/1550)). Not observed on our 4.45 Libra Colour, so it's filed as a hypothesis with a fix sketch, not a change. ## Deliberately not implemented The two-phase `Preview` → `Full` sequence ([calibre-web#3394](https://github.com/janeczku/calibre-web/pull/3394), open and unmerged) does force a re-download: `ChangedEntitlement` with `Accessibility: "Preview"`, clear the delivered flag, `X-Kobo-sync: continue`, then `NewEntitlement` with `Full`. We already have every primitive it needs. It's documented rather than shipped because it rests on undocumented firmware behaviour and an upstream patch nobody has merged. ## Note on sources No official Kobo documentation exists; this is a private API. Every claim added here is attributed to the issue or PR it came from, with its verification status stated — several upstream sources explicitly say they were never confirmed on hardware. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Pulls together the published reverse-engineering on what Nickel actually
does with each envelope kind, which answers the open question from the
v0.1.9 work: why a changed book is offered but never re-downloaded.

The load-bearing finding, from packet captures in calibre-web#3133, is
that ChangedEntitlement invalidates the device's local copy and stops
there. The only observed automatic re-download trigger is a changed
BookEntitlement.Accessibility inside a NewEntitlement, and even that
covers only the first 5 new books of a sync request. Offering a change
and fetching it are separate mechanisms, and only the first is ours.

Also recorded, with sources:

- RevisionId must stay equal to EntitlementId. Nickel keys entitlements
  on EntitlementId and ignores RevisionId, so a versioned revision files
  a second copy rather than replacing the book. Upstream shipped
  versioned revisions and reverted them after an on-device retest. We
  already hold RevisionId stable; this is here so it stays that way.
- ChangedEntitlement for a book the device does not hold is dropped
  without trace, so never-delivered books must go out as New.
- A ReadingState inside ChangedEntitlement seeds device state and can
  overwrite live progress. We omit it; now the reason is written down.
- A mass file rewrite re-announces the library, because the session
  fingerprint includes file_hash and Nickel marks a re-offered book as
  not downloaded.
- social_host still points at social.kobobooks.com, which no longer
  resolves; on 4.38-4.45 the resulting WebRequestErr can mark an
  otherwise-clean sync as failed. Not observed on our 4.45 Libra Colour,
  so it is filed as a hypothesis with a fix sketch rather than a change.

The two-phase Preview to Full sequence that does force a re-download is
described but deliberately not implemented: it rests on undocumented
firmware behaviour and an unmerged upstream patch.

Doc-only; no behaviour change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The fourth and last layer behind "the cover doesn't update", and the one
I missed: an entitlement-delivered book's library cover never comes from
the EPUB. Nickel fetches it from image_url_template, renders it to a
fixed set of sizes, writes each to disk keyed by (ImageId, size), and
never revalidates. Production logs in omnibus#2684 show 1,185 cover
requests with zero conditional requests and zero 304s.

CoverImageId is the bare book UUID, so the cache key never changes and
the stale render is permanent.

Records the cache path (sharded by Qt's qhash, ImageId in the filename,
per calibre's driver.py), the variants and their pixel sizes, the
per-book SSH fix including the mandatory reboot, and the server-side fix
of versioning CoverImageId.

The server-side fix is written up with its caveat rather than
implemented: upstream reports the new cover is fetched but the device
often draws a blank placeholder instead, cause unknown. The omnibus logs
suggest why - after an ImageId change the device fetched only sizes it
had never requested before - but that needs on-device confirmation.

Also notes what this means for the v0.1.7/v0.1.8 EPUB rewrite: still
correct, since the file did carry the wrong image and other readers do
read it, but not what Nickel draws for an entitlement book.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
/mnt/onboard is the KOBOeReader USB mass-storage volume, so .kobo/ and
.kobo-images/ are reachable with a cable and nothing enabled on the
device. This is how calibre does it. The cover-cache fix now leads with
that route and keeps the SSH form as the alternative.

Also records that a firmware update restores .kobo/ssh-disabled, since
the marker lives on the partition the updater rewrites. SSH breaks after
an update with no other symptom, and the rename has to be re-applied
over USB.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Read-only walk of the library tree. Per book it reports the sidecar
cover's real format and pixel dimensions, the EPUB's zip hygiene
(mimetype first and stored, stray directory entries), OPF version,
presence of dc:title/dc:creator/dc:language, series metadata, how the
cover is declared (EPUB3 properties, EPUB2 meta, both, or not at all),
the embedded cover's dimensions, whether a nav doc or NCX exists, spine
length, and whether kepubify conversion succeeds.

The cover dimensions are checked against the sizes Nickel actually
renders, taken from calibre's driver: 600x800 for the sleep screen and
355x530 for the detail screen. Anything smaller is being upscaled on the
device, which is the difference between a crisp cover and a soft one and
is not otherwise visible from the admin UI.

Output is TSV so results can be aggregated or diffed between runs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'kobo-api-entitlement-semantics:kobo-api-entitlement-semantics'
git switch 'kobo-api-entitlement-semantics'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'kobo-api-entitlement-semantics'
git switch 'kobo-api-entitlement-semantics'
git rebase 'main'
git switch 'main'
git merge --ff-only 'kobo-api-entitlement-semantics'
git switch 'kobo-api-entitlement-semantics'
git rebase 'main'
git switch 'main'
git merge --no-ff 'kobo-api-entitlement-semantics'
git switch 'main'
git merge --squash 'kobo-api-entitlement-semantics'
git switch 'main'
git merge --ff-only 'kobo-api-entitlement-semantics'
git switch 'main'
git merge 'kobo-api-entitlement-semantics'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
arne/books!32
No description provided.