Skip to content

fix(woocommerce): initial import can no longer false-complete + silently disable live sync#430

Merged
OneTwo3D merged 1 commit into
developmentfrom
fix/wc-initial-import-no-false-complete
Jun 26, 2026
Merged

fix(woocommerce): initial import can no longer false-complete + silently disable live sync#430
OneTwo3D merged 1 commit into
developmentfrom
fix/wc-initial-import-no-false-complete

Conversation

@OneTwo3D

Copy link
Copy Markdown
Owner

Problem (found debugging staging order 163295)

The WooCommerce initial order import errored on all 6 orders ("No storefront-synced warehouse available for sale") yet still recorded itself as done / "Import completed" with 0 imported. That left:

  • a dead-end UI ("Import completed · 6 errors") with no way to re-run (only the error state had a Retry button), and
  • live order sync silently gated off (it requires wc_initial_import_completed).

A second bug compounded it: saveSyncSettings rewrote every SYNC_SETTING_KEY present in the payload — including the machine-managed wc_initial_import_completed flag and the sync cursors — so simply saving WC settings could wipe a genuine completion and disable live sync.

Fixes (so this can't happen)

  1. initial-import.ts — new pure decideInitialImportOutcome: a pass that imported/reconciled nothing and had errors → failed (status error, flag NOT set, error toast) so it stays retryable and live sync stays off until a real import succeeds. Any real progress, or genuinely no active orders, → complete (per-order errors surfaced but non-blocking).
  2. wc-sync.ts — exclude MACHINE_MANAGED_SYNC_KEYS (completed flag + sync cursors + webhook timestamps) from saveSyncSettings, so a settings save can't clobber them.
  3. sync-client.tsx — the done state now also shows a "Re-import active orders" button, so a previously-stuck "completed" (including existing data) is always re-runnable.

Verification

3 new unit tests for the decision helper; type-check ✅, eslint ✅, next build ✅, full unit suite 1887 pass / 0 fail.

Note: this is the root-cause fix. The underlying staging issue (storefront warehouses have 0 stock, and the stale cron points at wc-sync not wc-reconcile) is operational config, separate from this code fix.

🤖 Generated with Claude Code

…ently disable live order sync

A WC initial import that errored on every order and imported nothing still marked
itself complete (status 'done' + wc_initial_import_completed='true') — leaving a
dead-end "Import completed" with 0 orders, no retry button (only 'error' state had
one), and live order sync silently gated off. A separate bug compounded it: saving
WC sync settings re-wrote every SYNC_SETTING_KEY including the machine-managed
wc_initial_import_completed flag, so a settings save could wipe a genuine completion
and turn live sync back off.

Three coordinated fixes so this situation cannot happen:
- initial-import: new pure decideInitialImportOutcome — a pass that imported/
  reconciled nothing AND had errors is FAILED (status 'error', flag NOT set, error
  notification), so it stays retryable and live sync stays off until a real import
  succeeds. Any real progress, or no active orders at all, is COMPLETE (partial
  per-order errors are surfaced but don't block).
- wc-sync: exclude MACHINE_MANAGED_SYNC_KEYS (the completed flag + sync cursors +
  webhook timestamps) from saveSyncSettings so a settings save can't clobber them.
- sync UI: the 'done' state now also offers a "Re-import active orders" button, so a
  previously-stuck "completed" (incl. existing data) is always re-runnable.

Tests: decideInitialImportOutcome (0-imported+errors → failed; no-orders → complete;
partial/clean → complete). type-check, eslint, next build, full unit suite (1887
pass / 0 fail) all green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@OneTwo3D OneTwo3D merged commit d12fab7 into development Jun 26, 2026
10 checks passed
@OneTwo3D OneTwo3D deleted the fix/wc-initial-import-no-false-complete branch June 26, 2026 22:06

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93a20848e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// retry. Surface it as an error so the UI shows Retry and live order sync
// stays gated off until a real import succeeds.
progress.status = 'error'
progress.message = `Import failed \u2014 0 of ${progress.totalOrders} order${progress.totalOrders === 1 ? '' : 's'} imported (${progress.errors.length} error${progress.errors.length === 1 ? '' : 's'}). Resolve the cause and retry; live order sync stays off until the initial import succeeds.`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Ensure failed imports retry partial orders

When this failed path is hit for the reported warehouse-allocation error, importWcOrder may already have created the SalesOrder and WooCommerce shopping link before returning success: false after auto-allocation throws. On the next retry, runInitialImport preloads shoppingOrderLink ids and skips those same orders, so the retry can mark the import complete without ever re-running allocation or repairing the partially imported orders. This leaves the affected active orders in the broken state while unlocking live sync; the failure path needs to roll back/clean up partial links or make retries process those existing linked orders.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant