Expand description
The append-only, replica-tagged operation log.
OpRecord follows docs/proposals/multi-device-sync.md §“The frame:
sync events, not files” field-for-field, with two B1 specifics:
op_idis content-derived via the shipped B7 discipline (car_proto::deterministic_run_id’s SHA-256 +0x1ffield separators; the proposal’sblake3(payload)is the same content-addressing idea — we reuse the hash the codebase already standardized on rather than add a dependency). The digest coversdevice_id ‖ seq ‖ prev ‖ hlc ‖ scope ‖ surface ‖ canonical(payload), so the id is simultaneously the natural dedup key for op retransmission AND a tamper-evident cover of the record, including its position in the device chain. Logical-entity dedup across devices (the proposal’s “conversations dedup on (speaker,text,timestamp); knowledge on fact_id”) happens at the fold’s stable-key level, not onop_id— seeOpRecord::stable_key. Event-stream surfaces are the exception: routing observations fold as a MULTISET (the proposal replays “the merged multiset of observations”), so they key byop_id— two byte-identical observations are two events, and only retransmission dedups. SeeSurface::is_event_stream/OpRecord::fold_key.- The HLC is shape-only in B1.
Hlccarries the proposal’s{wall_ms, counter, device_id}total order;DeviceLogstamps pure Lamport values intowall_ms(counterstays 0) with the standard send/receive rules, so nothing in this crate reads a wall clock. B3 replaces the stamp source with the true hybrid clock — the wire shape and the fold are unchanged.
Order-verifiability: each op carries a per-device seq and the prev
op_id of the same device’s preceding op — a per-device hash chain.
verify_log recomputes every id and walks every chain, so a loaded or
received log proves its own order and integrity.
Honesty note — device identity is asserted, not authenticated. The
hash chain proves internal consistency (nothing was reordered or mutated
after the fact), but a forger who recomputes the hashes can emit a chain
claiming any device_id and it will pass verify_log. Cryptographic
device identity (signing ops/checkpoints with a device key) lands with
the checkpoint/relay slices (B4/B6); until then, trust in a log’s origin
comes from the transport that delivered it.
Structs§
- Device
Log - The per-device append discipline: maintains the
seq/prevchain and stampsHlcvalues from anHlcClockover an injectedWallClock— B3’s real hybrid clock, replacing B1’s pure-Lamport stamp source behind the same wire shape. - Hlc
- Hybrid-logical-clock stamp — the proposal’s
{wall_ms, counter, device_id}. The derivedOrd(field order) IS the total order every device agrees on. B1 stamped pure Lamport values into this shape; B3’sHlcClocksupplies the real hybrid clock — the wire shape is unchanged, exactly as promised. - HlcClock
- The real hybrid logical clock (B3) — the proposal’s
{wall_ms, counter}state with the standard HLC send/receive rules (Kulkarni et al.): - OpRecord
- One state-changing operation in the oplog.
Enums§
- Chain
Error - A chain-verification failure from
verify_log. - Fold
Tier - How a surface folds — the proposal’s per-surface fold-rule tiers.
- Scope
- Visibility regime — the proposal’s “the
scopefield is the whole answer”. - Surface
- Which persisted surface an op mutates — the proposal’s surfaces.
Functions§
- canonical_
json - Canonical, key-sorted, compact JSON — the deterministic serialization the
op_iddigest andcrate::fold::state_hashare computed over. Independent ofserde_json’s map-ordering configuration. - logical_
clock - A wall clock that never advances (always 0): the HLC’s degenerate pure-Lamport mode — B1’s stamp semantics, now produced by the same hybrid-clock code path.
- system_
clock - The real wall clock — the ONE place system time enters this crate, and only ever by explicit caller opt-in.
- verify_
log - Verify a log’s integrity and order: every id recomputes, and every
device’s ops form a contiguous,
prev-linked, HLC-monotone chain from the first op present for that device (a checkpointed log need not start atseq 0, but ifseq 0is present itsprevmust beNone).
Type Aliases§
- Wall
Clock - An injectable wall-clock reading (milliseconds since the Unix epoch).