Skip to content

fix(library): decide book availability from metadata, not read probes - #293

Merged
yicheng47 merged 1 commit into
mainfrom
fix/icloud-availability-metadata
Aug 8, 2026
Merged

fix(library): decide book availability from metadata, not read probes#293
yicheng47 merged 1 commit into
mainfrom
fix/icloud-availability-metadata

Conversation

@yicheng47

Copy link
Copy Markdown
Owner

Problem

Every book in the library shows the iCloud download overlay even though all files are fully materialized on disk and open fine in the reader.

Cause

#289 made availability a first-byte read probe with a 300ms deadline. Measured against a real 357-book library, that breaks two ways:

  1. Cold reads are slow on healthy files. A cold first-byte read through fileproviderd takes 0.7–8s per file — 72% of the library exceeds 100ms and virtually everything exceeds the 300ms deadline. list_books therefore marks the whole page unavailable. (Warm reads are fast, which is why the reader still opens books after a beat.)
  2. Concurrent probes poison each other. The PROBES_IN_FLIGHT guard reports "unavailable" for any path already being probed. Home triggers list_books from several event listeners; in a two-sweep race over warm files, one call reported 323/357 unavailable and the other 34.

Fix

  • is_file_downloaded is now metadata-only: the file has metadata (legacy .icloud-rename eviction leaves none at the real path) and doesn't carry SF_DATALESS (FileProvider-style eviction). No reads, no deadline, and list_books drops its per-book probe threads.
  • The read probe survives as is_file_readable behind a new check_book_readable command, used only where fix(reader): surface error when iCloud book file is unreadable #289 needed it: after a reader load failure, to distinguish broken iCloud sync from a broken book (and nudge a re-download). Same bounded-wait and in-flight guarantees.

Testing

  • All 256 backend tests pass; probe tests moved to is_file_readable, plus a new test pinning that a hanging path counts as downloaded but not readable
  • tsc --noEmit and cargo clippy clean
  • Repro harness run against the real library: metadata checks report 0/357 unavailable; old probe logic reported nearly all books unavailable when cold or raced

🤖 Generated with Claude Code

Every book in the library showed the iCloud download overlay even
though all files were fully materialized and opened fine. Two causes,
both in the first-byte read probe that #289 made the availability
signal:

- Cold first-byte reads through fileproviderd take 0.7-8s on healthy
  downloaded files (measured across a 357-book library), so the 300ms
  probe deadline marked virtually every book unavailable.
- Concurrent probes of the same path short-circuit to "unavailable"
  via the in-flight marker, so two overlapping list_books calls (Home
  refreshes from several event listeners) poisoned each other's
  results wholesale.

Availability is now metadata-only: the file has metadata (legacy
.icloud-rename eviction leaves none at the real path) and doesn't
carry SF_DATALESS (FileProvider-style eviction). No reads, no
deadline, no per-book probe threads in list_books.

The read probe survives as is_file_readable behind a new
check_book_readable command, used only where #289 needed it: after a
reader load failure, to tell broken iCloud sync from a broken book
(and nudge a re-download). Same bounded-wait and in-flight guarantees,
now covered by tests under the new name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@yicheng47
yicheng47 force-pushed the fix/icloud-availability-metadata branch from 5c549f0 to bfb1df9 Compare August 8, 2026 15:25
@yicheng47
yicheng47 merged commit e44f5e4 into main Aug 8, 2026
2 checks passed
@yicheng47
yicheng47 deleted the fix/icloud-availability-metadata branch August 8, 2026 15:35
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