Files
patriothacks/.omo/evidence/coherence-audit/assembly.md
T
OmO Orchestrator 93101cf237 docs: add 13-mini-app concept-execution coherence audit evidence
Full read-only audit of all 13 mini-apps against README's problem-mapping
table + each module's own doc comments. 6 COHERENT (lightclock, fairdraw,
healthpost, theclimb, sky, mentor), 7 GAP-FOUND and fixed in prior commits
(fairshare, waterwatch, tunnelsafety, housing, assembly, findfamily, farms).
2026-11-20 17:58:56 -05:00

11 KiB

Coherence Audit: Assembly (ma-assembly)

Scope: README's claim - "Yjs CRDT for offline-first proposals/rosters/votes with liquid-democracy tally, a 3-layer resilience model (local-first, WebRTC partition-and-heal, QR-sneakernet air-gapped fallback), and a signed public testimony board reusing the same event-log infrastructure as group voting." Testimony board sync is explicitly OUT of scope here (already audited and fixed this session - see .omo/evidence/service-sync-reevaluation.md).

Files read: src/lib/governance.ts, src/lib/assemblySync.ts, src/lib/qrSneakernet.ts, src/lib/governanceEvents.ts, src/miniapps/assembly/useAssemblyEngine.ts, src/miniapps/assembly/AssemblyScreen.tsx, plus grep across src/ and .omo/evidence / .omo/plans for cross-references.

1. Liquid democracy - REAL, not mislabeled

src/lib/governance.ts implements actual vote delegation, not plain one-resident-one-vote QV wearing a label:

  • DelegationRecord { delegatorId, delegateId } + putDelegation / removeDelegation (governance.ts:60-120, CRDT-backed Y.Map).
  • resolveEffectiveVoter (governance.ts ~190-230) walks the delegatorId -> delegateId chain transitively (A delegates to B, B delegates to C -> C's ballot counts for A), with a visited set that detects a cycle (A -> B -> C -> A) and deterministically falls back to the starting resident's own ballot instead of looping or double-counting.
  • computeQvTally (governance.ts ~270-330) resolves every enrolled resident's effective voter through resolveEffectiveVoter before adding their sqrt(credits) weight to a tally bucket - delegation moves whose choice counts, never whose credits are spent (the module's own stated design, matching real liquid-democracy semantics, e.g. Behrens et al.).
  • Wired into the UI: AssemblyScreen.tsx has a "Your delegation" card (assembly-delegate-select / assembly-delegate-submit / assembly-revoke-delegation) calling useAssemblyEngine's delegate / revokeDelegation, which call putDelegation / removeDelegation directly. Casting your own ballot and having an active delegation are mutually exclusive in the UI (canVoteDirectly = isEnrolled && myDelegation === undefined), matching the documented "delegation is global, not per-proposal" semantics.

Verdict: liquid democracy is a real, correctly-implemented, UI-reachable mechanism - transitive, cycle-safe, distinct from the QV ballot/credit mechanism it sits on top of. No gap here.

2(a). Local-first layer - REAL

useAssemblyEngine persists the AssemblyDoc/GovernanceDoc via openPersistedAssemblyDoc (y-indexeddb), re-renders on doc.on("update"), and exposes a synced flag read directly off IndexeddbPersistence.synced (never hard-coded). Proposals, roster, delegations, credits all live in the Yjs CRDT and work with the WebRTC sync toggle permanently off - the toggle defaults to false ("Assembly stays fully offline/local-first until a resident opts in", per the hook's own doc comment). Genuine zero-network operation.

2(b). WebRTC partition-and-heal layer - REAL and wired

src/lib/assemblySync.ts's connectAssemblySync wraps a genuine y-webrtc WebrtcProvider (real signaling + RTCDataChannel transport, not a stub) with a self-hostable default signaling URL (VITE_SIGNALING_URL / ws://localhost:4444) and an opt-in third-party fallback. useAssemblyEngine wires this to a real "Sync with devices using the same code" toggle in AssemblyScreen.tsx with a live peer count (connectedPeerCount(), never fabricated - stays honestly 0 when partitioned or when RTCPeerConnection is undefined, e.g. in tests).

This is independently confirmed by prior work in this repo: gate review .omo/evidence/the-commons-hollow-polish/task-11-the-commons-hollow-polish-gate-review.md documents a Playwright test driving two isolated browser contexts through the shipped screen's own UI - connect over real WebRTC, prove a proposal seeded on side A arrives on side B, partition (toggle off + setOffline, tearing the real RTCDataChannel), independent proposals on each side proven not to cross, heal (toggle on + network restored), and converge to the identical union set. service-sync-reevaluation.md separately verdicts this "works as claimed." This layer is genuine and demonstrable end-to-end through the real UI, not a console-only harness.

2(c) / 3. QR-sneakernet layer - GAP FOUND: real transport, zero UI wiring, camera never reachable

src/lib/qrSneakernet.ts is a genuinely well-built transport:

  • encodeDelta / decodeFrames / FrameCollector chunk a real Yjs CRDT delta (Y.encodeStateAsUpdate) into self-describing frame strings with per-frame CRC32, sequence/total, and whole-delta length+CRC32 (so a misread, dropped, or cross-transfer frame is detected rather than silently corrupting the reassembly).
  • renderFrameToDataURL / renderFramesToDataURLs use the real qrcode package to render actual QR code images.
  • scanFrameFromImage uses the real jsQR package against a CameraImage { data, width, height } (the exact shape canvas.getImageData produces) - this is a genuine QR decode, not a copy-paste text blob.
  • The task-24 build evidence (.omo/evidence/the-commons-hollow/task-24-the-commons-hollow.json) confirms a real round-trip: a 17,779-byte Yjs delta (well over one QR's ~2.9KB capacity) chunked into 35 frames, reassembled out-of-order with a dropped-then-retried frame, byte-for-byte equal to the original, then applied to a target Y.Doc via Y.applyUpdate - genuinely exercising the CRDT, not a toy string.

But it is never called from anywhere outside its own test file. Grep across src/ for qrSneakernet|scanFrameFromImage|FrameCollector|encodeDelta|decodeFrames and across src/miniapps for qrSneakernet turns up matches only in qrSneakernet.ts itself and qrSneakernet.test.ts; miniappSharing.ts mentions it only in a comment ("Assembly's QR-sneakernet transport ... kept independent here"), never an import. AssemblyScreen.tsx / useAssemblyEngine.ts import QRCode from the qrcode package directly, but only to render the WebRTC sync-room-code string as a QR code (QRCode.toDataURL(syncRoomCode, ...))

  • a plain text room-id QR, unrelated to qrSneakernet.ts and carrying no Yjs delta at all. encodeAssemblyState / applyAssemblyUpdate (src/lib/assembly.ts, the functions qrSneakernet.ts's own header says callers should pair it with) are likewise used only in assembly.test.ts and assemblySync.test.ts - never in a mini-app screen.

There is also no getUserMedia / BarcodeDetector / any camera API call anywhere in src/ (confirmed by grep: zero matches). The task-24 evidence file says this explicitly under its own real_qr_packages_wired.camera_note: "no real camera needed for the acceptance tests ... scanFrameFromImage is the production jsQR entry point a <video>->canvas pipeline feeds" - i.e. the <video>-to-canvas pipeline that would make a camera scan reachable was never built. This was also already flagged as an open item in this project's own planning history: .omo/plans/the-commons-hollow.md line 748 calls for exercising "the QR-sneakernet path (todo 24) with a real camera on a real device at least once (plan-consultant finding F4 - no automated test touches an actual camera)" - that follow-up was never done, and no UI affordance to even attempt it (an "Export sync code via QR" / "Scan a device's QR" button pair for the Assembly CRDT state) exists in AssemblyScreen.tsx today.

Answering the audit's specific question 3 directly: the camera is never invoked anywhere in the shipped app for this purpose. QR-sneakernet is tested only via hand-built Uint8Array deltas and synthetic RGBA bitmaps in qrSneakernet.test.ts, never reachable through a real camera scan in the UI.

4. Claimed-but-unwired UI/feature summary

Claim Status
Liquid-democracy delegation (transitive, cycle-safe) Wired, real, reachable
WebRTC partition-and-heal Wired, real, reachable (Playwright-proven through the shipped screen)
QR-sneakernet air-gapped CRDT transport Built but completely unwired - zero production callers, no camera pipeline, no UI entry point

Verdict: GAP-FOUND (one layer of three)

Two of the three claimed resilience layers (local-first, WebRTC partition-and-heal) and the liquid-democracy tally are coherent: genuinely implemented, UI-reachable, and independently verified by this project's own prior Playwright evidence. The third layer, QR-sneakernet, is a real, carefully-engineered, well-tested transport module (src/lib/qrSneakernet.ts, 9 passing unit tests, a documented 17.7KB real-delta round-trip) that is completely disconnected from the shipped app - exactly the "claimed but unwired" pattern the audit was looking for. The README's "3-layer resilience model ... QR-sneakernet air-gapped fallback" phrasing therefore overstates what a user can actually do: there is no way, today, to open the Assembly screen and move governance state between two air-gapped devices by camera.

Exact gap location: src/lib/qrSneakernet.ts (fully built, zero non-test importers) vs src/miniapps/assembly/AssemblyScreen.tsx / useAssemblyEngine.ts (no import of qrSneakernet.ts, encodeAssemblyState, or applyAssemblyUpdate; no <video>/getUserMedia anywhere in the file).

Effort-size honesty, per the project's own standing preference for a real fix over a half measure: wiring this is a genuinely larger scope item than a quick fix, but it is buildable now with code that already exists - nothing novel needs inventing:

  1. An "Export state as QR" control: call encodeAssemblyState(assembly), feed the bytes through encodeDelta, animate the resulting frames with renderFramesToDataURLs (all three functions already exist and are tested).
  2. A "Scan a device's QR" control: a <video> element + getUserMedia (camera permission) + a canvas drawImage/getImageData loop feeding scanFrameFromImage into a FrameCollector, then applyAssemblyUpdate(assembly, collector.reassemble()) once complete - this is the one genuinely new piece (the camera capture loop itself; getUserMedia appears nowhere in this codebase today, so it would need its own permission-prompt/error-handling UI, unlike the already-proven encode half).
  3. Manual QA with a real camera on a real device (the plan's own previously-flagged, never-closed F4 item).

This is a multi-hour UI task (new component + permission flow + a manual camera QA pass), not a one-line fix - but it is well within reach given the transport layer is already complete and tested. The alternative - correcting the README to describe QR-sneakernet as "a built, tested, not-yet-wired transport" rather than a working third resilience layer - is the honest stopgap if this item is deprioritized, but given the module is this close to done, wiring it is the better fix and should not be quietly downgraded to a documentation change.