Skip to content

feat(peers): P2P sync phase 1 — SQLite op-log + HLC + column-LWW on progress_tasks#129

Merged
ParkerM2 merged 17 commits into
developfrom
feature/p2p-sync-phase1
Apr 24, 2026
Merged

feat(peers): P2P sync phase 1 — SQLite op-log + HLC + column-LWW on progress_tasks#129
ParkerM2 merged 17 commits into
developfrom
feature/p2p-sync-phase1

Conversation

@ParkerM2
Copy link
Copy Markdown
Owner

Summary

Phase 1 of the P2P sync migration (spec: docs/superpowers/specs/2026-04-24-p2p-sync-design.md). Proves the SQLite + op-log + HLC + column-level LWW replication stack on progress_tasks with a hardcoded-address WebSocket transport. No user-facing behavior change: the transport only activates when ADC_PEER_PORT is set.

Retires no existing code. Hub sync (v0.2.0) continues to work unchanged. Phases 2-5 will add schema sweep, mDNS/PIN pairing + TLS, extend to all sync-scope tables, and finally retire hub/.

What ships

  • src/shared/replication/{sync-tables,hlc,op-types}.ts — primitives
  • src/main/features/peers/{schema,op-log,lww-merge,replication-engine,ws-transport,peer-config}.ts — core
  • drizzle/0026_op_log_and_row_meta.sql — new tables (op_log, row_meta)
  • src/main/features/progress/progress-service.ts — 4 new recordLocalWrite call sites (create/update/archive/delete)
  • src/main/bootstrap/service-registry.ts — constructs engine; fire-and-forget WS transport when port is set
  • docs/peers/phase1-dev-harness.md — manual two-instance verification steps

Scope boundary — explicitly NOT in this PR

  • mDNS discovery (Phase 3)
  • PIN pairing / Ed25519 exchange (Phase 3)
  • TLS + fingerprint pinning (Phase 3)
  • Schema-hash handshake (Phase 2)
  • Sync for tables other than progress_tasks (Phase 4)
  • Hub deletion (Phase 5)
  • Op-log GC (Phase 4)

Test plan

  • 56/56 integration tests pass (npx vitest run --config vitest.integration.config.ts tests/integration/peers)
  • Typecheck clean (npx tsc --noEmit)
  • Lint clean on all new/modified files
  • Manual two-instance verification pending — follow docs/peers/phase1-dev-harness.md: run ADC-Dev (port 7701) + ADC-Local (port 7702) with peer env vars, create/edit/archive/delete a task on one, confirm it appears on the other within ~1s.

Known follow-ups (flagged by code review, deferred)

  • Array.isArray(ops) guard in ws-transport for malformed peer frames (minor — Phase 3 pair-security takes this seriously)
  • Fire-and-forget WS transport: no cleanup handle held by service-registry (minor; Phase 3 adds proper lifecycle)
  • archiveTask not covered by the new progress-service replication test (low risk — functionally identical to updateTask)

Commits

17 commits on feature/p2p-sync-phase1, tagged p2p-phase1-done at c519696a.

ParkerES and others added 17 commits April 24, 2026 15:47
Adds createWsTransport (WebSocketServer + optional outbound dial, reconnect
with 1s backoff) that subscribes to engine.onLocalOp and broadcasts OPS
frames to all peers; applies inbound OPS via engine.applyRemoteOp. Adds
loadPhase1PeerConfig reading ADC_PEER_PORT/REMOTE/ID_SHORT/ID_FULL env vars.
Integration test spins two engines with in-memory SQLite, migrates the
Drizzle schema, wires them over localhost WS, and asserts A→B and B→A
writes converge within 1s.

Tasks 9 + 10 of Phase 1 P2P sync plan.
…truct engine in service-registry

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@ParkerM2 ParkerM2 merged commit 6733eaa into develop Apr 24, 2026
3 of 4 checks passed
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.

2 participants