Skip to content

feat(Store): auto-heal stale price data stuck in cart - #1022

Merged
jakeaturner merged 1 commit into
stagingfrom
fix/store-price-auto-heal
Nov 5, 2026
Merged

jakeaturner merged 1 commit into
stagingfrom
fix/store-price-auto-heal

Conversation

@jakeaturner

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI balanced review requested due to automatic review settings November 2, 2026 23:05
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Severity: Medium — server/api.js:1404: Removing optionalGetUserAttributes breaks glossary access for support staff and superadmins who are not project members. getBookGlossary() still checks project membership using req.user.roles, which this middleware populates. Restore it so administrators can load the glossary.

The supplied commits have no merge base locally; review used their direct snapshot diff.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A transient price-sync gap can delete a valid persisted cart line, while shipping failures omit reconciliation data and cart merging can overwrite fresh product details with stale data.

3 open issues
What changed in this PR

This PR adds cart reconciliation against the current Stripe catalog to repair stale prices before shipping and checkout.

Changes:

  • Replace archived book prices with matching active variants, remove unavailable items, and merge matching cart lines.
  • Apply reconciliation in the client, recalculate subtotals, and notify customers of price changes or removals.
  • Add helper tests and require customers to review cart changes detected at checkout.
File Description
server/​types/​Store.ts Defines the server reconciliation payload.
server/​api/​store.ts Reconciles shipping requests and rejects stale checkout requests.
server/​api/​services/​store-service.ts Resolves replacement prices and merges reconciled items.
client/​src/​utils/​storeHelpers.ts Applies cart changes and formats customer notices.
client/​src/​utils/​storeHelpers.test.ts Tests reconciliation and notice helpers.
client/​src/​types/​Store.ts Defines client reconciliation and notice types.
client/​src/​screens/​conductor/​store/​shipping.tsx Applies server updates and displays cart notices.
client/​src/​providers/​CartProvider.tsx Updates cart state and recalculates subtotals.
client/​src/​context/​CartContext.ts Exposes the cart reconciliation action.
client/​src/​api.ts Types reconciliation data in shipping responses.

Review effort: Balanced

Comment thread server/api/services/store-service.ts Resolved
Comment thread client/src/utils/storeHelpers.ts Resolved
Comment thread server/api/store.ts Resolved
@jakeaturner
jakeaturner force-pushed the fix/store-price-auto-heal branch from 80943e1 to 47c015c Compare November 5, 2026 18:33
Copilot AI balanced review requested due to automatic review settings November 5, 2026 18:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The error path can change cart lines without clearing the previous shipping quote, leaving stale costs displayed and allowing payment to proceed without a valid quote for the updated cart.

1 open issue
3 resolved since last review

Review effort: Balanced

@jakeaturner
jakeaturner force-pushed the fix/store-price-auto-heal branch from 47c015c to bc53eda Compare November 5, 2026 18:41
Copilot AI balanced review requested due to automatic review settings November 5, 2026 18:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Overlapping syncs can leave variants with no active price, and incomplete price pagination can cause valid products to be permanently removed from carts.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread server/api/services/store-service.ts Resolved
@jakeaturner
jakeaturner force-pushed the fix/store-price-auto-heal branch from bc53eda to e4cad8b Compare November 5, 2026 18:56
Copilot AI balanced review requested due to automatic review settings November 5, 2026 18:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Stripe mutations continue after lease ownership is lost, allowing stale runs to archive prices used by the new holder, while unbounded cart lookups risk exhausting shared Stripe limits.

3 open issues
1 resolved since last review

Review effort: Balanced

Comment thread server/api/services/store-service.ts Resolved
@jakeaturner
jakeaturner force-pushed the fix/store-price-auto-heal branch from e4cad8b to e95c2c2 Compare November 5, 2026 19:11
Copilot AI balanced review requested due to automatic review settings November 5, 2026 19:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical lease-safety gaps allow renewal writes to shorten the stored expiry and release the lease before timed-out Stripe mutations are resolved, enabling overlapping syncs and incorrect price deactivation.

3 open issues
2 resolved since last review

Review effort: Balanced

const sentAt = Date.now();
StoreBookSyncLock.updateOne(
{ _id: { $eq: bookID }, leaseID: { $eq: leaseID } },
{ $set: { lockedUntil: new Date(sentAt + BOOK_SYNC_LOCK_MS) } },
} finally {
clearInterval(heartbeat);
// A failed release costs at most one lease length of waiting for the next run.
await StoreBookSyncLock.deleteOne({ _id: { $eq: bookID }, leaseID: { $eq: leaseID } })
@jakeaturner
jakeaturner merged commit cdbfc80 into staging Nov 5, 2026
10 of 11 checks passed
@jakeaturner
jakeaturner deleted the fix/store-price-auto-heal branch November 5, 2026 19:18
@libretexts-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 2.157.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants