Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

IndexedDB writes can fail transiently due to browser-level issues (transaction aborts, timeouts, blocking). Without retries, these failures result in silent data loss.

Changes

Retry Infrastructure

  • Exponential backoff: 3 attempts max with ~1s, ~2s, ~4s delays (±10% jitter, capped at 5s)
  • Error classification: Immediate failure for quota/permission errors; retry for transient failures (aborts, timeouts)
  • Logging: Console output for retry attempts with timing and error details

Database Layer

Wrapped all write operations in database.js with retryOperation():

  • Single/batch encrypted record storage
  • User CRUD operations
  • Metadata updates
  • Migration operations

User Notifications

  • Material-UI Snackbar context for non-retryable errors
  • User-friendly messages: "Storage quota exceeded. Please free up space..." vs generic retry failures

Idempotency

Leverages Dexie's native put()/bulkPut() behavior—same ID updates existing record rather than creating duplicates.

Example

// Before: Direct IndexedDB write (no retry)
await db[storeName].put(record);

// After: Wrapped with retry logic
await retryOperation(
  async () => {
    await db[storeName].put(record);
  },
  `storeUserEncryptedRecord(${storeName}, ${id})`
);

Non-retryable quota errors fail immediately; transient errors retry with backoff. UI remains responsive via setTimeout() for async delays.

Testing

  • 26 unit tests covering error classification, backoff calculation, retry logic
  • 10 integration tests validating retry behavior with mocked Dexie operations
  • Idempotency verified: multiple retries with same ID don't create duplicates
Original prompt

This section details on the original issue you should resolve

<issue_title>Add retry logic for failed IndexedDB writes</issue_title>
<issue_description># Summary
Add best-effort retry logic for failed IndexedDB writes in v2 to reduce data loss from transient errors.

Requirements

  • Wrap write ops with capped exponential backoff (e.g., ~1s, ~2s, ~4s; max 3 attempts).
  • Classify errors: retry transient failures; surface non-retryable (e.g., quota exceeded) immediately with a clear UI message.
  • Keep retries off the main thread; UI remains responsive.
  • Ensure idempotency (no duplicate records on partial retries).
  • Add lightweight logging/metrics for retry attempts and outcomes.

Acceptance Criteria

  • Transient write failures are retried with capped backoff (up to 3 attempts).
  • Non-retryable errors display a clear message (e.g., quota/storage full).
  • No duplicate records created by the retry mechanism.
  • UI stays responsive during retries; no freezes.
  • Basic logs confirm retries and final status.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 7, 2025
Copilot AI and others added 6 commits December 7, 2025 23:57
Co-authored-by: jwaspin <6432180+jwaspin@users.noreply.github.com>
… system

Co-authored-by: jwaspin <6432180+jwaspin@users.noreply.github.com>
Co-authored-by: jwaspin <6432180+jwaspin@users.noreply.github.com>
Co-authored-by: jwaspin <6432180+jwaspin@users.noreply.github.com>
Co-authored-by: jwaspin <6432180+jwaspin@users.noreply.github.com>
Co-authored-by: jwaspin <6432180+jwaspin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add retry logic for failed IndexedDB writes Add retry logic with exponential backoff for IndexedDB write failures Dec 8, 2025
Copilot AI requested a review from jwaspin December 8, 2025 00:20
@jwaspin jwaspin added this to the Version 2.1.0 milestone Dec 8, 2025
@jwaspin jwaspin added the enhancement New feature or request label Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants