Skip to main content

Module staged

Module staged 

Source
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_sessions returns the blobs to open sessions for now, in strict ladder order (T0 index → T1 preview → T2 original). Under UploadPolicy::Full every session opens eagerly; under UploadPolicy::Staged a tier opens only when the detected ConnectionClass permits 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_tiers re-derives the outstanding work from what the server holds (held_from_feed reads the held blob roles + original_held off 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 the UploadClient’s own create-dedup / HEAD offset rather than restarting.
  • awaiting-original. T2 is exactly what staged defers, so a staged asset is in the derived awaiting-original state on other devices until its original lands (original_held flips). The badge and the transient error.blob.pending_upload fetch 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§

OpenedTier
One opened tier session, in observed order.
StagedAsset
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.
StagedReport
The outcome of one staged run: the tier sessions opened, in observed order.
StagedScheduler
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.
TierBlob
One upload unit within an asset bundle: a single blob, tagged with the UploadTier it belongs to and its ciphertext content address.
UploadClientTierSink
The production TierSink: opens each planned tier session through the hand-written, resumable UploadClient, so staged session ordering rides the real upload protocol. In-flight tiers resume through the client’s create-dedup / HEAD offset — the reason resume needs no extra scheduler state.

Enums§

StagedError
Errors a staged run can fail with.
TierSessionOutcome
How one opened tier session resolved.

Traits§

TierRequestBuilder
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.
TierSink
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; UploadClientTierSink is 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 attempt under the scheduler monitor’s current plan allows, and re-plan when the path changes under it.