Skip to content

fix: confirm ratio drop alert - #1522

Open
AbhishekChorotiya wants to merge 4 commits into
mainfrom
fix/confirm_ratio_drop_alert
Open

fix: confirm ratio drop alert#1522
AbhishekChorotiya wants to merge 4 commits into
mainfrom
fix/confirm_ratio_drop_alert

Conversation

@AbhishekChorotiya

@AbhishekChorotiya AbhishekChorotiya commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Fixes #1521

The CONFIRM_CALL log event was not being reliably sent to the logging server. On Safari it was never sent, and on other browsers it was intermittently missing.

Root Cause

inside sendLogsOverNetwork(), sendCachedLogsFromIDB() was being await-ed before beaconApiCall(mainLogFile):

let sendLogsOverNetwork = async () => {
  try {
    await sendCachedLogsFromIDB()  // <-- Blocking!
    beaconApiCall(mainLogFile)      // <-- Never reached in time
    clearLogFile(mainLogFile)
  } catch {
  | _ => ()
  }
}

The sequence of events that causes the issue:

  1. Payment response → SDK logs the CONFIRM_CALL event (a priority event).
  2. Since it's a priority event, sendLogsOverNetwork() is called immediately (not deferred).
  3. sendLogsOverNetwork() first awaits sendCachedLogsFromIDB(), which reads cached logs from IndexedDB, sends them via beacon, and then clears IDB — all of which is async and slow.
  4. Only after that IDB operation completes does beaconApiCall(mainLogFile) execute to send the current log batch (containing CONFIRM_CALL).
  5. Meanwhile, the merchant receives the payment response and immediately unmounts the SDK, re-initializing with a new clientSecret.
  6. The sdk context is destroyed before beaconApiCall ever runs.

Why Safari is worst affected: Safari's IndexedD is particularly slow. The await on sendCachedLogsFromIDB() takes so long that the context is always destroyed before beaconApiCall executes. On Chrome/Firefox, IndexedDB is faster, so it sometimes completes in time — but it's still a race condition.

Fix

Removed the await on sendCachedLogsFromIDB() so it runs as fire-and-forget. beaconApiCall(mainLogFile) now executes immediately without being blocked by the IDB operation:

let sendLogsOverNetwork = async () => {
  try {
    sendCachedLogsFromIDB()->ignore  // Fire-and-forget: don't block the priority beacon
    beaconApiCall(mainLogFile)        // Executes immediately now
    clearLogFile(mainLogFile)
  } catch {
  | _ => ()
  }
}

Since navigator.sendBeacon is designed for reliable delivery during page unload (fire-and-forget at the browser level), the CONFIRM_CALL log is now always sent regardless of IDB latency or how quickly the merchant unmounts the SDK. The cached IDB logs are still sent — just concurrently instead of sequentially.

How did you test it?

  • Verified that CONFIRM_CALL log events are now sent reliably on Safari when the SDK is unmounted immediately after payment response
  • Verified that CONFIRM_CALL log events are sent reliably on Chromeeven with rapid SDK unmount/re-initialize cycles

Checklist

  • I ran npm run re:build
  • I reviewed submitted code
  • I added unit tests for my changes where possible

@semanticdiff-com

Copy link
Copy Markdown

Review changes with  SemanticDiff

@AbhishekChorotiya AbhishekChorotiya changed the title fix: CONFIRM_CALL log missing for Safari and intermittently for other browsers fix: confirm ratio drop alert Apr 29, 2026
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.

Confirm ratio drop alert

4 participants