Expand description
The key-free sync consumer (SSoT: Download & Sync).
SyncConsumer drives GET /v1/sync through the generated REST client — the same
paged (cursor, page_size) feed the server serves — authorizing through the
SDK session and retrying once on a 401. The opaque, server-MAC’d cursor is round-tripped
verbatim: the client stores next_cursor and hands it back untouched.
There was a second transport here and there is not any more. The feed rode
capsule.sync.v1.SyncService over tonic, which meant the SDK described one wire contract in
a .proto and every other in an OpenAPI document. Nothing below the transport moved:
SyncState and its two rules were never about gRPC.
SyncState is the client-side anti-rewind + forward-version layer, split
out as a pure, network-free state machine so every rejection rule is a
deterministic unit test (sync doc, “Cursor Authenticity and Anti-Rewind”):
- Forward-version rejection. A feed entry whose
protocol_versionis above the client’s max known is rejected without partial application — the whole page is validated before any high-water mark advances (the tightened Postel’s Law). - Rewind rejection. The client holds a per-album
sync_seqhigh-water mark; a page whosesync_seqregresses against it is surfaced, not applied. This is the independent anti-rewind layer that the server’s cursor MAC cannot provide: a malicious server can always hand back one of its own older, validly-MAC’d cursors, and only the client-held high-water mark defeats that (Download & Sync — cursor authenticity).
Blob bytes never ride this surface; on-demand ranged blob fetch is crate::fetch.
The feed carries only an asset’s latest provenance record. fetch_history walks the
chain back from it to the asset’s create through that blob fetch, for a device that first
sees an asset past its create and adopts it from its whole chain; history_sources names
the live metadata blob and the original that adoption fetches, which an album page’s
tombstone does not.
Modules§
- reannounce
- Re-announcing held manifests after a sync epoch change (#781).
Structs§
- Blob
Manifest - The asset’s blobs by role.
- BlobRef
- A single blob’s content address and role, carried on a feed entry (never blob bytes).
- Feed
Entry - One decoded sync feed entry. Ids arrive as opaque bytes (UTF-8 nanoids / raw UUIDs); the manifest and metadata blob pass through as opaque bytes.
- History
Sources - The blobs adopting an asset from its fetched history needs beyond its records, by content
address: what
history_sourcesreads off a head and the records before it. - Sync
Consumer - The sync consumer, over the generated REST client.
- Sync
Cursor - The opaque, server-MAC’d sync cursor. The client never interprets it — it is
round-tripped verbatim: empty on first sync, then whatever the server last
returned as
next_cursor. - Sync
Page - A decoded page of the feed plus the cursor for the next page.
- Sync
State - The client-side reconciliation state: the per-album
sync_seqhigh-water marks, the max-known protocol version, and the opaque cursor. Pure and network-free —SyncState::apply_pageis the whole anti-rewind / forward-version contract in one testable function.
Enums§
- Change
Kind - What changed, mirroring
capsule.sync.v1.ChangeKind. - History
Error - Why an asset’s earlier provenance records could not be fetched, or the blobs its adoption
needs could not be named from them (
history_sources). Nothing is verified here —Workspace::adopt_remote_historydoes that — so each variant is a fact about the walk, not a verdict on the chain. - Original
Availability - The derived per-asset original availability — the badge a client’s timeline
reads (staged uploads; transfer download doc, “The
awaiting-originalstate”). It is always derived from the feed’soriginal_heldfact, never stored as a second source of truth: an asset whose original has not yet landed on the server shows in the timeline immediately (LQIP, then T1 tiers as they arrive) with an “original still on device” badge, and its full-resolution fetch returns the transienterror.blob.pending_uploadrather than a failure. - Sync
Error - Everything the sync consumer / reconciliation can fail with. Callers switch on
the typed variant (never a bare gRPC status);
SyncError::error_codeyields the stableerror.*catalog code where one applies.
Constants§
- MAX_
HISTORY_ RECORDS - The most records
fetch_historywalks back from a head: a chain longer than this is refused (HistoryError::TooLong) rather than held in memory without bound. Every record of a chain is one lifecycle write of one asset, so a real chain is far shorter. - MAX_
RECORD_ BYTES - The largest provenance record
fetch_historyaccepts (1 MiB). A record is a signed manifest and its chain link, a few KiB; anything past this is not one.
Functions§
- fetch_
history - Walk an asset’s provenance chain back from
head_record(themanifest_cbora feed entry carries) to itscreate, fetching each record the one after it names byprior_provenance_hashthroughsource(GET /v1/blob/{hash}, where the server keeps an asset’s superseded records under the live record’s read authority). - history_
sources - Name the live metadata blob and the original an asset’s adoption needs, from its head record
(a feed entry’s
manifest_cbor) and the records before it (fetch_history’s answer). - retention_
closed - Whether the retention window of the
deletethat ishead_record(a feed entry’smanifest_cbor) had closed atat:atis at or after theretention_untilsigned into it, the instant from which the server refuses atrash-restoreand stops serving the asset’s records and bytes to its readers.