Skip to content

Add IndexedDB connection recovery, upload retry with exponential backoff, and remove diverged type definitions#27

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-indexeddb-recovery-retry-fix
Draft

Add IndexedDB connection recovery, upload retry with exponential backoff, and remove diverged type definitions#27
Copilot wants to merge 2 commits intomainfrom
copilot/add-indexeddb-recovery-retry-fix

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 12, 2026

Three reliability and maintainability fixes: IndexedDB connections had no recovery path on unexpected closure, transient upload failures were immediately terminal, and stale duplicate type definitions in types/index.ts had diverged from the real types used by the codebase.

IndexedDB connection recovery (IndexedDBService.ts)

  • Attach onclose/onversionchange handlers on the opened IDBDatabase instance to reset this.db = null, so ensureDB() triggers a fresh init() rather than returning a closed, unusable handle.
request.onsuccess = () => {
  this.db = request.result;
  this.db.onclose = () => { this.db = null; };
  this.db.onversionchange = () => { this.db?.close(); this.db = null; };
  resolve();
};

Upload retry with exponential backoff (UploadService.ts)

  • Transient errors (Fetch TypeError, HTTP 5xx, timeout/connection messages) are retried up to 3 times with 2 s → 4 s → 8 s backoff before the asset is marked failed.
  • Insufficient-balance errors remain non-retryable and still pause the queue immediately.
  • Refactored handleUploadError into focused helpers: markAssetFailed, isTransientError, sleep.
  • Retry count is cleared on successful upload to avoid memory leaks.

Remove stale type definitions (types/index.ts)

  • Deleted UserSettings, StorageKeys, ScreenshotCapturedMessage, and UploadProgressMessage — all exported but never imported anywhere.
  • StoredSettings in StorageService.ts is the single authoritative settings type.
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature][High] Add IndexedDB recovery, upload retry with backoff, and fix type divergence</issue_title>
<issue_description>## Summary

Three high-priority improvements for reliability, data integrity, and code maintainability.


1. IndexedDB Connection Has No Recovery Mechanism

File: src/services/IndexedDBService.ts:42-76

The IndexedDB connection stores a single this.db reference but never handles onclose or onversionchange events. If the browser closes the connection unexpectedly (storage pressure, corruption), all subsequent operations silently fail with "Database not initialized" errors. The ensureDB() method checks this.db for null, but a closed database object is non-null yet unusable.

Fix: Add event handlers to reset this.db = null on unexpected closure:

request.onsuccess = () => {
  this.db = request.result;
  this.db.onclose = () => { this.db = null; };
  this.db.onversionchange = () => { this.db?.close(); this.db = null; };
  resolve();
};

Impact: Prevents silent data loss when IndexedDB connections are interrupted, critical for upload queue persistence.


2. No Automatic Retry With Backoff for Transient Upload Failures

File: src/services/UploadService.ts:220-229

When an upload fails due to a transient error (timeout, 500, connection reset), the asset is immediately marked as failed. The user must manually retry each failed upload. Only "insufficient balance" receives special handling. All other failures — including perfectly retryable network blips — are treated as terminal.

Fix: Track retryCount per asset. Auto-retry transient failures (network errors, 5xx, timeouts) up to 3 times with exponential backoff (2s/4s/8s). Only mark as failed after exhausting retries.

Impact: Significantly reduces failed uploads from transient network issues, improving reliability without manual intervention.


3. Duplicate Type Definitions Are Diverging

Files:

  • src/types/index.ts:46-53UserSettings (6 fields)
  • src/services/StorageService.ts:18-34StoredSettings (14 fields)

Two parallel settings type definitions have diverged. UserSettings in types/index.ts is exported but never imported anywhere. Similarly, StorageKeys, ScreenshotCapturedMessage, and UploadProgressMessage in types/index.ts are exported but unused. A developer referencing types/index.ts would use stale, incorrect types.

Fix: Remove unused types from types/index.ts (UserSettings, StorageKeys, ScreenshotCapturedMessage, UploadProgressMessage). Make StoredSettings from StorageService.ts the single source of truth.

Impact: Eliminates confusion from stale types, reducing bugs from type mismatches.

Generated by Health Monitor with Omni</issue_description>

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


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…gence

Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot AI changed the title [WIP] [Feature][High] Add IndexedDB recovery and upload retry with backoff Add IndexedDB connection recovery, upload retry with exponential backoff, and remove diverged type definitions Mar 12, 2026
Copilot AI requested a review from numbers-official March 12, 2026 18:18
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.

[Feature][High] Add IndexedDB recovery, upload retry with backoff, and fix type divergence

2 participants