Expand description
The client-side staged upload scheduler (SSoT: Download & Sync — Upload Tiering (Staged Uploads)).
Uploads used to be all-or-nothing; staged uploads add the upload-direction
ladder for low-data situations. The policy is client-side session ordering
only — the server has zero mode branches (the canonical UploadPolicy /
UploadTier contract lives in capsule_library::import::upload). This module is
that ordering’s network half:
- Ladder ordering + gating.
StagedScheduler::plan_sessionsreturns the blobs to open sessions for now, in strict ladder order (T0 index → T1 preview → T2 original). UnderUploadPolicy::Fullevery session opens eagerly; underUploadPolicy::Stageda tier opens only when the detectedConnectionClasspermits it (ConnectionClass::permits_tier) — T0 escapes on any usable link, T1/T2 wait for a non-metered link (or an explicit force-sync). Because the tier gate is monotone, the permitted set is always a ladder prefix: T2 never opens before T1, which never opens before T0. - Resume from server truth. Resume needs no durable client state:
remaining_tiersre-derives the outstanding work from what the server holds (held_from_feedreads the held blob roles +original_heldoff a sync feed entry). Kill the client mid-ladder and the queue rebuilds from the feed; only missing tiers are re-uploaded, and any tier with an in-flight session resumes through theUploadClient’s own create-dedup /HEADoffset rather than restarting. awaiting-original. T2 is exactly what staged defers, so a staged asset is in the derivedawaiting-originalstate on other devices until its original lands (original_heldflips). The badge and the transienterror.blob.pending_uploadfetch state are the sync/fetch halves (crate::sync,crate::fetch); this scheduler is what makes T2 land last.
Verify-before-destroy is untouched: a staged asset pins its local original until
T2 is durable, by the same ReleaseGate
that always governed release. Staged and streaming import are mutually exclusive
per import — enforced in capsule_library::import (planner confirmation + the
streaming executor), so it can never reach this scheduler.
Structs§
- Opened
Tier - One opened tier session, in observed order.
- Staged
Asset - An asset’s staged upload bundle: its id and the blobs to upload. The blobs may be supplied in any order — the scheduler sorts them into ladder order.
- Staged
Report - The outcome of one staged run: the tier sessions opened, in observed order.
- Staged
Scheduler - The staged upload scheduler: given a
UploadPolicy, the tiers the path admits, and an optional force-sync consent, it decides which of an asset’s tier sessions open now and in what order. - Tier
Blob - One upload unit within an asset bundle: a single blob, tagged with the
UploadTierit belongs to and its ciphertext content address. - Upload
Client Tier Sink - The production
TierSink: opens each planned tier session through the hand-written, resumableUploadClient, so staged session ordering rides the real upload protocol. In-flight tiers resume through the client’s create-dedup /HEADoffset — the reason resume needs no extra scheduler state.
Enums§
- Staged
Error - Errors a staged run can fail with.
- Tier
Session Outcome - How one opened tier session resolved.
Traits§
- Tier
Request Builder - Builds the per-blob upload request + ciphertext the scheduler hands to the upload client. The app implements this — it holds the sealed bytes and the signed manifest envelope; the scheduler owns only the tier ordering and gating, so the two policies stay on one code path.
- Tier
Sink - The network seam the scheduler drives to open one tier’s upload session. Kept a
trait so the ordering + gating are exercised by a deterministic recording mock;
UploadClientTierSinkis the production impl over the hand-written upload client.
Functions§
- held_
from_ feed - The set of blob content addresses the server durably holds for an asset, read from a sync feed entry — the server truth a resume re-derives from.
- remaining_
tiers - Re-derive the outstanding staged work from server truth: keep only the blobs the server does not already hold, in ladder order.
- run_
under_ path - Run
attemptunder the schedulermonitor’s current plan allows, and re-plan when the path changes under it.