← Back to Pull requests

fix: the Firestore document id is a bookmark's identity, not stored data (#407) #408

Closed
unknown closed this pull request without merging on Nov 30, 2026 06:09 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 06:03 UTC
Author

Closes #407

What was wrong

Every bookmark created in Firebase mode stored a literal id: null field in its Firestore document, and every read then let that stored field win over the real document id. From there, exactly the reported symptoms:

  • Edit duplicated the bookmark — saveBookmark saw a falsy id and routed the save through create (a second document).

  • Delete failed — remove(null) built a null path segment, which Firestore refuses.

  • The Firestore console showed documents with id: null.
  • The corruption came from both ends of the same spread:

    1. The create forms hand the store objects carrying a transient id: null (the full app's add form and the popup's quick add), and create() spread the whole object into addDoc — the local composite store never exposed this because it cherry-picks fields.
    2. readAll() and the snapshot handler mapped { id: d.id, ...d.data() } — the stored id overrode d.id.

    Documents written by bulkAdd/bulkReplace were unaffected (they overwrite id with the generated reference id), which is why adopted/imported bookmarks behaved.

    The fix

    The document id is the bookmark's identity, never document data:

  • Reads (readAll and the snapshot handler) spread data first: { ...d.data(), id: d.id }.

  • create() strips the caller's transient id before addDoc.

  • update() strips id from the patch (defensive — every current caller strips it, but the contract now holds at the store too).
  • The read-side rule also heals the already-corrupted documents: a document carrying a legacy id: null reads back with its real document id, so delete and edit work again with no migration. (The stale field stays in those documents, inert; any future update that rewrites them simply doesn't carry it.)

    Tests

    Three new tests in a firebaseStore document identity (#407) describe: the create form's transient id never becomes document data; a stale stored id loses to the document id in both the snapshot and list(), and a delete with the healed id reaches the document; a patch's id field is never written into the data. npm run ci green; DESIGN.md carries the invariant in the persistence boundary; patch changeset included.

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

    Diff: 290 lines (+217 / -73) across 3 files Reviewer: qwts Review duration: 6m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 290 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: 84% · Reviewer familiarity: 35%
    56%
    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.339
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #408"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.6% 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: 39.9% (MEDIUM) · Higher = larger blast radius
    39.9%
    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: 56.6% · Lower = rushed or shallow review
    56.6%
    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: 17.3% · Safe to merge
    17.3%