Skip to content

fix(purchase): skip duplicate purchase_history insert on re-drive and add a unique index #704

Closed

Description

@cristim

Summary

Re-drive and root retry insert duplicate purchase_history rows. ExistingCommitment is never read, and there is no unique index to stop the second insert. Spend, savings and YTD totals are double counted.

Where

At commit b50ca38:

  • internal/purchase/execution.go:686-699
  • store_postgres.go:2023-2061

Failure scenario

An execution is re-driven (or a root is retried) after the commitment already exists. The code inserts a second history row for the same purchase instead of skipping it, so dashboards and savings reports count it twice. Found by source reading; not run against Postgres.

Suggested fix

  • Skip the history insert when ExistingCommitment is set.
  • Add a dedupe migration and a unique index on (provider, account_id, purchase_id).
  • Refuse a root retry when completed children exist.

Severity

High: financial totals are wrong, and duplicate rows corrupt data that other features read.

Related: #267 (duplicate purchase_id rows wedging the marketplace listing slot). That issue covers the marketplace-slot symptom; this one covers the insert path that creates the duplicates and the double counted spend.

Reviewer ID: MON-06 (money H6)
Found by the 2026-10-08 review fleet.

Activity

  1. cristim commented on Oct 9, 2026

    @cristim
    MemberAuthor

    Fixed by #776 (merge 57f42e0). Existing duplicate purchase-history rows are untouched; cleaning them up is a pending owner decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions