Skip to content

fix: prevent storage quota errors during event logging#1287

Open
khushi1033 wants to merge 4 commits into
developmentfrom
fix/storage-quota-event-logging
Open

fix: prevent storage quota errors during event logging#1287
khushi1033 wants to merge 4 commits into
developmentfrom
fix/storage-quota-event-logging

Conversation

@khushi1033

Copy link
Copy Markdown
Contributor

Background

  • Partner error logs showed QuotaExceededError surfacing from the synchronous commerce event path, including eCommerce.logImpression.
  • The SDK had unguarded Web Storage writes in persistence and vault storage paths, so localStorage/sessionStorage quota or blocked-storage failures could escape event logging.

What Has Changed

  • Makes vault storage best-effort by catching Web Storage read/write/remove failures and returning a boolean write result.
  • Guards savePersistence() localStorage writes so quota failures are logged without throwing.
  • Adds offline batch queue trimming that drops the oldest batches until localStorage accepts the payload. If no batch can be stored (storage blocked or a single batch exceeds quota), batches are retained in memory for retry rather than dropped.
  • Adds regression tests for vault write failures, persistence write failures, and offline batch trimming/retention behavior.

Verification

  • npm run build:iife
  • npm run build:test-bundle
  • npm run test:jest
  • npx karma start test/karma.config.js --browsers ChromeHeadless --single-run

Screenshots/Video

  • {Include any screenshots or video demonstrating the new feature or fix, if applicable}

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

  • {Any additional information or context relevant to this PR}

Reference Issue (For employees only. Ignore if you are an outside contributor)

@khushi1033 khushi1033 marked this pull request as ready for review June 26, 2026 17:55
@khushi1033 khushi1033 requested a review from a team as a code owner June 26, 2026 17:55
@cursor

cursor Bot commented Jun 26, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes core offline event/batch persistence and can drop oldest batches under quota; behavior is intentional but affects data retention during storage pressure.

Overview
Stops QuotaExceededError and other Web Storage failures from bubbling into synchronous event paths (e.g. commerce logging) by making persistence and vault writes best-effort instead of throwing.

Vault (vault.ts)store() now returns a StorageResult (Success, QuotaExceeded, Unavailable) after catching setItem failures; retrieve() and purge() are wrapped in try/catch so corrupt or blocked storage yields null instead of exceptions.

Batch uploader — Offline event/batch loads use retrieve() ?? [] so null/corrupt session or local storage does not break spreads. Failed-upload batch persistence goes through storeBatchesQueuedForProcessing(), which trims oldest batches on quota until a write succeeds, logs warnings when batches are dropped, and keeps batches in memory when storage is unavailable or even a single batch cannot fit.

PersistencesavePersistence() wraps localStorage.setItem in try/catch and logs errors without throwing.

Regression tests cover vault outcomes, persistence save failures, and offline batch trim/retain/null-retrieve behavior.

Reviewed by Cursor Bugbot for commit 23b01ea. Bugbot is set up for automated code reviews on this repo. Configure here.

@alexs-mparticle alexs-mparticle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few notes toward making the storage paths purer — mostly separating decisions from side effects and consolidating the quota handling. Suggestions inline.

Comment thread src/vault.ts Outdated
Comment thread src/batchUploader.ts
Comment thread src/vault.ts

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit fdbe5d6. Configure here.

Comment thread src/batchUploader.ts
Comment thread src/batchUploader.ts
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
17.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

3 participants