Skip to content

Save and browse public Bluesky records offline with durable, resumable jobs - #705

Open
micahflee wants to merge 3 commits into
mainfrom
issue-676-bluesky-collection-engine
Open

micahflee wants to merge 3 commits into
mainfrom
issue-676-bluesky-collection-engine

Conversation

@micahflee

Copy link
Copy Markdown
Member

Closes #676.

The engine

Saving a whole Bluesky account is long work that gets interrupted: the app quits, the network goes, Bluesky rate limits, the disk fills, someone changes their mind. So durability is the shape of the collection loop rather than something layered on top of it.

  • Every page is committed in one transaction with the checkpoint that describes it, so a checkpoint can never claim more than is saved.
  • Every identifier is derived from what it names — a captured profile from its labels, an asset from its owner, role, and position — so committing the same page twice leaves the same data and resuming never duplicates.
  • The media still to fetch is derived from the saved data rather than queued beside it, so a restart finds exactly the work that is left and a failed asset stays explicit and retryable until a success upgrades the backup's completeness.
  • A rate limit is a wait with a time on it, reported as rateLimitedUntil, not a failure.
  • Stopping — by cancellation or a full disk — keeps everything committed and leaves only staging behind. Media lands in staging before the content-addressed store, so a full volume never leaves a file lying about its digest.

What a category supplies is its AT Protocol surface and its mapping, and nothing else. Posts read raw repository records, so an own post's images and video are saved at original quality; reposts and likes hydrate their subjects; bookmarks arrive already hydrated. The engine never knows which category it is running.

Storage preflight

Bluesky publishes a post count and nothing else. So the report separates the part Cyd is certain about from the part it is estimating, and refuses a run only when even the certain part does not fit. An uncertain estimate is reported as uncertain, never as a refusal — refusing on a guess would block runs that would have fitted.

Browse

Per-category chronological paging read from this computer alone: no connection, no network. Embeds, subjects, bounded context, deletion state, and source links where they exist. Media that was never fetched is shown as absent rather than omitted, because a gap in a backup is something to see.

Decisions worth a reviewer's attention

Bookmarks match Cyd Mobile, and mint nothing. Bluesky keeps bookmarks in a private stash and gives the bookmark itself no AT URI — only a strong ref to the post. The first commit minted at://<did>/app.cyd.bookmark/<rkey> to give it the stable identifier a saved record needs. Mobile instead points the bookmarks selection straight at the post and carries the bookmark time on the selection (cyd-mobile/services/archive-export/interchange.ts: "There is no bookmark record URI in Mobile's storage, so the selection names the bookmarked post directly"). A Cyd Bluesky archive is a cross-client contract, so an identifier meaning one thing on desktop and another on mobile breaks the idempotent merge the format promises. Desktop now writes what Mobile writes.

Worth noting separately: the canonical fixture under docs/archive/bluesky/v2/fixtures/ does carry an app.cyd.bookmark record with a record_subjects row, which is what the minting was based on. Mobile's reader handles both shapes, so nothing is broken — but the fixture shows a shape Mobile never writes, and that's probably worth its own issue against the archive contract.

A liked video's blob comes from the repository that holds it. com.atproto.sync.getBlob through this account's session only answers for this account's own repository, so a liked video — which belongs to whoever posted it — could never have been saved whole. The owning server is resolved from its DID document; blobs are public, so that needs no authorization, and the authenticated session stays the fallback for an unresolvable document. The fake client sits above this seam, so no test would have caught it.

Captured authors survive a rename. The archive contract's own fixture has a record pointing at a captured profile (alice.test) while the identity points at the renamed one (alice.example) — that is the whole substance of "profile refresh does not rewrite captured historical author labels". Records keep their captured author; only a record Cyd could not read at first, whose author is a bare DID, takes its real author once Bluesky answers for it.

Tests

Controller tests drive the whole engine against a fake AT Protocol client with real temporary storage, and they interrupt it: restart, retry, rate limit, cancellation, and disk pressure, each parametrised over all four categories. UI tests mock only the controller boundary. Progress and error reports carry operational metadata only, per docs/adr/0029-minimize-bluesky-diagnostics.md, and a test asserts the serialized progress contains no DID, handle, record text, AT URI, or local path.

npm run lint clean; 1530 tests passing.

Known limitation

For reposts, likes, and bookmarks, estimatedBytes on a first run is only the headroom constant, because Bluesky publishes no count for them and the estimate falls back to what is already saved. It is reported as uncertain and the UI names each unsized category, so it is honest — but the number is weak on a first run. Left as-is rather than papered over.

🤖 Generated with Claude Code

micahflee and others added 3 commits September 13, 2026 15:00
Closes #676.

Saving a whole Bluesky account is long work that gets interrupted: the app
quits, the network goes, Bluesky rate limits, the disk fills, someone changes
their mind. So durability is the shape of the collection loop rather than
something layered on top of it.

Every page is committed together with the checkpoint that describes it, so a
checkpoint can never claim more than is saved. Every identifier — a captured
profile, an expected asset, a bookmark's minted AT URI — is derived from what
it names, so committing the same page twice leaves the same data and resuming
never duplicates. The media still to fetch is derived from the saved data
rather than queued beside it, so a restart finds exactly the work that is left
and a failed asset stays explicit and retryable until a success upgrades the
backup's completeness. A rate limit is a wait with a time on it. Stopping keeps
everything committed and leaves only staging behind.

What a category supplies is its AT Protocol surface and its mapping, and
nothing else: posts, reposts, likes, and bookmarks all inherit durability from
an engine that never knows which one it is running.

Storage preflight is honest about what it cannot know. Bluesky publishes a post
count and nothing else, so the report separates the part Cyd is certain about
from the part it is estimating, and refuses a run only when even the certain
part does not fit.

Browse views read this computer alone — no connection, no network. Media that
was never fetched is shown as absent rather than omitted, because a gap in a
backup is something to see.

Controller tests drive the whole engine against a fake AT Protocol client with
real temporary storage, restarting, retrying, rate limiting, cancelling, and
filling the disk for every category. UI tests mock only the controller
boundary. Progress and error reports carry operational metadata only, per
docs/adr/0029-minimize-bluesky-diagnostics.md.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Match Cyd Mobile on bookmarks. Bluesky keeps bookmarks in a private stash and
gives the bookmark itself no AT URI, only a strong ref to the post. Desktop was
minting `at://<did>/app.cyd.bookmark/<rkey>` to give it the stable identifier a
saved record needs; Mobile instead points the bookmarks selection straight at
the bookmarked post and carries the bookmark time on the selection. A Cyd
Bluesky archive is a cross-client contract, so an identifier that means one
thing on desktop and another on mobile breaks the merge the format promises.
Desktop now writes what Mobile writes, and mints nothing.

Keep the author a record was captured with. The archive contract's own fixture
has a record pointing at a captured profile while the identity points at the
renamed one, which is the whole substance of "profile refresh does not rewrite
captured historical author labels". Re-collecting was repointing every record at
the new profile, and the test asserted that as if it were correct. Records now
keep their captured author; only a record Cyd could not read at first — whose
author is a bare DID — takes its real author once Bluesky answers for it.

Fetch a blob from the repository that holds it. `com.atproto.sync.getBlob`
through this account's session only answers for this account's own repository,
so a liked video — which belongs to whoever posted it — could never have been
saved whole. The owning server is now resolved from its DID document; blobs are
public, so that needs no authorization, and the authenticated session remains
the fallback for an unresolvable document.

Resume interrupted saves. A job only says "running" while a process is running
it, so one found in that state on open was interrupted. It now returns to the
pending queue and the dashboard offers to carry on, which is what the engine's
checkpoint was already able to do and an IPC comment already claimed. A full
disk can also defeat the one-row write that records where a run stopped, so that
write no longer turns a reported outcome into a thrown one.

One definition each, and no dead code. The category graph, the asset address
codec, the save-job type name, the AT Protocol collection constants, and the
saved-totals list were each written twice; the two copies of the category graph
already disagreed, so a Browse view could report a completeness the engine did
not mean. Deleted six unused store readers, an unused rate-limit type, and a
controller getter only its own tests called. Narrowed a glossary entry whose
_Avoid_ list contradicted the code shipped beside it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

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.

Save and browse public Bluesky records offline with durable, resumable jobs

1 participant