Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
7e25d97
chore: ignore woocommerce reference tree; add commerce planning docs
vidarbrekke Apr 2, 2026
a04f1f0
docs: add third-party review brief; ignore zip archives
vidarbrekke Apr 2, 2026
6883f3c
arch: incorporate 3rd-party review — state machines, layer model, err…
vidarbrekke Apr 2, 2026
188d474
feat(commerce): scaffold kernel with idempotent finalize decision + t…
vidarbrekke Apr 2, 2026
23991c8
chore: lockfile for plugin-commerce devDependencies
vidarbrekke Apr 2, 2026
86f01c2
arch(commerce): robustness & scale — §20, composite webhook keys, ker…
vidarbrekke Apr 2, 2026
0c58ff7
docs(commerce): §21 platform alignment — EmDash sandbox, Workers bind…
vidarbrekke Apr 2, 2026
887640b
docs: add merchant one-pager comparing Commerce cart vs x402
vidarbrekke Apr 2, 2026
b5fe4fa
docs: third-party review packet v2 (3rdpary_review_2.md)
vidarbrekke Apr 2, 2026
902db2c
Docs: finalize commerce handover and review alignment
vidarbrekke Apr 2, 2026
c66de68
chore(commerce): align kernel error and finalize contract
vidarbrekke Apr 2, 2026
4125de6
commerce: formalize internal vs wire error codes (Option A)
vidarbrekke Apr 2, 2026
9dc5504
commerce: add route error adapter and rate-limit guardrails
vidarbrekke Apr 2, 2026
bfd8ab6
chore: tighten finalize semantics and enforce stage-1 handover flow
vidarbrekke Apr 2, 2026
cc502af
feat(commerce): storage schemas, checkout route, idempotent finalize
vidarbrekke Apr 2, 2026
5c2d338
docs: add third-party review packet (v4)
vidarbrekke Apr 2, 2026
6ca5547
feat(commerce): checkout/finalize slice and AI extensibility contracts
vidarbrekke Apr 2, 2026
a1d95fe
refactor(commerce): harden webhook finalize path for deterministic id…
vidarbrekke Apr 2, 2026
3590d29
docs(commerce): add third-party evaluation path and review checklist
vidarbrekke Apr 2, 2026
a5c3389
docs(commerce): add one-page third-party review checklist
vidarbrekke Apr 2, 2026
e3df0b9
docs(commerce): add reviewer onboarding guide for third-party evaluation
vidarbrekke Apr 2, 2026
ebf2744
docs(commerce): add explicit file-sharing list for third-party reviewer
vidarbrekke Apr 2, 2026
e24c5df
docs(commerce): provide comprehensive single-file third-party review …
vidarbrekke Apr 2, 2026
473d5b0
fix(commerce): resumable finalize, checkout idempotency tests, invent…
vidarbrekke Apr 3, 2026
d7b2bdf
docs(commerce): add paid-stock runbooks and docs index
vidarbrekke Apr 3, 2026
632c4eb
refactor(commerce): extract typed replay and finalize decision flows
vidarbrekke Apr 3, 2026
159dc0f
fix(commerce): restore idempotent inventory replay compatibility
vidarbrekke Apr 3, 2026
8f2c52b
fix(commerce): harden partial-failure edges per external review
vidarbrekke Apr 3, 2026
6c4725d
docs: refresh handover for next-phase developer takeover
vidarbrekke Apr 3, 2026
c963d8b
docs: update handover archive metadata for latest release
vidarbrekke Apr 3, 2026
747f24d
docs: include external review handoff notes in repo
vidarbrekke Apr 3, 2026
2674481
docs: rewrite handover as concise technical onboarding for next phase
vidarbrekke Apr 3, 2026
570bbfe
chore: harden webhook body checks and finalize telemetry
vidarbrekke Apr 3, 2026
826c79a
chore: make finalize telemetry and failure semantics explicit
vidarbrekke Apr 3, 2026
da23a64
chore: append core lock-down policy to handover
vidarbrekke Apr 3, 2026
0748995
feat(commerce): add checkout/get-order for SSR; disable recommendations
vidarbrekke Apr 3, 2026
b33a06d
feat(commerce): add cart upsert/get MVP routes
vidarbrekke Apr 3, 2026
f8898e1
feat(commerce): migrate legacy carts and share line-item validation
vidarbrekke Apr 3, 2026
8a5061b
chore(commerce): fix lint issues in line-item and error tests
vidarbrekke Apr 3, 2026
1710f98
feat(commerce): require possession tokens for cart read and order read
vidarbrekke Apr 3, 2026
b94c600
docs: add EmDash plugin developer handoff (best-practices)
vidarbrekke Apr 3, 2026
d5c432c
feat(commerce): require ownerToken at checkout; unify plugin storage …
vidarbrekke Apr 3, 2026
f1de179
Refine commerce plugin API semantics and portability
vidarbrekke Apr 3, 2026
acb909e
chore(commerce): codify extension seams and kernel boundaries
vidarbrekke Apr 3, 2026
4289826
fix(commerce): resolve webhook seam boundary and test id assumptions
vidarbrekke Apr 3, 2026
9a30b2f
Finalize review package cleanup and receipt state audit
vidarbrekke Apr 3, 2026
a236a21
Tighten external review packet and protect finalize stress edge
vidarbrekke Apr 3, 2026
92475f9
Quarantine Node crypto shim and trim external review bundle
vidarbrekke Apr 3, 2026
0723536
Rewrite HANDOVER for next-phase developer onboarding
vidarbrekke Apr 3, 2026
ece9ef3
feat(commerce): add option B diagnostics guardrails and finalization …
vidarbrekke Apr 3, 2026
7f6dbf6
Add one-line reviewer entrypoint map to canonical docs
vidarbrekke Apr 3, 2026
c9f33b9
Complete zero-legacy commerce kernel and review packet harmonization
vidarbrekke Apr 3, 2026
f4cd782
feat(commerce): terminalize inventory finalize and rate-limit identity
vidarbrekke Apr 3, 2026
0434c7b
test(commerce): use raw finalize token in terminal replay coverage
vidarbrekke Apr 3, 2026
4288700
fix(commerce): prefer Array.from for map-to-array in tests
vidarbrekke Apr 3, 2026
84cec6f
chore: update HANDOVER for next-phase extension-focused handoff
vidarbrekke Apr 3, 2026
bda8b75
refactor(commerce): prep provider contract hardening strategy A
vidarbrekke Apr 3, 2026
21e7f8d
chore(reviewer): tighten external review entrypoints
vidarbrekke Apr 3, 2026
7198c82
chore: include share-with-reviewer in review zip
vidarbrekke Apr 4, 2026
d260187
chore: add systematic post-review roadmap for next phase
vidarbrekke Apr 4, 2026
9208ddf
chore: archive external review memo in packet script
vidarbrekke Apr 4, 2026
7a0fac7
docs: consolidate developer handover for next-phase transfer
vidarbrekke Apr 4, 2026
1a53ccc
docs: make HANDOVER the single-source developer handoff
vidarbrekke Apr 4, 2026
fff34d0
feat(commerce): complete Tier 1-2 mitigation hardening
vidarbrekke Apr 4, 2026
2c9ac2b
feat(core): add compareAndSwap storage primitive
vidarbrekke Apr 4, 2026
276eae4
feat(commerce): finalize payment hardening and webhook integrity
vidarbrekke Apr 4, 2026
1e53faa
feat(commerce): add webhook receipt claim metadata fields
vidarbrekke Apr 4, 2026
4d4f40f
feat(commerce): implement deterministic webhook receipt claim transit…
vidarbrekke Apr 4, 2026
1ede7e1
feat(commerce): protect finalize pipeline with active claim checks
vidarbrekke Apr 4, 2026
ce8ad35
feat(commerce): gate claim lease checks behind rollout flag
vidarbrekke Apr 4, 2026
12cceac
feat(commerce): complete COMMERCE_USE_LEASED_FINALIZE rollout documen…
vidarbrekke Apr 4, 2026
8609bb7
test(commerce): lock strict-mode malformed lease replay
vidarbrekke Apr 4, 2026
a61b1f4
docs(commerce): add AI roadmap PR-ready ticket stubs
vidarbrekke Apr 4, 2026
557a841
fix(commerce): validate pending checkout rows before replay promotion
vidarbrekke Apr 4, 2026
5d43b60
docs(commerce): update handover for strict replay checks
vidarbrekke Apr 4, 2026
e0a7684
docs(commerce): reflect handover commit metadata update
vidarbrekke Apr 4, 2026
43e7689
fix(commerce): coalesce duplicate in-process webhook deliveries
vidarbrekke Apr 4, 2026
24d9670
feat: add catalog foundation update and state endpoints
vidarbrekke Apr 4, 2026
a3f0a73
feat: add catalog asset routes, schemas, and tests
vidarbrekke Apr 4, 2026
9672268
Phase 3 variable product model implementation and plan progress
vidarbrekke Apr 4, 2026
bb833d5
Phase 4 add digital asset and entitlement catalog model
vidarbrekke Apr 4, 2026
1a312f2
Update catalog phase plan progress
vidarbrekke Apr 4, 2026
f2140c8
Add checkout-time catalog snapshots for immutable order history.
vidarbrekke Apr 4, 2026
b101fe4
Make bundle checkout use component stock and finalize accordingly
vidarbrekke Apr 5, 2026
abb1d36
Refactor commerce catalog and finalize paths for stricter typing.
vidarbrekke Apr 5, 2026
4d7ef01
Stabilize bundle component position normalization.
vidarbrekke Apr 5, 2026
181e628
fix: stabilize catalog inventory source-of-truth sync
vidarbrekke Apr 5, 2026
18e7dcb
enforce simple product single-SKU invariant
vidarbrekke Apr 5, 2026
38a8d09
docs: include handover and review notes for handoff
vidarbrekke Apr 5, 2026
0b525f9
refactor catalog ordered child mutation helpers
vidarbrekke Apr 5, 2026
2ee341f
consolidate ordered bundle component normalization
vidarbrekke Apr 5, 2026
ba32a40
refactor catalog read assembly via shared metadata loader
vidarbrekke Apr 5, 2026
6466f7f
add product read-path parity regression test
vidarbrekke Apr 5, 2026
2381def
Optimize commerce catalog read-path batching
vidarbrekke Apr 5, 2026
7cdd4ce
Extract inventory stock doc id helper to shared library
vidarbrekke Apr 5, 2026
3c1262f
Fix catalog batching helper for stable test compatibility
vidarbrekke Apr 6, 2026
d6ea9f4
Update handover for current commerce development state
vidarbrekke Apr 6, 2026
2eda436
chore: disable GitHub Actions auto triggers temporarily
vidarbrekke Apr 6, 2026
f239ebe
chore: finalize commerce ordered-child refactor and tests
vidarbrekke Apr 6, 2026
d5b614d
docs: fix external review packet references
vidarbrekke Apr 6, 2026
ab065b3
chore: extract ordered-row helpers into neutral commerce lib
vidarbrekke Apr 6, 2026
7d71972
chore: optimize variable SKU validation query pattern
vidarbrekke Apr 6, 2026
cc233e6
chore: improve catalog error precision and timestamp consistency
vidarbrekke Apr 6, 2026
97d8df2
chore: archive legacy strict-lease rollout artifacts
vidarbrekke Apr 6, 2026
46040ed
refactor: remove catalog handler shim modules
vidarbrekke Apr 6, 2026
d475437
refactor: extract catalog read-model helpers
vidarbrekke Apr 6, 2026
3800668
refactor: delegate catalog asset handlers to module
vidarbrekke Apr 6, 2026
3a8da76
refactor: extract bundle and digital handlers
vidarbrekke Apr 6, 2026
b7f77cc
refactor: extract catalog category/tag association handlers
vidarbrekke Apr 6, 2026
fd624ee
refactor(commerce): split catalog handlers and share conflict helpers
vidarbrekke Apr 6, 2026
c36f7eb
chore: tighten type safety across commerce and adapters
vidarbrekke Apr 6, 2026
4a0d9f3
style: format
emdashbot[bot] Apr 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions .github/workflows/bonk.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
name: Bonk

on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]

workflow_dispatch:
jobs:
bonk:
if: github.event.sender.type != 'Bot'
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

workflow_dispatch:
permissions:
contents: read

Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/cla.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: "CLA Assistant"
on:
issue_comment:
types: [created]
pull_request_target:
types: [opened, synchronize]
merge_group:

workflow_dispatch:
permissions:
actions: write
contents: write
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/deploy-marketplace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ name: Seed Marketplace Plugins

on:
workflow_dispatch:
push:
branches: [main]
paths:
- "packages/plugins/**"
- ".github/workflows/deploy-marketplace.yml"

permissions:
contents: read

Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
name: Format

on:
push:
branches: [main]
pull_request:
branches: [main]

workflow_dispatch:
permissions:
contents: read

Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/preview-releases.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
name: Preview Releases

on:
push:
branches: [main]
pull_request:
branches: [main]

workflow_dispatch:
permissions: {}

concurrency:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Release

on:
push:
branches:
- main

workflow_dispatch:
concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ __screenshots__/
.emdash-bundle-tmp

# Downloaded test data (fetched on demand in CI)
examples/wp-theme-unit-test/
examples/wp-theme-unit-test/

# Local WooCommerce source copy (reference only; not part of EmDash)
woocommerce/

# Archives (e.g. review bundles); keep local only
*.zip
102 changes: 102 additions & 0 deletions 3rd-party-checklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Third-Party Review Checklist (One-Page)

> This is the historical Option A hardening checklist.
> For the current external reviewer flow, use:
>
> - `@THIRD_PARTY_REVIEW_PACKAGE.md`
> - `external_review.md`
> - `SHARE_WITH_REVIEWER.md`

## Scope and review goal

- Path reviewed: Option A finalize hardening for EmDash Commerce webhooks.
- Primary objective: validate whether the implementation is correct enough for production rollout and identify the smallest safe improvements.
- Owner roles:
- **RE** = Commerce plugin runtime engineer
- **SRE** = platform/storage operator
- **SEC** = security reviewer
- **QA** = QA/automation owner

## Quick pass/fail criteria

1. No finalize side effects occur without valid webhook signature.
2. Duplicate webhook deliveries do not create duplicate inventory side effects.
3. Preflight validation failures do not apply partial stock mutations.
4. Deterministic payment-attempt selection is stable across retries.
5. Remaining concurrency risk is explicitly accepted with an owner and follow-up ticket.

## Issue-level checklist (severity + owner)

### 1) Webhook signature gate is bypassable by malformed request

- **Severity**: P1 (Integrity / Fraud)
- **What to verify**
- `Stripe-Signature` is parsed and validated before finalize side effects.
- Missing/invalid/malformed signatures return `WEBHOOK_SIGNATURE_INVALID`.
- `settings:stripeWebhookSecret` must be required in deployment paths that receive webhooks.
- **Reviewer outcome**
- `[ ]` Pass / `[ ]` Fail / `[ ]` N/A
- **Ownership**: **SEC** (validation), **RE** (fallback/edge-case handling)
- **Notes**
- Current implementation: implemented in `packages/plugins/commerce/src/handlers/webhooks-stripe.ts`.

### 2) Replay safety on duplicate webhook events

- **Severity**: P1 (Data integrity / Inventory)
- **What to verify**
- Duplicate event IDs return replay/error semantics via existing receipt decision path.
- Deterministic movement IDs prevent second write from creating additional ledger rows.
- Duplicate deliveries do not produce negative stock totals.
- **Reviewer outcome**
- `[ ]` Pass / `[ ]` Fail / `[ ]` N/A
- **Ownership**: **RE** (logic), **SRE** (runtime contention observations)

### 3) Partial mutation risk during preflight failures

- **Severity**: P1 (Inventory correctness)
- **What to verify**
- Stock validation and normalization occur before stock/ledger writes.
- Preflight failures return conflict/invalid-stock errors and preserve current stock.
- Ledger has no row written when any validation fails.
- **Reviewer outcome**
- `[ ]` Pass / `[ ]` Fail / `[ ]` N/A
- **Ownership**: **RE**

### 4) Nondeterministic payment-attempt selection

- **Severity**: P2 (State correctness)
- **What to verify**
- Selection uses deterministic filter/sort (`orderId + providerId + status`, ordered by stable field).
- Tests cover multiple pending attempts and earliest selection.
- **Reviewer outcome**
- `[ ]` Pass / `[ ]` Fail / `[ ]` N/A
- **Ownership**: **RE**

### 5) Inventory movement index / replay model mismatch

- **Severity**: P2 (Idempotency)
- **What to verify**
- Unique index definition for movement identity exists in `storage.ts`.
- No migration gap for existing deployments where index is required for full guarantee.
- **Reviewer outcome**
- `[ ]` Pass / `[ ]` Fail / `[ ]` N/A
- **Ownership**: **SRE** + **RE**

### 6) Residual concurrent-race window under perfect simultaneity

- **Severity**: P2 (Concurrency / Scaling)
- **What to verify**
- Confirm if remaining race window is acceptable for current traffic profile.
- Confirm follow-up plan if stronger guarantees are required (CAS/claim primitive).
- **Reviewer outcome**
- `[ ]` Accept as-is / `[ ]` Requires follow-up / `[ ]` N/A
- **Ownership**: **RE** (design), **SRE** (capacity/risk)

## Final recommendation block

- **Recommended rollout readiness**: `[ ] Ready` / `[ ] Hold until fixes` / `[ ] Require follow-up`
- **Owner**: `_____________________`
- **Review comments summary**:
- ***
- ***
- ***
13 changes: 13 additions & 0 deletions 3rdparty_share_index_4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 3rd Party Share Index (v4)

## Status

This index is historical and refers to an earlier review zip layout.

## Canonical review path

- `external_review.md` (current canonical review packet)
- `@THIRD_PARTY_REVIEW_PACKAGE.md` (authoritative entrypoint)
- `SHARE_WITH_REVIEWER.md` (single-file handoff instructions)

Use this file only for artifact history; current review work should follow the canonical packet chain above.
168 changes: 168 additions & 0 deletions 3rdpary_review-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Third-Party Evaluation Brief — Commerce Finalize Hardening (Option A execution)

> Historical review packet (Option A). Canonical current entrypoint is:
>
> - `@THIRD_PARTY_REVIEW_PACKAGE.md`
> - `external_review.md`
> - `SHARE_WITH_REVIEWER.md`

## Executive summary

This review package covers the Option A hardening pass for the EmDash Commerce plugin, focused on webhook-driven payment finalize integrity.
The current implementation improves reliability of the `stripe` webhook finalize path by making side effects deterministic, adding signature validation, and making inventory mutation behavior safer under duplicate/malformed flows.

The guiding constraint is still your original brief:

- keep changes narrow
- avoid over-engineering
- prioritize correctness over speculative features
- remain review-friendly for external audit before moving to Stage 2

## Ecosystem context (what this code lives in)

- `packages/plugins/commerce` is a plugin package in a pnpm monorepo.
- Runtime writes are performed through EmDash plugin storage abstractions (`ctx.storage` + `StorageCollection`).
- Public plugin routes are defined in `packages/plugins/commerce/src/index.ts`.
- Route handlers are currently thin wrappers that call orchestration modules and throw API errors through existing error contracts.
- Checkout and finalize flows intentionally stay isolated from storefront/catalog concerns and do not couple recommendation/agent read paths.

## Why this pass was needed

Three categories of risk were addressed:

1. **Security/inbound trust**
- Webhook traffic was entering finalize logic without cryptographic proof, creating an integrity risk.
2. **Correctness under duplicates and retries**
- `webhookReceipts` and deterministic identifiers reduce duplicate side effects but pre-existing write patterns could still expose partial mutation windows.
3. **Determinism/state consistency**
- Payment attempt updates could vary based on storage ordering, and partial stock/ledger writes were possible during failures.

## Files changed in this implementation pass

### Core logic

- `packages/plugins/commerce/src/orchestration/finalize-payment.ts`
- Added deterministic inventory preflight + normalization path:
- validate required stock rows and line-item consistency before writes.
- convert intended stock adjustments into deterministic movement plans.
- Added deterministic ledger IDs via `inventoryLedgerEntryId(...)`.
- Added idempotent replay-safe mutation path by skipping already-written movement IDs.
- Kept payment conflict/error mapping deterministic and explicit.

- `packages/plugins/commerce/src/handlers/webhooks-stripe.ts`
- Added webhook signature verification:
- parses `Stripe-Signature`
- validates timestamp tolerance
- validates HMAC (`whsec` style hex signature) using settings secret
- rejects invalid/missing signature before finalize execution.
- exposes helper exports for focused unit tests.

### Guardrails / schema tightening

- `packages/plugins/commerce/src/storage.ts`
- Added unique index for deterministic inventory movement replay safety:
- `inventoryLedger`: `["referenceType","referenceId","productId","variantId"]`

- `packages/plugins/commerce/src/handlers/checkout.ts`
- Added stronger input checks to reject malformed line items (`quantity`, `inventoryVersion`, `unitPriceMinor`) before order creation.

### Tests added/updated

- `packages/plugins/commerce/src/orchestration/finalize-payment.test.ts`
- Added scenarios:
- earliest-pending provider attempt is chosen deterministically
- duplicate SKU merge still yields one ledger movement
- preflight failure leaves stock/ledger unchanged (partial-write prevention)
- In-memory storage mock now supports `orderBy` for deterministic pending-attempt behavior.

- `packages/plugins/commerce/src/handlers/webhooks-stripe.test.ts` _(new)_
- Added signature helper unit coverage:
- parse format
- valid v1 signature
- bad secret rejection
- missing timestamp rejection
- stale timestamp rejection

## Known residual risk (explicit)

- Storage currently lacks native CAS/conditional writes or transactional locking in the orchestration contract used here.
- In a perfect simultaneous duplicate webhook delivery race, one delivery can still attempt overlapping writes before first-commit visibility.
- The current design is replay-bounded and recoverable through receipt ledgering and deterministic IDs, but a true CAS/receipt-lock step remains the next hardening milestone if your volume/profile requires stronger isolation.

## Third-party evaluator checklist

### What to validate first

1. Confirm environment configuration includes `settings:stripeWebhookSecret` in all production and staging runtime paths used by webhook ingestion.
2. Verify raw request body consumption remains compatible with EmDash route pipeline in production workers.
3. Confirm storage guarantees around `query` sorting and unique index enforcement on `inventoryLedger`.

### What to validate during review

1. Security
- invalid signatures cannot reach finalize side effects
- malformed / missing signatures fail safely
2. Determinism
- one deterministic attempt is selected across multiple pending attempts
- duplicate SKU merge produces one stock movement row
3. Integrity
- preflight failures produce no stock mutation
- inventory version mismatch and insufficient stock map to stable API errors
4. Idempotency/replay behavior
- duplicate webhook deliveries of same event do not create duplicate stock side effects

### Suggested production rollout checks

1. Deploy to staging with production-like concurrency.
2. Send duplicate/simultaneous webhook deliveries and verify:
- one success, one replay or controlled terminal conflict path
- no negative stock from partial writes
3. Monitor for `commerce.finalize.inventory_failed` and `commerce.finalize.token_rejected` logs.

### Clear review path for a 3rd-party evaluator

1. **Start with context**
- `3rdpary_review-4.md` (this document)
- `COMMERCE_REVIEW_OPTION_A_PLAN.md`
- `COMMERCE_REVIEW_OPTION_A_EXECUTION_NOTES.md`
2. **Inspect runtime contracts**
- `packages/plugins/commerce/src/index.ts`
- `packages/plugins/commerce/src/handlers/webhooks-stripe.ts`
- `packages/plugins/commerce/src/orchestration/finalize-payment.ts`
3. **Inspect constraints and storage model**
- `packages/plugins/commerce/src/storage.ts`
4. **Validate test coverage**
- `packages/plugins/commerce/src/orchestration/finalize-payment.test.ts`
- `packages/plugins/commerce/src/handlers/webhooks-stripe.test.ts`
5. **Validate behavior against this matrix**
- `WEBHOOK_SIGNATURE_INVALID` on bad/missing signatures
- duplicate events produce replay or controlled terminal conflict semantics
- insufficient stock/version mismatch remains non-partial
- deterministic payment attempt selection
- no duplicate movement rows for duplicate SKUs
6. **Finalize decision**
- Confirm residual concurrent-race risk is acceptable for current scale
- Decide whether a stronger CAS/lock path should be phase-2 scope

## Artifacts this review package is optimized for

- Implementation plan and status:
- `COMMERCE_REVIEW_OPTION_A_PLAN.md`
- `COMMERCE_REVIEW_OPTION_A_EXECUTION_NOTES.md`
- `3rdpary_review-4.md` (this document)
- Core implementation/test bundle:
- `packages/plugins/commerce/src/orchestration/finalize-payment.ts`
- `packages/plugins/commerce/src/handlers/webhooks-stripe.ts`
- `packages/plugins/commerce/src/storage.ts`
- `packages/plugins/commerce/src/handlers/checkout.ts`
- `packages/plugins/commerce/src/orchestration/finalize-payment.test.ts`
- `packages/plugins/commerce/src/handlers/webhooks-stripe.test.ts`

## Decision support for 3rd-party suggestions

The current path intentionally avoids broad redesigns (no middleware/framework migration, no new plugin boundaries, no new schema surface area).
If reviewer confirms current delivery profile needs stronger concurrency guarantees, the recommended follow-up should be:

1. introduce a storage-level claim primitive (or explicit lock emulation) for webhook receipts, then
2. fold claim + mutation into one atomic boundary where backend storage allows it,
3. keep current deterministic IDs as a second line of defense for replay safety.
Loading
Loading