Skip to content

fix(pos): keep scheduled order retry attempt - #1488

Merged
khaira777 merged 3 commits into
mainfrom
fm/flocafe-fix-scheduled-order-idempotency
Nov 7, 2026
Merged

khaira777 merged 3 commits into
mainfrom
fm/flocafe-fix-scheduled-order-idempotency

Conversation

@khaira777

@khaira777 khaira777 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1470

Intent

Verify and fix [P1] Preserve unresolved order attempts when scheduling settings fail (frontend/src/app/(dashboard)/pos/page.tsx:1434): when a scheduled order commits on the server but its response is lost, a failed scheduling-setting read or disabling and re-enabling scheduling previously cleared the cart schedule so retry generated a new idempotency key and created a duplicate 201 order.

What Changed

  • Extracted schedule fingerprint matching, store-scoped attempt matching, and schedule preservation helpers into frontend/src/lib/order-attempt.ts (parseStoredAttemptScheduledFor, fingerprintsMatchAcrossScheduleToggle, doesAttemptMatchStore, resolveRetryScheduledFor, and resolveCartScheduledForAfterSettingRead).
  • Updated frontend/src/app/(dashboard)/pos/page.tsx to persist storeId on postpaid and prepaid order attempts, retain a matching unresolved attempt's scheduled_for value and idempotency key across failed or toggled scheduled_orders_enabled reads, and clear stored attempts when the server returns a definitive schedule validation rejection (isDefinitiveScheduleRejection).
  • Added unit coverage in tests/issue-788-order-attempt-storage.test.ts and Playwright E2E coverage in frontend/e2e/scheduled-orders.spec.ts for scheduled order retry idempotency and rejection reconciliation.

Risk Assessment

✅ Low: The change cleanly preserves unresolved scheduled order attempts (both payload scheduled_for and idempotency key) across scheduling-setting read failures and setting toggles, scopes attempts by store to prevent cross-store schedule bleed, retires attempts upon definitive server-side schedule rejection, and adds comprehensive unit and E2E test coverage.

Testing

Ran the targeted order-attempt storage unit suite (npm run test:issue-788-order-attempt-storage), scheduled-orders integration suite (npm run test:scheduled-orders), cart/append retry suite (npm run test:issue-255), and live Chromium Playwright E2E suite (e2e/scheduled-orders.spec.ts), capturing visual screenshots and request/response idempotency traces in the evidence directory; all scenarios passed.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
When a scheduled takeaway order commits on the backend (HTTP 201) but the client loses the response, followed by a failed GET /api/settings/scheduled_orders_enabled read (HTTP 503) and a subsequent re… ✅ pass live ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scenario-1-replayed-scheduled-order.png and ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scheduled-orde…
When a scheduled takeaway order commits on the backend (HTTP 201) but the client loses the response, followed by disabling scheduled_orders_enabled (false) and re-enabling it (true), clicking Place Or… ✅ pass live ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scenario-2-replayed-after-disable-reenable.png and ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/schedul…
Adversarial / definitive rejection recovery: When an uncommitted scheduled order attempt fails before reaching the backend and a retry after disabling scheduled orders receives a definitive rejection… ✅ pass live ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scenario-3-definitive-rejection-409.png, ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scenario-3-fresh-…

Scenario 1 - Lost response banner after scheduled order commit
Scenario 1 - POS state after failed scheduling-setting read (503)
Scenario 1 - Replayed scheduled order (HTTP 200) after scheduling-setting read recovery
Scenario 2 - Replayed scheduled order (HTTP 200) after disabling and re-enabling scheduling
Scenario 3 - Definitive schedule rejection (409 SCHEDULED_ORDERS_DISABLED) retiring uncommitted attempt
Scenario 3 - Subsequent immediate unscheduled order placed with fresh idempotency key (HTTP 201)

Evidence: Captured request/response idempotency trace across all live browser scenarios

{ "scenario1_failed_setting_read_recovery": { "firstCommittedOrderId": 1, "replayedOrderId": 1, "replayStatus": 200, "initialRequest": { "idempotencyKey": "eb71d121-2a9d-419f-81a4-fc3eadfa2dd5", "scheduled_for": "2026-11-07T09:00" }, "replayRequest": { "idempotencyKey": "eb71d121-2a9d-419f-81a4-fc3eadfa2dd5", "scheduled_for": "2026-11-07T09:00" } }, "scenario2_disable_reenable_toggle": { "secondCommittedOrderId": 2, "replayedOrderId": 2, "replayStatus": 200, "initialRequest": { "idempotencyKey": "7b25f83c-8de8-48ae-a1b1-90f1b84840dc", "scheduled_for": "2026-11-07T09:20" }, "replayRequest": { "idempotencyKey": "7b25f83c-8de8-48ae-a1b1-90f1b84840dc", "scheduled_for": "2026-11-07T09:20" } }, "scenario3_definitive_schedule_rejection_retires_attempt": { "rejectedStatus": 409, "rejectedCode": "SCHEDULED_ORDERS_DISABLED", "rejectedOutcome": "not_applied", "initialAttemptKey": "4eb3be40-3da2-4215-8262-a0f12ea94274", "rejectedRetryKey": "4eb3be40-3da2-4215-8262-a0f12ea94274", "subsequentImmediateOrderStatus": 201, "subsequentImmediateOrderId": 3, "subsequentImmediateKey": "7c290bcc-53f3-4040-a770-d221e74afd42" } }

{
  "scenario1_failed_setting_read_recovery": {
    "firstCommittedOrderId": 1,
    "replayedOrderId": 1,
    "replayStatus": 200,
    "initialRequest": {
      "idempotencyKey": "eb71d121-2a9d-419f-81a4-fc3eadfa2dd5",
      "body": {
        "table_id": null,
        "customer_id": null,
        "type": "takeaway",
        "guest_count": 1,
        "scheduled_for": "2026-11-07T09:00",
        "waived_charge_ids": [],
        "opted_in_charge_ids": [],
        "items": [
          {
            "product_id": "e2e-product",
            "variant_id": null,
            "quantity": 1,
            "addons": null,
            "special_instructions": null
          }
        ]
      }
    },
    "replayRequest": {
      "idempotencyKey": "eb71d121-2a9d-419f-81a4-fc3eadfa2dd5",
      "body": {
        "table_id": null,
        "customer_id": null,
        "type": "takeaway",
        "guest_count": 1,
        "scheduled_for": "2026-11-07T09:00",
        "waived_charge_ids": [],
        "opted_in_charge_ids": [],
        "items": [
          {
            "product_id": "e2e-product",
            "variant_id": null,
            "quantity": 1,
            "addons": null,
            "special_instructions": null
          }
        ]
      }
    }
  },
  "scenario2_disable_reenable_toggle": {
    "secondCommittedOrderId": 2,
    "replayedOrderId": 2,
    "replayStatus": 200,
    "initialRequest": {
      "idempotencyKey": "7b25f83c-8de8-48ae-a1b1-90f1b84840dc",
      "body": {
        "table_id": null,
        "customer_id": null,
        "type": "takeaway",
        "guest_count": 1,
        "scheduled_for": "2026-11-07T09:20",
        "waived_charge_ids": [],
        "opted_in_charge_ids": [],
        "items": [
          {
            "product_id": "e2e-product",
            "variant_id": null,
            "quantity": 1,
            "addons": null,
            "special_instructions": null
          }
        ]
      }
    },
    "replayRequest": {
      "idempotencyKey": "7b25f83c-8de8-48ae-a1b1-90f1b84840dc",
      "body": {
        "table_id": null,
        "customer_id": null,
        "type": "takeaway",
        "guest_count": 1,
        "scheduled_for": "2026-11-07T09:20",
        "waived_charge_ids": [],
        "opted_in_charge_ids": [],
        "items": [
          {
            "product_id": "e2e-product",
            "variant_id": null,
            "quantity": 1,
            "addons": null,
            "special_instructions": null
          }
        ]
      }
    }
  },
  "scenario3_definitive_schedule_rejection_retires_attempt": {
    "rejectedStatus": 409,
    "rejectedCode": "SCHEDULED_ORDERS_DISABLED",
    "rejectedOutcome": "not_applied",
    "initialAttemptRequest": {
      "idempotencyKey": "4eb3be40-3da2-4215-8262-a0f12ea94274",
      "body": {
        "table_id": null,
        "customer_id": null,
        "type": "takeaway",
        "guest_count": 1,
        "scheduled_for": "2026-11-07T09:40",
        "waived_charge_ids": [],
        "opted_in_charge_ids": [],
        "items": [
          {
            "product_id": "e2e-product",
            "variant_id": null,
            "quantity": 1,
            "addons": null,
            "special_instructions": null
          }
        ]
      }
    },
    "rejectedRetryRequest": {
      "idempotencyKey": "4eb3be40-3da2-4215-8262-a0f12ea94274",
      "body": {
        "table_id": null,
        "customer_id": null,
        "type": "takeaway",
        "guest_count": 1,
        "scheduled_for": "2026-11-07T09:40",
        "waived_charge_ids": [],
        "opted_in_charge_ids": [],
        "items": [
          {
            "product_id": "e2e-product",
            "variant_id": null,
            "quantity": 1,
            "addons": null,
            "special_instructions": null
          }
        ]
      }
    },
    "subsequentImmediateOrderStatus": 201,
    "subsequentImmediateOrderId": 3,
    "subsequentImmediateRequest": {
      "idempotencyKey": "7c290bcc-53f3-4040-a770-d221e74afd42",
      "body": {
        "table_id": null,
        "customer_id": null,
        "type": "takeaway",
        "guest_count": 1,
        "waived_charge_ids": [],
        "opted_in_charge_ids": [],
        "items": [
          {
            "product_id": "e2e-product",
            "variant_id": null,
            "quantity": 1,
            "addons": null,
            "special_instructions": null
          }
        ]
      }
    }
  }
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
When a scheduled takeaway order commits on the backend (HTTP 201) but the client loses the response, followed by a failed GET /api/settings/scheduled_orders_enabled read (HTTP 503) and a subsequent re… ✅ pass live ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scenario-1-replayed-scheduled-order.png and ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scheduled-orde…
When a scheduled takeaway order commits on the backend (HTTP 201) but the client loses the response, followed by disabling scheduled_orders_enabled (false) and re-enabling it (true), clicking Place Or… ✅ pass live ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scenario-2-replayed-after-disable-reenable.png and ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/schedul…
Adversarial / definitive rejection recovery: When an uncommitted scheduled order attempt fails before reaching the backend and a retry after disabling scheduled orders receives a definitive rejection… ✅ pass live ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scenario-3-definitive-rejection-409.png, ~/.no-mistakes/evidence/01M6SNPYPYX4ES73XQ0X03SY1K/scenario-3-fresh-…
  • npm run test:issue-788-order-attempt-storage
  • npm run test:scheduled-orders
  • npm run test:issue-255
  • cd frontend && npx playwright test e2e/scheduled-orders.spec.ts --config=playwright.config.ts --project=chromium
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Preserve unresolved scheduled order attempts and their scheduled_for payload and idempotency key when reading scheduled_orders_enabled fails and recovers or when scheduling is disabled and re-enabled before reconciliation.

Fixes #1470
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Preserve scheduled order retries across scheduling-setting changes

🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Preserve unresolved scheduled order attempts when scheduling-setting reads fail or scheduling is
 toggled.
• Reuse the original schedule and idempotency key so retries cannot create duplicate orders.
• Add unit and browser coverage for failed reads, toggles, and successful replay.
Diagram

graph TD
  Settings["Settings read"] --> Cart["POS cart"] --> Match{"Matching attempt?"} -->|Yes| Retry["Original payload"] --> API["Orders API"] --> Replay["Existing order"]
  Attempt["Stored attempt"] --> Match
  Match -->|No| Fresh["New attempt"] --> API
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Persist an immutable request snapshot
  • ➕ Retries could send the exact original payload without reconstructing it from cart state.
  • ➖ Requires a broader change to attempt storage and compatibility with existing saved attempts.

Recommendation: Keep the focused fingerprint-and-schedule preservation approach for this fix: it works with existing attempt records and covers both checkout paths. Consider immutable request snapshots if retry payload reconstruction becomes a broader source of failures.

Files changed (4) +645 / -61

Bug fix (2) +207 / -61
page.tsxPreserve matching scheduled attempts throughout POS retries +132/-61

Preserve matching scheduled attempts throughout POS retries

• Keeps a matching unresolved attempt's schedule in the cart when scheduling settings fail or change. Restores its schedule on postpaid and prepaid retries and avoids rejecting that preserved schedule against the current clock.

frontend/src/app/(dashboard)/pos/page.tsx

order-attempt.tsAdd schedule-aware attempt matching and retry helpers +75/-0

Add schedule-aware attempt matching and retry helpers

• Adds helpers to extract and compare stored schedules, resolve retry payload schedules, and synchronize cart schedules after setting reads. Fingerprint matching tolerates a cleared schedule when the rest of the cart still matches.

frontend/src/lib/order-attempt.ts

Tests (2) +438 / -0
scheduled-orders.spec.tsVerify idempotent replay across failed reads and setting toggles +275/-0

Verify idempotent replay across failed reads and setting toggles

• Adds browser scenarios where an order commits but its response is lost. Verifies retries reuse the scheduled payload, idempotency key, and existing order after a failed setting read or a disable-and-reenable sequence.

frontend/e2e/scheduled-orders.spec.ts

issue-788-order-attempt-storage.test.tsCover schedule preservation in stored-attempt logic +163/-0

Cover schedule preservation in stored-attempt logic

• Tests failed and toggled setting reads, schedule-aware fingerprint matching, and retry schedule restoration. Confirms schedules still clear normally when no unresolved attempt remains.

tests/issue-788-order-attempt-storage.test.ts

@qodo-code-review

qodo-code-review Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Rejected retries keep carts stuck ✓ Resolved

Resolving commit: 74699ab

Resolution reason
Added isDefinitiveScheduleRejection/getScheduleRejectionCode/reconcileRejectedScheduledOrderAttempt
helpers in order-attempt.ts. In pos/page.tsx, the postpaid, send-to-payment, and prepaid submit
paths now track attemptedScheduledFor and, on a definitive schedule rejection (status 400/409 with a
schedule code and outcome not_applied), clear the saved attempt and, when scheduling is disabled or
the code is SCHEDULED_ORDERS_DISABLED, turn off scheduled orders and clear the cart's scheduledFor
so the cashier can place an immediate order. Tests cover past-time and disabled-setting rejections,
and an e2e scenario checks that a fresh immediate order gets a new idempotency key after the
rejection. The fix uses a different structure than the suggested prompt (it adds helpers rather than
reconciling inside resolveRetryScheduledFor), but it addresses the same problem across the flows.
Description
resolveRetryScheduledFor restores the saved schedule and the widened fingerprint match keeps
reusing its attempt even after the server definitively rejects that schedule. If the first request
never committed and the time passes or scheduling is disabled, retry returns a validation error;
clearing the cart's schedule still sends the old value, so the cashier cannot place an immediate
order with that cart.


Remediation recommended

2. Failed test cleanup leaves billing changed ✓ Resolved

Resolving commit: 74699ab

Resolution reason
Replaced the suppressed .catch(() => {}) business restore with a Promise.allSettled-based restore
of both business and scheduled_orders_enabled settings, and added assertions that each restoration
response succeeded, so cleanup failures are reported and one failing restore does not prevent the
other.
Description
The new test's finally block suppresses errors from restoring /settings/business and never
checks whether that request succeeded. If restoration fails after the test switches billing to
postpaid, subsequent tests run against the changed billing setting without this test reporting the
cleanup failure.

3. Store switches can import old schedules ✓ Resolved

Resolving commit: 74699ab

Resolution reason
Attempts now persist a storeId (normalizeAttemptStoreId in pos/page.tsx persist helpers).
getPreservedAttemptScheduledFor takes a targetStoreId and only returns a preserved schedule when
doesAttemptMatchStore(postpaidAttempt/prepaidAttempt, targetStoreId, initialStoreIdRef.current) is
true. The setting callback passes currentStoreId into getPreservedAttemptScheduledFor.
resolveCartScheduledForAfterSettingRead in order-attempt.ts also gates the preserved schedule by
store match (storeMatches), so a store-1 schedule is not imported into a store-2 cart. Tests in
issue-788 cover store-1 vs store-2 mismatch and legacy attempts without storeId. The fix is
store-scoped attempt verification, matching the suggested fix's approach of recording and verifying
originating store.
Description
getPreservedAttemptScheduledFor reads attempts by user ID without checking which store created
them, then the setting callback writes a matching attempt's schedule into the shared cart. When a
cashier switches stores with an otherwise matching unscheduled cart, a pending attempt from the
previous store can supply its time even if scheduling is disabled in the newly selected store.

Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #10
  🌐 PR #34
✅ Compliance rules (platform): 5 rules
✅ Cross-repo context — repo relationships
✅ REVIEW.md
Review mode: Auto: ⚖️ Balanced: Downgraded extended -> standard: change is below the extended eligibility bar (hunks 13/18, lines 706/200; both must reach the floor). Router rationale: Idempotency and duplicate-order logic across 13 hunks in several independent paths.

Grey Divider

Tip of the day
💡 Did you know, you can hide the parts of a finding you never read, like the evidence or the agent prompt

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread frontend/src/lib/order-attempt.ts Resolved
Comment thread frontend/e2e/scheduled-orders.spec.ts Resolved
Reconcile definitive schedule rejections (not_applied) by retiring the saved order attempt so cashiers can clear or replace the schedule across postpaid, send-to-payment, and prepaid flows.

Scope saved order attempts to their originating store so switching stores with a matching unscheduled cart does not import the prior store's schedule, while preserving legacy attempts in their origin store.

Assert business settings restoration in the scheduled-orders E2E cleanup.
@khaira777 khaira777 changed the title fix(frontend): preserve unresolved order attempts when scheduling settings fail fix(pos): keep scheduled order retry attempt Nov 7, 2026
@khaira777 khaira777 changed the title fix(pos): keep scheduled order retry attempt fix(pos): preserve unresolved scheduled order attempts across setting reads Nov 7, 2026
@khaira777 khaira777 changed the title fix(pos): preserve unresolved scheduled order attempts across setting reads fix(pos): keep scheduled order retry attempt Nov 7, 2026
@khaira777
khaira777 enabled auto-merge (squash) November 7, 2026 03:27
@khaira777
khaira777 merged commit 034bc1d into main Nov 7, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-fix-scheduled-order-idempotency branch November 7, 2026 03:38
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.

fix(pos): preserve unresolved order attempts when scheduling settings fail

1 participant