|
| 1 | +# Partial replication protocol — subset snapshot, scoped updates, existence privacy, dangling references |
| 2 | + |
| 3 | +Design record for issue #5800 (developing-today/code). |
| 4 | +Date: 2026-11-16. Status: Decision (recorded by queue task 16841, lane any-d). |
| 5 | +Parent: #5672 (closed). Programme: epic #2056. Fixed inputs: #5799 grants-model |
| 6 | +decision record (2026-11-05, task 10716), #5678 read-authority order (via #5799). |
| 7 | + |
| 8 | +This record settles the protocol mechanics #5800 owes: how a granted subset |
| 9 | +moves from an issuer to a peer — the subset snapshot, the scoped update |
| 10 | +stream, the existence-privacy mechanics, and what happens to references that |
| 11 | +point outside the slice. Implementation timing is a separate decision (the |
| 12 | +issue notes it may be months out); this record is the design only. |
| 13 | + |
| 14 | +## Fixed inputs (not re-decided here) |
| 15 | + |
| 16 | +From #5672: selective sharing exists so a server shares *subsets* instead of |
| 17 | +all-or-nothing replication; the existence-privacy rule (a share must not leak |
| 18 | +what it does not include); the receiving side may cap, pause, or drop a |
| 19 | +share; revocation cannot un-copy plaintext a peer already holds. |
| 20 | + |
| 21 | +From #5799 (grants model): grant units are the individual object and the |
| 22 | +stable collection; operations are `read`, `subscribe` (requires `read`), |
| 23 | +`write`, `append`, each explicit; durations are `standing`, `expires_at`, |
| 24 | +and `snapshot_once` (one initial snapshot, no subscription or later |
| 25 | +re-fetch; retries belong to that same transfer); revocation stops future |
| 26 | +replication at the next authorization check; delegation is attenuated and |
| 27 | +off by default. #5799 invariant 6 binds this protocol directly: |
| 28 | +unauthorized and nonexistent resources are indistinguishable in |
| 29 | +protocol-visible results, and partial replication exposes no |
| 30 | +withheld-object inventory. #5799 also assigns the dangling-reference |
| 31 | +treatment and the exact snapshot/update protocol to this record. |
| 32 | + |
| 33 | +## Decisions |
| 34 | + |
| 35 | +### 1. Subset snapshot: grant-evaluated, self-describing, scope-only |
| 36 | + |
| 37 | +A snapshot is the set of objects the grant covers **at the snapshot cut**, |
| 38 | +evaluated by the #5678/#5799 resolver at cut time — not a database dump |
| 39 | +filtered afterwards. The bundle is self-describing and contains only: |
| 40 | + |
| 41 | +- the grant id it answers and the issuer's snapshot epoch (a monotonic |
| 42 | + per-issuer sequence number stamped at the cut); |
| 43 | +- a manifest listing **only the included objects** (id + content hash), and |
| 44 | + the objects themselves; |
| 45 | +- for each object, its references rewritten per §4 below. |
| 46 | + |
| 47 | +Later additions to a granted collection are **not** in the snapshot: they |
| 48 | +reach the peer only through scoped updates (§2), and only when the grant |
| 49 | +includes `subscribe`. A `snapshot_once` grant's snapshot is the whole |
| 50 | +transfer, per #5799. Transfer is chunked with per-chunk acknowledgement |
| 51 | +keyed by (grant, epoch, chunk), so an interrupted snapshot resumes the |
| 52 | +same transfer instead of restarting or re-cutting at a newer epoch. |
| 53 | + |
| 54 | +### 2. Scoped updates: a per-grant stream, epoch-ordered |
| 55 | + |
| 56 | +For grants with `subscribe`, updates flow as a stream keyed by |
| 57 | +(grant id, epoch): |
| 58 | + |
| 59 | +- each update carries the object id, the operation (`upsert` / `delete`), |
| 60 | + and its epoch; the peer applies updates in epoch order; |
| 61 | +- an update is emitted **only** for an object inside the grant's scope at |
| 62 | + emission time, re-evaluated per update — scope is not frozen at the |
| 63 | + snapshot cut; |
| 64 | +- a **delete** inside scope is a real tombstone: the peer holds the object |
| 65 | + legitimately and must learn it is gone; |
| 66 | +- when an object **leaves scope** without being deleted (revocation, |
| 67 | + expiry, removal from the collection, policy change), the peer receives a |
| 68 | + scope-exit marker for that object — and nothing else: the marker does |
| 69 | + not say why, because the reason can itself describe withheld state; |
| 70 | +- grant termination (revocation, expiry, peer drop) ends the stream; a |
| 71 | + peer that detects an epoch gap resynchronises with a **fresh snapshot |
| 72 | + of the current grant scope** — never by requesting ranges, which would |
| 73 | + let it probe outside the slice. |
| 74 | + |
| 75 | +Write-back under `write`/`append` grants travels the same stream in |
| 76 | +reverse and is authorized per update by the same grant; conflict policy |
| 77 | +for concurrent writes belongs to the data layer (#2048), not this |
| 78 | +protocol — the protocol's obligation is only that nothing moves outside |
| 79 | +the grant's operation set. |
| 80 | + |
| 81 | +### 3. Existence-privacy mechanics |
| 82 | + |
| 83 | +The #5672/#5799 rule is enforced by construction, not by filtering a |
| 84 | +wider feed: |
| 85 | + |
| 86 | +- **Scope-only content.** The snapshot manifest and the update stream |
| 87 | + contain granted objects and nothing else — no withheld ids anywhere in |
| 88 | + either, including in error paths and resync. |
| 89 | +- **No totals.** Neither the snapshot nor the stream carries counts of |
| 90 | + the source collection or database, "N of M" progress, or |
| 91 | + withheld-object statistics. Transfer progress, if shown, is computed |
| 92 | + from included bytes/objects only. |
| 93 | +- **Indistinguishable absence.** Absent and existing-but-ungranted |
| 94 | + produce the same protocol-visible result everywhere (queries, lookups, |
| 95 | + resync responses), per #5799 invariant 6. |
| 96 | +- **Opaque placeholders.** Reference rewriting (§4) never embeds the |
| 97 | + target's identity. |
| 98 | +- **Side channels named, not promised.** Timing and total-size |
| 99 | + correlation are not closed by this protocol in v1; batching/padding is |
| 100 | + an implementation choice, and no invariant below claims otherwise. |
| 101 | + |
| 102 | +### 4. Dangling references: redacted placeholder by default |
| 103 | + |
| 104 | +When an included object references an object outside the slice, the |
| 105 | +reference is delivered as a **redacted placeholder**: the referencing |
| 106 | +field is present, carrying an opaque token and no target data. The token |
| 107 | +is a per-grant keyed hash of the target id, so: |
| 108 | + |
| 109 | +- two fields in the same slice pointing at the same ungranted object |
| 110 | + render as the *same* placeholder (intra-slice linkability is kept — |
| 111 | + the peer can tell its slice references one shared external thing); |
| 112 | +- the token reveals neither the target's id nor anything correlatable |
| 113 | + across grants (each grant salts differently), so placeholders cannot |
| 114 | + be used to enumerate or cross-reference withheld objects. |
| 115 | + |
| 116 | +Per data type, exactly two deviations are permitted, both explicit: |
| 117 | + |
| 118 | +- **Omission** — the field is dropped instead of placeholdered — only |
| 119 | + where the data type's schema marks the reference optional; recorded |
| 120 | + per data type, never improvised per object. |
| 121 | +- **Closure** — the referenced object is pulled into the slice — never |
| 122 | + implicit: only when the grant itself carries an explicit closure flag |
| 123 | + set at grant creation (off by default, recorded with the grant). This |
| 124 | + composes with #5799 invariant 3 (a collection grant cannot escape its |
| 125 | + scope): closure is the grant's own stated scope, not the protocol |
| 126 | + widening it. |
| 127 | + |
| 128 | +If a placeholder's target later enters scope (grant widened, object |
| 129 | +added to the collection), the next scoped update for the referencing |
| 130 | +object resolves the placeholder to the real reference; the placeholder |
| 131 | +token lets the peer match the resolution to what it already holds. |
| 132 | + |
| 133 | +### 5. Receiving side |
| 134 | + |
| 135 | +Per #5672, the peer may cap accepted share size/count, pause a share, or |
| 136 | +drop it. A drop deletes the local replica by the peer's own choice and |
| 137 | +reads to the issuer as subscription termination, not an error. Caps are |
| 138 | +enforced at snapshot-chunk and update boundaries: hitting a cap pauses |
| 139 | +the transfer with the (grant, epoch) position retained, so resumption |
| 140 | +does not re-cut the snapshot. |
| 141 | + |
| 142 | +## Alternatives rejected |
| 143 | + |
| 144 | +- **Full snapshot + peer-side filtering.** The peer receives everything |
| 145 | + and discards the ungranted — existence privacy is violated outright, |
| 146 | + before any filtering happens. The protocol exists to make this |
| 147 | + unnecessary. |
| 148 | +- **Closure by default.** Auto-including referenced objects widens every |
| 149 | + grant beyond its stated scope and contradicts #5799 invariant 3; it |
| 150 | + also makes share size unpredictable for the receiving side's caps. |
| 151 | +- **Identity-revealing placeholders** (embedding the target id so the |
| 152 | + peer can "fetch it later if granted"). Leaks the existence and |
| 153 | + identity of withheld objects — precisely the enumeration #5799 |
| 154 | + invariant 6 forbids — and invites probing. |
| 155 | +- **Omitting all dangling fields.** Silently lossy: the peer cannot |
| 156 | + distinguish "no reference" from "reference withheld", and slices stop |
| 157 | + being schema-consistent. Placeholders keep the distinction visible |
| 158 | + without leaking the target. |
| 159 | +- **Issuer-wide change feed, filtered at the peer.** Same leak as a full |
| 160 | + snapshot, stretched over time: the feed's shape (rates, ids, delete |
| 161 | + patterns) describes the withheld set. |
| 162 | +- **Counts/totals for progress and planning.** "3 of 41 objects" tells |
| 163 | + the peer the collection holds 41; the withheld set's size is withheld |
| 164 | + information. |
| 165 | + |
| 166 | +## Invariants implementation must hold |
| 167 | + |
| 168 | +1. Every byte of a snapshot or update is authorized by the grant |
| 169 | + (subject, scope, operation, lifetime) at the moment it is emitted, |
| 170 | + evaluated by the #5678/#5799 resolver — there is no second, |
| 171 | + protocol-private authority path. |
| 172 | +2. Snapshot membership is the resolver's answer at the cut; stream |
| 173 | + membership is the resolver's answer at each emission. |
| 174 | +3. No protocol message — manifest, update, error, resync, progress — |
| 175 | + contains a withheld object's id, count, name, metadata, or a token |
| 176 | + correlatable to it across grants. |
| 177 | +4. Absent and ungranted are indistinguishable in every protocol-visible |
| 178 | + result. |
| 179 | +5. Deletes of held objects are delivered as tombstones; scope exits are |
| 180 | + delivered as reason-free markers; the two are never conflated. |
| 181 | +6. Revoked or expired grants emit nothing further, including resync |
| 182 | + responses and placeholder resolutions. |
| 183 | +7. `snapshot_once` delivers exactly one snapshot cut; retries resume |
| 184 | + that cut's chunks and never re-cut. |
| 185 | +8. Dangling references are placeholders by default; omission only per |
| 186 | + data-type schema; closure only under an explicit grant flag. |
| 187 | +9. A peer-side cap or drop never obliges the issuer to reveal more to |
| 188 | + "complete" a transfer; a paused transfer resumes from its retained |
| 189 | + (grant, epoch) position. |
| 190 | + |
| 191 | +## Divergence check against the parents |
| 192 | + |
| 193 | +None. Nothing here changes a #5672 or #5799 decision: the grants model, |
| 194 | +the authority order, the revocation boundary, and the existence-privacy |
| 195 | +rule are consumed as fixed. The epoch/scope-exit mechanics, the |
| 196 | +per-grant placeholder token, and the chunk-resume rule are new detail |
| 197 | +inside the space #5799 explicitly left to this record ("the treatment of |
| 198 | +dangling references/redacted placeholders and the exact |
| 199 | +partial-snapshot/update protocol remain #5800's decision"). |
| 200 | + |
| 201 | +## Splits and follow-ons |
| 202 | + |
| 203 | +No further splits are filed: the three questions the issue names are |
| 204 | +settled above, and the neighbouring designs already exist as their own |
| 205 | +issues (encrypted shares #5801, public-share UX #5802). Implementation — |
| 206 | +when its timing is decided — will touch the grants resolver surface, the |
| 207 | +capability scopes in `pkgs/id/crates/id-caps`, and the ID relay transport |
| 208 | +(#2036); none exists as replication code today, so this record is the |
| 209 | +contract that work builds against. |