8000 feat(sync): reliable secure LAN sync — whph_sync_core engine, security propagation, simulator oracle and SC-001 proof by ahmet-cetinkaya · Pull Request #318 · ahmet-cetinkaya/whph · GitHub
[go: up one dir, main page]

Skip to content

feat(sync): reliable secure LAN sync — whph_sync_core engine, security propagation, simulator oracle and SC-001 proof - #318

Merged
ahmet-cetinkaya merged 130 commits into
mainfrom
feat/reliable-secure-lan-sync
Nov 8, 2026
Merged

ahmet-cetinkaya merged 130 commits into
mainfrom
feat/reliable-secure-lan-sync

Conversation

@ahmet-cetinkaya
@ahmet-cetinkaya ahmet-cetinkaya commented Oct 19, 2026 •
Copy link
Copy Markdown
Owner

Summary

Adds the pure-Dart sync engine package packages/whph_sync_core (M1 + review fixes) and the simulator/oracle that proves it, per plan 0001 reliable-secure-lan-sync (F5 program).

Engine fixes (Efe-reviewed, card A + B.2 + C + 100336 rulings)

  • Relay/superseded fix (F5): index superseded versions in the sync store (0a504772), several disjoint ranges per origin in a batch (b3b03ea9).
  • Card A round 2 (6e6d0e6e, 3b7a8da5): flush the written watermark at session start/end, before restore and at copy time via the store's dirty flag; failure counters.
  • B.1/B.2 revocation propagation (9162e629, b8de0534): re-publish own directory-verified revocations stranded on sealed unserved carriers; "served" means manifested + rooted carrier origin + seq ≤ persisted sent mark; key-lost re-issue only after re-pair; quiet-sync counts security cells.
  • Rooted membership (29aa047d, 656fca91): trust anchored in key-file anchors; key loss leaves no member row on the new origin.

Simulator/oracle model (Efe rulings A+C, then 100336)

  • Stale-restore marking (causal trigger), needsRepairing-driven re-pair repair model, stale-cluster exclusion with K=2 auth-only rounds and explicit-auth-only pair classification (35ae4692, a45b8486, b507db6c).
  • Stranded-revocation holder rule; post-exclusion carrier-reachability (author i 8000 n cluster AND no converged copy) and member-row strand rule with device-id divergence clause (70ee43d8). Pure decision cores (decideStaleExclusion, strandedRevokedPubs, unreachableClusterWinners, strandedMemberIdentities) with engineered guard tests and 4 recorded mutation-red checks.

SC-001 status: CLOSED

  • Gates under final semantics 70ee43d8: smoke +23, stale-cluster suite 12/12, 16/16 targeted seeds violations=0 (incl. the former failure 100336 → 0), determinism double-run, negative controls.
  • Supplementary: partial full passes — 351 seeds (1 failure, root-caused and fixed by the ruling) and 265 consecutive seeds all 0 under final semantics. The 1000-seed number was waived by human order (CPU/energy).
  • Closure note: .agents/state/reliable-secure-lan-sync/evidence/sc001-closure.md (working-tree only, gitignored); key logs: ruling-gates.log, mutation-red.log, sc001-full2.log, sc001-seed100336*.log, release-condition-justification.txt.

Documented limitations

  • Post-exclusion crossing is fail-closed by endgame assertions; the dynamic path is unmodeled (mid-run repair covers the real path).
  • Third-party re-issue of stranded revocations: roadmap card, not started.
  • Soak ceiling going forward: class representatives + 8-10 randomized picks, -P2, on rule changes only.

Commit chain: 9162e629..70ee43d8 (28 commits on top of origin/main).

Test plan

  • fvm dart test --tags sim-smoke (+23), full non-soak suite (+501 ~2 skipped), stale-cluster suite 12/12 — all green on 70ee43d8
  • Mutation-red checks recorded for all four oracle guards
  • Reviewer: confirm evidence bundle paths in .agents/state/... (gitignored; ask @ayg-n for copies if needed)

Known gap: T28 performance gate is UNMET

The T28 loopback benchmark (test/performance_sync/sync_performance_loopback_test.dart, tag perf-sync) has a gate: first sync of the large_usage fixture (about 657k cells) must finish in 10 minutes or less. It does not. We measured about 23 minutes on a desktop over loopback (about 480 cells/s; the cost is per-cell SQL statements and pure-Dart ChaCha). The gate was not raised or weakened.

The benchmark is a manual run (its file header says how). CI used to run it inside the generic flutter test and it hit the 30 minute limit, so the generic runs and the Performance Tests job now pass --exclude-tags perf-sync (commit 21e9c4c). The speedup (batched per-cell SQL and crypto) is a separate follow-up, ACF-99.

Also in this round: EC-04 got its own 3 minute test timeout (a4dcbff), because four sessions over 1500 notes take about 20 s locally and more on CI runners; its assertions are unchanged.

New pure-Dart package for the reliable and secure LAN sync (change 0001, M1):
HLC + field-level LWW, per-origin version vectors with declared ranges,
Noise XXpsk3 sessions, signed batch manifests, group epochs and key
handover, membership with grow-only trust anchors, and an out-of-data-dir
sync ledger. Includes the simulator with an independent oracle, fuzz and
regression suites.

U11 fixes (F1, F3, F4, G1, G2/G2b) and the security review rounds:
- ledger keeps signed revocation records, written before the DB commit
- ledger revoker entries are verify-only and grant no trust
- a storage error stops further commits in the session
- a flagged signer without a record is held as unverified
- ledger-only revocations set local cutoffs only: no self-extension,
  rotation, anchor flag or self-removal

Known open gap F5 (relay omits a superseded change) is tracked by the
f5-pending test, skipped by default.
Protocol v3 (F5 step 1a): ChangeBatchMessage.ranges carries a list of
ranges per origin. The receiver sorts each origin's ranges, rejects
duplicate or overlapping ones, requires every envelope to lie in exactly
one range, and advances the cursor ascending. maxRangesPerBatch caps the
count before any other work.

The sender still emits one range per origin, so sync behaviour is
unchanged; the superseded-change relay builds on this.
F5 step 1b: SyncStore keeps, per origin, the seqs whose version was
replaced by a newer winner, with the key of that cell. Recorded only in
the replace branch of _put; a same-version re-put, the _clone rebuild and
the adoption re-keying in switchOrigin record nothing. _clone copies the
index, an origin switch prunes entries whose cell is gone, and a
debug-only check (run by the simulation after every op) keeps the index
disjoint from the stored winners.

Nothing reads the index yet, so sync behaviour is unchanged.
… session start/end and before restore, and count failures
…ooted, key-lost re-issue only after repair, quiet-check counts security cells
…imulator per Efe rulings A+C

- needsRepairing-driven repair step (re-pair self, re-invite stranded, never revoked keys); SIM_NO_REPAIR negative control
- causal staleRestored marking on restore ops; mutual-complete cluster partition; auth-only evidence (K=2); never-stale member blocks exclusion
- stranded-revoked accounting: identities whose only revocation records live inside an excluded cluster are not expectable revoked on the converged set (stat + log line)
- provisional exclusion in the quiesce loop so excluded devices do not block quiet
- regression tests: dir-restore stranding/flag-only-cleared-by-pair; registration relearn probes; sim_stale_cluster_test (100006 clusters+stranded+det, 100003 clean no-exclusion, SIM_NO_REPAIR 100160)
…er the engineered guard cases

- decideStaleExclusion pure function (cluster partition + evidence gating)
- never-stale acceptor blocks exclusion; other-failure blocks; whole-set-stale reported not excluded
…revocation decision core, assert exclusion counters

F1: only explicit notAuthorized/refusedByPeer counts as auth evidence at
pair level; unknown/transport failures count as otherFail so a cluster
that merely cannot reach outsiders is never excluded as stale.

Extract strandedRevokedPubs as a pure decision core with a data-level
test for rule (7): relaxation only when every holder of the record is
inside the excluded cluster.

sim_stale_cluster_test now asserts the F2 evidence counters and the
second-run trace stability on seed 100006.
…stranding per Efe 100336 ruling

(a) unreachableClusterWinners: a required/optional write is not expectable
on the converged side iff its author is inside the excluded cluster AND no
converged device holds a copy of that version (crossed copies keep the
winner required). Authors come from the oracle itself, not from holders.

(b) strandedMemberIdentities: a final identity whose every member row was
authored inside the excluded cluster is not expected in converged views;
id-level view diffs fully attributable to excluded-cluster identities are
counted as staleClusterDivergence (device-id clause), not violations.

Guards: a1/a2/b1/b2 engineered tests; 100003 no-relaxation control (both
new counters zero); 100006 determinism extended to the new counters.
Mutation-red for A (third condition deleted) and B (every->any) recorded.
@ahmet-cetinkaya ahmet-cetinkaya self-assigned this Oct 19, 2026
…M INTO backups, sqlite connection setup, spike suites and fixtures

Prepares Phase 2 (T13-T19) on the phase2 branch:
- database_backup_service: VACUUM INTO snapshot writer injected from the
  open connection (Drift does not wrap onUpgrade in a transaction);
- sqlite_connection_setup: shared WAL/busy-timeout connection wiring;
- spike suites (crypto/dedupe/scale/trigger) + fixtures + WAL/backup tests
  that T13-T19 build on;
- run_tests.sh: sync spike lanes; pubspec: whph_sync_core path dependency.
… cannot be checked without the key file stay on disk (#332 follow-ups M-1, M-2)
…-joiners

feat(sync): expose stranded joiner ids in the origin switch outcome (ACF-37)
…ac-followups

fix(sync): ledger MAC follow-ups from the #332 review (M-1, M-2)
…ember-table boundary, ordering (#333 review survivors)
…tore (ACF-47)

SyncGroupState.needsRepairing was set by restore/key loss but only removedFromGroup had a card, so a device restored from an old backup stopped syncing without a word. NeedsRepairingCard explains it and offers pairing, in all 22 locales.
…-tests

test(sync): close the #333 mutation survivors for stranded member ids
…rompt

feat(sync): prompt to pair again after a stale restore (ACF-47)
…ate (#336 review MINOR)

Extracts SyncGroupStateCard from the sync devices page so the mapping from SyncGroupState to card is testable; widening needsRepairing to ungrouped now fails a test.
…d on an origin no single member owns (ACF-49)

maintainMembership already re-issued own records stranded on a sealed origin. It now also re-issues a directory-verified record authored by another member when its carrier origin is unregistered or conflicted, so peers reject the carrier cell and cannot fetch the record. Ledger-only records are never re-issued and the re-issue stays idempotent.
…rty-reissue

test(sync): group-state card shows only the card meant for its state (#336 MINOR)
…rty-reissue

feat(sync): third-party revocation re-issue for records stranded on an unowned origin (ACF-49)
…can button works

Navigator.pushNamed<String> cast the app's PageRouteBuilder<dynamic> to Route<String?>
and threw, so the scanner page never opened on Android. QRCodeScannerPage.scan pushes a
MaterialPageRoute<String> instead.
…evice can sync

Joining a group schedules the reauthor phase, but only app start ran the job, so every
sync was skipped silently until a restart. The membership service now starts it in the
background once the switch commits, and logs a failure instead of dropping it.
…a device joins

The manual dialog only took an IP and port, which cannot pair under the invitation flow,
so it now takes the pairing code the other device shows (with a copy button). The old
connection string is removed. The connect-info dialog is centred and tells the page when
a device paired so the list reloads. This commit also carries the translation keys and
the 22 locale files for the progress and hint texts of the next commit.

feat(sync): show per-device progress and the last failure on the device card

A syncing device's card shows an approximate percentage and a bar (processed batches over
the total known after the vector exchange); the loading overlay and the failure toast are
gone because the card and the AppBar button already say it. Not-reachable gets a hint to
start Server Mode on the other device. The desktop, which answers sessions, now records
the peer's last success and clears a stale not-reachable result, and its sync button also
shows in server mode. The Server Mode card is hidden while the server is off.
…ted session's result when the status write fails
…ring code, show a stalled preparation and drop the pending ledger entry on a refused switch
…onnection mode the same on desktop and phone
…0 notes outrun the 30 s default on CI runners
… min limit and its first-sync gate (10 min) is unmet (~23 min)
@ahmet-cetinkaya
ahmet-cetinkaya merged commit 694d006 into main Nov 8, 2026
5 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.

1 participant

0