fix(woocommerce): initial import can no longer false-complete + silently disable live sync#430
Conversation
…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>
There was a problem hiding this comment.
💡 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.` |
There was a problem hiding this comment.
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 👍 / 👎.
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:errorstate had a Retry button), andwc_initial_import_completed).A second bug compounded it:
saveSyncSettingsrewrote everySYNC_SETTING_KEYpresent in the payload — including the machine-managedwc_initial_import_completedflag and the sync cursors — so simply saving WC settings could wipe a genuine completion and disable live sync.Fixes (so this can't happen)
initial-import.ts— new puredecideInitialImportOutcome: a pass that imported/reconciled nothing and had errors →failed(statuserror, 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).wc-sync.ts— excludeMACHINE_MANAGED_SYNC_KEYS(completed flag + sync cursors + webhook timestamps) fromsaveSyncSettings, so a settings save can't clobber them.sync-client.tsx— thedonestate 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.🤖 Generated with Claude Code