Skip to content

Experiment 1: Explicitly commit IndexedDB write transactions - #2853

Merged
stopachka merged 2 commits into
mainfrom
codex/indexeddb-explicit-commit
Aug 10, 2026
Merged

Experiment 1: Explicitly commit IndexedDB write transactions#2853
stopachka merged 2 commits into
mainfrom
codex/indexeddb-explicit-commit

Conversation

@stopachka

@stopachka stopachka commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Problem

If you background a tab in android, sometimes it causes active tabs to freeze

Reason

We open a transaction on IndexedDB when we save pending mutations. If Chrome decides to freeze while the tx is open, all other transactions to IndexedDB will be blocked, waiting for that transaction

Solution

Unfortunately there is no easy way to tell IndexedDB to time out when we are sending a tx.

But one thing we can do is to commit the transaction faster:

We call IDBTransaction.commit() after setItem, multiSet, and removeItem right away.

This lets IDB commit the transaction, before having to send back a "done" result to our callback.

When running tests, this reduced the number of noticed blocks from 4/6 to 1/6

Detailed explainer: https://instant-frozen-tab-idb.stopa.chatgpt.site

Future Work

This still may not be enough. It's still possible that we try to do a very large write (with lots of pending mutations), and just at that moment Android freezes us.

To avoid this, we would have to start saving each transaction as a separate row, so we could start to bound writes to pendingMutations.

This may be a bit more involved, so I wanted to first ship this version, before experimenting with a full on rewrite.

@dwwoelfel @nezaj

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c7273bd0-3f20-4b2d-801e-55c5895ba293

📥 Commits

Reviewing files that changed from the base of the PR and between 647e3aa and a5a460e.

📒 Files selected for processing (1)
  • client/packages/version/src/version.ts

📝 Walkthrough

Walkthrough

IndexedDBStorage now explicitly commits supported write transactions for setItem, multiSet, and removeItem. Tests verify commit calls and stored values. The shared package version changes to v1.0.64.

Changes

IndexedDB transaction commits

Layer / File(s) Summary
Storage transaction handling
client/packages/core/src/IndexedDBStorage.ts, client/packages/core/__tests__/src/utils/PersistedObject.test.ts
Write operations call the optional commit method. Tests verify three commit calls, stored values, and spy cleanup.
Package version update
client/packages/version/src/version.ts
The shared version changes from v1.0.63 to v1.0.64.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: nezaj

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the IndexedDB transaction problem, the explicit commit solution, observed results, and future work.
Title check ✅ Passed The title clearly and concisely describes the primary change: explicit commits for IndexedDB write transactions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Comment @coderabbitai help to get the list of available commands.

@stopachka
stopachka force-pushed the codex/indexeddb-explicit-commit branch from c14e0c0 to 647e3aa Compare August 10, 2026 18:30
@stopachka stopachka changed the title Explicitly commit IndexedDB write transactions [in-progress] Explicitly commit IndexedDB write transactions Aug 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
client/packages/core/__tests__/src/utils/PersistedObject.test.ts (1)

432-439: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert one commit per write helper.

The aggregate assertion at Line 439 does not prove that setItem, multiSet, and removeItem each call commit() once. For example, two calls in one helper and no call in another would still pass. Clear the spy and assert one call after each awaited helper.

Proposed test adjustment
     await idb.setItem('key1', 'value1');
+    expect(commitSpy).toHaveBeenCalledTimes(1);
+    commitSpy.mockClear();

     await idb.multiSet([
       ['key2', 'value2'],
       ['key3', 'value3'],
     ]);
+    expect(commitSpy).toHaveBeenCalledTimes(1);
+    commitSpy.mockClear();

     await idb.removeItem('key3');

-    expect(commitSpy).toHaveBeenCalledTimes(3);
+    expect(commitSpy).toHaveBeenCalledTimes(1);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/packages/core/__tests__/src/utils/PersistedObject.test.ts` around
lines 432 - 439, Update the test around setItem, multiSet, and removeItem to
clear commitSpy before each awaited helper, then assert it was called exactly
once immediately afterward. Remove the aggregate commitSpy assertion so each
write helper’s individual commit behavior is verified.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@client/packages/core/__tests__/src/utils/PersistedObject.test.ts`:
- Around line 432-439: Update the test around setItem, multiSet, and removeItem
to clear commitSpy before each awaited helper, then assert it was called exactly
once immediately afterward. Remove the aggregate commitSpy assertion so each
write helper’s individual commit behavior is verified.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 132c8cb6-2b2c-4189-9f50-8f1f37bc9699

📥 Commits

Reviewing files that changed from the base of the PR and between c14e0c0 and 647e3aa.

📒 Files selected for processing (2)
  • client/packages/core/__tests__/src/utils/PersistedObject.test.ts
  • client/packages/core/src/IndexedDBStorage.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/packages/core/src/IndexedDBStorage.ts

@github-actions

Copy link
Copy Markdown
Contributor

@stopachka stopachka changed the title [in-progress] Explicitly commit IndexedDB write transactions Experiment 1: Explicitly commit IndexedDB write transactions Aug 10, 2026

@dwwoelfel dwwoelfel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool!

@stopachka
stopachka merged commit a679d8b into main Aug 10, 2026
30 checks passed
@stopachka
stopachka deleted the codex/indexeddb-explicit-commit branch August 10, 2026 21:10
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.

2 participants