fix: the Firebase store sorts, notifies, and reorders like the local stores (#359) #372
<!-- codex-pull-request-review-summary -->
<!-- codex-review-state:v1 {"code_review":{"commit_sha":"5ed33a4d2720247fc20a153b5411be0c67e835af","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->
<details>
<summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>
This comment shows the latest Codex review activity on this pull request.
| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-28T05:42:11.101248Z">2026-11-28T05:42:11.101248Z</relative-time> | 5ed33a4 | PR opened |
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
</details>
</details>
<sub><sub>!P2 Badge</sub></sub> Preserve notifications for overlapping bulk writes
When two chunked operations overlap—for example, an import calling bulkAdd while a link sweep calls updateMany—both increment the shared writeDepth; the first completion only decrements it to 1 and therefore emits nothing, while the second completion emits one combined notification. This leaves the first successful caller without its required notification, potentially indefinitely if the other write stalls, and violates the store contract's one-notification-per-write behavior. Serialize these operations or track each top-level write independently instead of treating concurrency as nesting.
AGENTS.md reference: AGENTS.md:L22-L23
Useful? React with 👍 / 👎.
<!-- codex-code-review-finding:v1 -->
<!-- codex-review-receipt:v1 -->
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ed33a4d27
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
</details>
Approved these changes.
Keeping this as-is — it is the contract's own reference behavior. chromeBookmarksStore's mutate, the implementation DESIGN.md cites when it states the rule ("A store write notifies subscribers once, when the whole write is done"), counts a shared mutationDepth and behaves identically under overlap: two concurrent writes produce one notification at the last completion, whether the calls are nested or racing. #359's goal was parity with the local stores, so tracking each write independently here would put Firebase mode ahead of the contract rather than in line with it.
On the two consequences raised: subscribers are never left stale — the notification that does fire is a fresh read of the collection, so it carries both writes' effects (and each caller still gets its own promise resolution). And a stalled write does not hold the channel indefinitely: the Firestore batch rejects on its server timeout, the error path releases the hold and notifies — the same bound mutate has through its error path, which drops external echoes for exactly as long.
If overlapping writes should notify per completion rather than collapsing, that is a stricter reading than the chrome store itself implements, so it belongs as a contract change for both stores in DESIGN.md — glad to file it as an issue if you want it pursued.
<!-- agent-bot-write: ghw_bd37e92d0a0eb180 session=d320085c0c7d bot=trueline-zcode-agent[bot] -->
qwts
trueline-zcode-agent[bot]
Closes #359
Three parity gaps between
firebaseStore.jsand the local stores, all from the same review as #358:Sorting by folder did nothing.
persistSortedOrder()reada[sortBy]directly — the agent plan's key isfolder, the stored field isfolderId— so every value wasundefined, every comparison a tie, and the order never changed. It also comparedcreatedAt/updatedAtas strings. The comparator all three stores had copied is now shared insrc/stores/bookmarkSort.js(folder→folderId, timestamps parsed as instants, rating numeric, strings case-insensitive), and the local stores' copies are deleted; their semantics are unchanged.Bulk writes notified once per 500-operation batch. A 1,200-bookmark import emitted three lists, the first two describing a partial import.
commitInChunks()now holds the snapshot subscription while a write is in flight and notifies once from a fresh read when the last commit lands — including when a batch fails, because earlier chunks may have committed and a listener left on a stale list is the #18 mistake in reverse. This is DESIGN.md's "one write, one notification, whatever its size", kept the waychromeBookmarksStorekeeps it (mutationDepth).Reordering marked the whole library as modified.
reorderBookmarks()stampedupdatedAt: nowonto every document it positioned; the local store's reorder is achrome.bookmarks.movethat touches no metadata. It now writes the position and nothing else.Tests cover #359's acceptance: the 1,200-bookmark import produces exactly one notification; a 600-document
updateManyspanning two batches notifies once with the finished state; a failed chunked write still reports what actually landed; a reorder leavesupdatedAtunchanged; folder and instant date sorts work in Firebase mode; and the same single-folder collection sorted the same way gives the same order throughlocalCompositeStoreandfirebaseStore. (Multi-folder equality is out of scope by design — chrome keeps subfolders where they sit and lists the tree, #43 — so the contract test runs on one flat collection, which is what Firebase mode has.) The SDK double gained a commit-refusal hook so a part-way batch failure is drivable.Docs:
FIREBASE_SETUP.mdgains the position-only reorder, the shared sort semantics, and the single-notification bulk write; changeset included.<!-- agent-bot-write: ghw_4621f2e2561d692a session=d320085c0c7d bot=trueline-zcode-agent[bot] -->