← Back to Pull requests

feat: the cloud sync engine core (#409) #416

Closed
unknown closed this pull request without merging on Dec 01, 2026 03:34 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 07:19 UTC
Author

Part of #409 (phase 2 of 4). Groundwork only — bm_sync_enabled is off everywhere and nothing constructs the engine yet, so no user-visible behavior changes and no changeset (docs/tests/internal work may omit one).

What

  • syncEngine.js — one engine over the composite store and a cloud store: every local change pushes up, every remote change applies down. One snapshot (uuid → synced view) is the single source of "what has been said"; both directions are the same diff-and-write move, and the snapshot moves only after the write lands, so a refused write is retried by the next notification and an echo of a landed write finds nothing left to say.

  • Notifications are ticks, not state: reconciles serialize through one promise chain and re-read the side that changed before diffing. A payload captured before earlier queued writes landed is already history — trusting it resurrected deleted bookmarks in an infinite reconcile loop during development; re-reading closes that class.

  • syncSetting.js — the bm_sync_enabled flag, off by default, SDK-free so first paint never pulls the Firebase chunks.

  • firebaseStore.putMany — the engine's up-write: full documents keyed by uuid (document id = uuid, so #407's "document id wins" holds by construction), item timestamps preserved, no id field ever stored.

  • localCompositeStore — honors an explicit updatedAt in a patch (sync applies keep the moment the change happened) and keeps urlStatusReason on bookmarks adopted from the cloud.

  • DESIGN.md — the sync-engine paragraph in the persistence boundary.
  • Deliberate limits (later phases)

  • Conflicts: LWW on the bookmark's updatedAt at the initial reconcile, arrival order after; phase 4 adds field-level resolution.

  • A deletion made while the engine is off is forgotten — the cloud copy reads as an adoption; phase 4 adds tombstones.

  • Legacy non-uuid cloud documents are ignored, not adopted — phase 3's initial reconciliation owns that.
  • Tests

    10 engine tests over in-memory doubles mirroring the composite's semantics (echo suppression in both directions, LWW, deletions both ways, legacy-document isolation, refused-push retry, stop, failed start), 2 flag tests, and store tests for putMany, explicit-updatedAt, and adopted failure reasons. npm run ci green locally.

    <!-- agent-bot-write: ghw_e674ab43be367d71 session=acad26a80cec bot=trueline-zcode-agent[bot] -->

    Diff: 300 lines (+225 / -75) across 3 files Reviewer: qwts Review duration: 1215m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 300 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.341
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #416"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.1% (MEDIUM) · Higher = larger blast radius
    40.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.8% · Safe to merge
    15.8%