← Back to Pull requests

Fix ways a run could create duplicate items #77

Closed
unknown closed this pull request without merging on Oct 04, 2026 19:53 UTC
View on GitHub
unknown unknown commented on Oct 04, 2026 19:21 UTC
Author

Fixes from a bug hunt through the recent changes. Most of them stop the tool from creating duplicate items, or adding wrong statements, on Wikidata.

A restart during a create no longer invites a duplicate (a12cee9)

  • Logged before it's sent. Each create's wikidata_edits row is written as "unknown" before the request goes out, then updated when Wikidata answers. Before, the row was only written after the answer. If a deploy restarted the server mid-create, the run was marked "interrupted", the UI said to start it again, and the item could be created twice.

  • Restart mid-create. markInterrupted now ends such a run "unknown", with "The server restarted while creating this, so it may have been created anyway." The check before the next run then asks the user to confirm, as it already does after a timeout.

  • Refused creates. If Wikidata refuses a create, the same row becomes the failure, so a create never gets two rows.

  • Failed search. If the search after a create with no answer itself fails, the run now ends "unknown", not "failed", so a rerun is still guarded.

  • Hidden while in flight. A create still waiting on Wikidata is left out of the live run log, so it doesn't flash "Outcome unknown".

  • No more crashes. A failed final status write in runPlan could reject unhandled and take the whole process down, cutting off every other user's run. The run now has a .catch, and that write is retried twice. The user's run guard is only let go once the run's end is saved, so another tab can't start the same form while the run still says "running" (531e4d8).

  • Recovered albums. An album create found later by checkUnknownRun now also sets the run's album_qid, so the album list shows it as created.
  • Leaving the page during a run keeps its QIDs (addbb43)

  • The bug. QIDs were only written back into the form while the form stayed mounted. Going to the new album list, reloading, or opening a run from the list during a run lost them, and a rerun created every item again.

  • The fix. The id of the run started from the form is now kept in localStorage. When the run ends, its QIDs are written back, even if the user was on another page or had another run open.

  • Guard. The form has an id, renewed by Clear, Load the example and a MusicBrainz import. QIDs are only written back into the form the run started from, so a form cleared or loaded with another release (even one with the same title) doesn't receive them. Edits to the form during the run still do.

  • Polling. Runs are only polled while logged in, and a 404 stops the polling instead of retrying forever.
  • A reused track isn't given a second composition (af0bcd3)

  • The bug. A row with an existing track but an empty composition field made the run create a new composition and add a second P2550 to the track. This happened when MusicBrainz matched the recording but not its work, or when the track's QID was typed in. The review step didn't catch it.

  • Check before a run. The run is now refused if a reused track already records a different composition, or if a track with none yet is used in two rows with different ones (74c26dd). The message names the rows and the composition to use. This costs one wbgetentities request per 50 reused tracks, and none when no tracks are reused.

  • Fill in unambiguous matches. An empty composition is now filled from the track already chosen.

  • Review step. A row with a used track stays unreviewed until that track's own composition is used or dismissed.
  • Two rows of the same MusicBrainz work creating two compositions is tracked separately in #76.

    Two tabs can't overwrite each other's form (ed5175e)

  • The bug. Each tab saved its whole form to localStorage, so the last tab to save won. A tab left open could undo the QIDs another tab's run wrote back, and then a run from it would create everything again.

  • The fix. A tab whose form was changed in another tab shows a banner with a Reload button. Until it's reloaded it can't start a run, and what's changed in it isn't saved. The tab being typed in works as before.

  • Runs. A tab follows a run started in another tab, so its QIDs still go back into the form when it ends.

  • Other devices. These checks only work inside one browser. A server-side check is tracked in #78.
  • Testing

  • vp check and vp test pass, with new tests for the composition check, the fill and the review step.

  • Run paths, against a local test database with Wikidata mocked: a create that succeeds, one Wikidata refuses, one found after no answer, a failed search after no answer, a restart mid-create followed by markInterrupted, and a failed final status write. 4 of these 6 fail on main. They're scratch tests, not in this PR, since the repo has no database test setup.

  • Own run. Its logic is in src/lib/own-run.ts, with tests for saving and loading it, when its QIDs go back into the form (only the form it started from), dropping it on a 404, and writing QIDs by plan key. RunSection only wires these to its state and polling, and that wiring has no tests.

  • Two tabs, checked in a browser. Typing in one tab kept every keystroke and saved it. The other tab showed the banner, saved nothing even when typed in, and showed the change once reloaded.

  • Not covered by tests. The checkUnknownRun album link.

  • Not checked in a browser. A real run would edit Wikidata, so the write-back after leaving the page still needs trying by hand. Start a small run, go to Albums or reload, then come back. The created QIDs should appear in the form once the run ends.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: connorshea Review duration: 31m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #77"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%