feat(peers): P2P sync phase 1 — SQLite op-log + HLC + column-LWW on progress_tasks#129
Merged
Conversation
…o register schema
…stener errors to logger
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>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 onprogress_taskswith a hardcoded-address WebSocket transport. No user-facing behavior change: the transport only activates whenADC_PEER_PORTis 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— primitivessrc/main/features/peers/{schema,op-log,lww-merge,replication-engine,ws-transport,peer-config}.ts— coredrizzle/0026_op_log_and_row_meta.sql— new tables (op_log,row_meta)src/main/features/progress/progress-service.ts— 4 newrecordLocalWritecall sites (create/update/archive/delete)src/main/bootstrap/service-registry.ts— constructs engine; fire-and-forget WS transport when port is setdocs/peers/phase1-dev-harness.md— manual two-instance verification stepsScope boundary — explicitly NOT in this PR
progress_tasks(Phase 4)Test plan
npx vitest run --config vitest.integration.config.ts tests/integration/peers)npx tsc --noEmit)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)archiveTasknot covered by the new progress-service replication test (low risk — functionally identical toupdateTask)Commits
17 commits on
feature/p2p-sync-phase1, taggedp2p-phase1-doneatc519696a.