Skip to content

quilt kernel P3: replay-verify reconciliation — the drift detector - #3

Closed
SuperInstance wants to merge 1 commit into
quilt-kernel-p2-encountersfrom
quilt-kernel-p3-reconcile
Closed

SuperInstance wants to merge 1 commit into
quilt-kernel-p2-encountersfrom
quilt-kernel-p3-reconcile

Conversation

@SuperInstance

Copy link
Copy Markdown
Owner

What

Stacks on #2#1. The dual-write is two sequential batches (D1 commits, then the WAL commits). The window between them is where drift can live. This module is the detector that closes the loop.

reconcileQuiltWal(database, walRows, readers):

  1. Verifies the hash chain first — a tampered ledger voids its own testimony: returns { ok: false, reason: chain_broken, firstBadSeq } and refuses to reconcile.
  2. Discovers entities from bare-cell binds by their kind field (never regexes on ids — production interaction ids are numeric snowflakes).
  3. Replays each nomination and encounter, diffs field-by-field against live D1: status, totals, votes, completedAt / actor, target, species, publication, message, response.

A mismatch IS the deliverable — reconciliation never mutates, never throws on drift. And the negative ledger stays honest: refusal rows are memories, not entities; reconciliation never expects encounter rows for encounters that never were.

Also

verifyChain now returns { ok } | { ok: false, firstBadSeq } — tampering points at its own break. All call sites updated.

Verification

  • 4 new tests: clean traffic → zero mismatches; D1-side drift (row changed behind the ledger's back) → flagged with wal/d1 values; tampered chain → refused with break location; vote drift between ledger and tally → caught
  • Full suite: 387 tests, 18/18 across the three kernel suites, only the 4 pre-existing artwork/env failures (verified identical on clean main)
  • tsc --noEmit clean

Refs openclaw#48

The dual-write is two sequential batches: D1 commits, then the WAL
commits. The window between them is where drift can live. This module
closes the loop: replay the ledger, diff against live rows, report
every divergence field-by-field.

- reconcileQuiltWal(database, rows, readers): refuses to reconcile a
  tampered chain (chain_broken + firstBadSeq), then diffs replayed
  nomination state (status/totals/votes/completedAt) and encounter
  state (actor/target/species/publication/message/response) against
  live D1. A mismatch IS the deliverable; reconciliation never mutates.
- entity discovery reads the bare-cell bind's kind field, never regexes
  on ids — production interaction ids are numeric snowflakes, so cell
  shape alone can't distinguish attempts from entities.
- verifyChain now returns {ok} | {ok:false, firstBadSeq} so tampering
  points at its own break; all call sites updated.
- negative-ledger awareness: refusal rows are memories, not entities —
  reconciliation never expects encounter rows for them.

tests/quiltKernelReconcile.test.ts: 4 tests — clean traffic zero
mismatches, D1-side drift flagged with wal/d1 values, tampered chain
refused with break location, vote drift between ledger and tally.

Full suite: 387 tests, 18/18 across the three kernel suites, only the
4 pre-existing artwork/env failures (identical on clean main).

Refs openclaw#48
SuperInstance added a commit that referenced this pull request Sep 20, 2026
…etector)

Conflict resolution: kept HEAD's commitNominationVoteProjection
(from PR #11) and the projection.ts structural-event changes
(from PR #2). Added PR #3's reconcile.ts (drift detector) and
the replay tests via auto-merge.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant