SSM-Clock Stamp – Resync from Sidecars (repair local ledger) (5.5)

Objective. Restore a damaged ledger without touching any stamps by rebuilding it from sidecar lines — deterministic, plain ASCII.

Setup (inputs)

  • Sidecars on disk, each containing the single-line stamp:
    SSMCLOCK1|iso_utc|rasi_idx|theta_deg|sha256(file)|chain[|kv:...]
  • The existing ledger may have deletions/reorders.

Procedure (deterministic, copy-ready)

  1. Collect sidecars for the time range you want to rebuild. Read each full line verbatim (carry any kv: tail unchanged).
  2. Sort by local creation order if known; otherwise, use a stable ASCII order you will keep for the rebuilt ledger (this choice affects only ledger presentation, not stamp validity).
  3. Rebuild from zero:
    • Seed: chain_0 = "0"*64.
    • For each sidecar line k, reconstruct stamp_core_k = "SSMCLOCK1|" + iso_utc + "|" + rasi_idx + "|" + theta_deg + "|" + sha256(file).
    • Select H_chain from kv:chain_algo (or default sha256).
    • Compute chain_k' = H_chain( ascii(chain_{k-1} + "|" + stamp_core_k) ).
    • Require chain_k' == chain from the sidecar.
    • Append the original full line to the new ledger; set prev = chain_k'.
  4. Atomically replace the damaged ledger with the rebuilt file (e.g., write to ledger.tmp then rename).

Expected result

  • A fresh, append-only ledger whose per-row chain values match the sidecars exactly; a subsequent continuity rewalk yields CHAIN_OK=true.

Why this works

  • Sidecars are the ground truth: each includes the recorded chain derived from chain_0 = "0"*64 and its stamp_core.
  • Recomputing chain_k = H_chain( ascii(chain_{k-1} + "|" + stamp_core_k) ) using the exact ASCII fields guarantees parity when no bytes changed.

Operational notes

  • Do not reprint/normalize inner fields (keep theta_deg as recorded with its fixed digits; digests remain lowercase 64-hex).
  • Mixed algorithms are fine: choose H_chain per row from kv:chain_algo.
  • If any sidecar fails the recomputation, flag that sidecar as suspect and do not include it.

Minimal verifier tail (after rebuild)

LEDGER_OK=true

Navigation
Back: SSM-Clock Stamp – Ledger Break (row deletion/reorder) (5.4)
Next: SSM-Clock Stamp – Daily Anchor Parity (ledger vs sidecars) (5.6)