← Back to Pull requests

fix(sync): #240 hold back dangling setlist changes; server refuses referenced song deletes #241

Open
unknown opened this pull request with 306 lines diff across 3 files
View on GitHub
unknown unknown commented on Oct 25, 2026 13:19 UTC
Author

Fixes #240 with the non-destructive design agreed after review (no automatic pruning).

Client (recordsSync.ts)

  • holdBackMissingReferences: after a round is built, any cloud change that would leave a setlist listing a song not in the library is held back as a conflict (with a reason), and the rest of the round applies:

  • - cloud deleted a song this device still lists → the song stays here ("Removed in the cloud, but setlist "X" on this device still lists it");
    - cloud setlist lists songs missing here → this device keeps its own version, or none ("The cloud version lists songs that are not in your library").
    Used in normal sync, first sync (adopt) and Replace.
  • Missing entries are dropped only after an explicit conflict choice (resolveOnce); the resolution snapshot now also keeps the raw cloud records.

  • "Offline" only for network failures (TypeError / timeout / navigator offline); other failures are errors.

  • Sample cleanup (#228) keeps an unchanged sample setlist already synced to the cloud, and the songs it lists.
  • Server (songbookRecordsCore.pushRecords)

  • A song deletion is refused while a live setlist lists it (conditional NOT EXISTS … json_each(data_json,'$.songs') in the same transaction) → conflict with reason: 'referenced'.

  • Setlist writes are ordered first in the batch, so dropping the entry and deleting the song in one push works.
  • Tests (recordsSyncClient)

  • Repro of the DEV sequence (stale sample setlist + old cleanup): setlist deletion conflicts and the song deletions are now refused → cloud stays consistent.

  • DEV state (live setlist, songs deleted in the cloud): a device that has the songs keeps them, deletions wait as conflicts, unrelated changes apply; "keep this device" restores the songs in the cloud; a new device then converges.

  • New device: setlist held back, songs synced, nothing written; "use cloud" (explicit) drops the missing entries and pushes.

  • Server guard; offline vs error; cleanup keeps a cloud-synced sample setlist.
  • Full suite 1691/0 (1 pre-existing browser skip), lint, tsc, build green.

    Owner recovery on DEV after deploy: on Edge (still has the 3 songs) open Sync Center → conflicts → "Keep this device" restores Stand By Me / Hotel California / Hallelujah in the cloud; or delete "Acoustic Gig Set" instead. Do not use Replace on Edge before that.

    ---
    _Generated by Claude Code_

    Diff: 306 lines (+229 / -77) across 3 files Reviewer: chatgpt-codex-connector[bot] Review duration: 3m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.40) × (1 − Review Confidence (0.28)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 306 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 44% · Reviewer familiarity: 35%
    28%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.343
    Real PR Conversation Timeline
    1 comments
    "Review active on #241"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 28.2% 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.2% (MEDIUM) · Higher = larger blast radius
    40.2%
    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: 28.2% · Lower = rushed or shallow review
    28.2%
    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: 28.8% · Safe to merge
    28.8%
    Repository