This repository was archived by the owner on Nov 24, 2026. It is now read-only.
Repository navigation
Conversation
mhsnook
force-pushed
the
claude/optimistic-settle-layer
branch
from
June 27, 2026 10:10
384b34d to
46e7cc3
Compare
mhsnook
force-pushed
the
claude/optimistic-settle-layer
branch
from
June 27, 2026 14:20
46e7cc3 to
2ee020f
Compare
Adds an additive 'acknowledged' milestone between optimistic and synced, so UIs can respond when the server accepts a write (the acknowledgement) without waiting for it to sync back. Core (@tanstack/db): - Transaction.acknowledge() + Transaction.isAcknowledged. acknowledge() is a no-op-safe setter a collection adapter calls when the server confirms a write. isAcknowledged resolves at the acknowledgement, or together with isPersisted when no adapter calls it, and rejects on failure — always safe to await and never later than isPersisted. isPersisted/$synced semantics and the optimistic overlay are unchanged. - New $acknowledged virtual property (true once acknowledged, always true when $synced). Wired through row enrichment, the virtual-prop cache, group-by aggregation, and emitted as a virtual-prop-only update when it flips mid-flight. Adapter (@tanstack/electric-db-collection): - wrapped insert/update/delete handlers call transaction.acknowledge() after the server responds, before awaiting the txid. One line each; non-breaking. Includes docs/proposals/acknowledged-and-settled.md and tests. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_012VvSGi4YvJ5cYtJosqXkMe
mhsnook
force-pushed
the
claude/optimistic-settle-layer
branch
from
June 27, 2026 14:41
2ee020f to
42d13dd
Compare
mhsnook
force-pushed
the
claude/optimistic-settle-layer
branch
from
June 27, 2026 16:59
42d13dd to
a06eec1
Compare
Builds on the acknowledge layer with the fuller shape, doing surgery on only one existing name. Core (@tanstack/db): - Transaction.settleWith(fn) + Transaction.isSettled. settleWith lets an adapter return the handler at the acknowledgement and hand the sync wait (e.g. awaiting a txid) to the framework, which keeps the transaction 'persisting' so the optimistic overlay is held — no stale-drop, no flicker — until the thunk resolves, then settles. - isPersisted is soft-deprecated in favour of isSettled (kept as an exact alias). This is the only existing name that changes; $synced and all sync/settle words are untouched. No new lifecycle-callback surface is added — await tx.isAcknowledged / tx.isSettled for side-effects at either milestone. Adapter (@tanstack/electric-db-collection): - wrapped handlers acknowledge() then settleWith(processMatchingStrategy), returning at the acknowledgement. Real collections settle via commit() exactly as before; isSettled/isPersisted timing is unchanged. Updates the proposal to the full version (keeps $synced, suggests a future $synced->$settled rename without acting on it) and adds transaction-settle.test.ts. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_012VvSGi4YvJ5cYtJosqXkMe
mhsnook
force-pushed
the
claude/optimistic-settle-layer
branch
from
June 27, 2026 18:17
a06eec1 to
cc10233
Compare
When a handler returns without throwing and has registered a settleWith thunk, that return is the acknowledgement. commit() now flips isAcknowledged / $acknowledged before awaiting the settle thunk, instead of leaving both milestones to resolve together at settle time. This makes the no-settleWith and settleWith paths consistent: resolving the handler flips acknowledged (and settled too, unless a settleWith defers the settle milestone to the thunk). Adapters using settleWith no longer need a separate acknowledge() call — the Electric handlers drop theirs accordingly (explicit acknowledge() remains a safe idempotent no-op). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_012JGbK3MVBn1dMn4xnvaWYu
2 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The idea
Same starting point as #2: an optimistic mutation has two confirmations — acknowledged (server accepted the write) and synced (it echoed back through sync, overlay dropped). Today every signal flips only when synced; the acknowledgement is usually what the UI wants.
Where #2 stops at exposing the acknowledgement, this PR also lets a handler return at the ack and hand the responsibility of waiting for the final sync-and-settle to the framework.
What this adds (additive; soft-deprecates one name)
Core —
@tanstack/db:acknowledgedstate for optimistic mutations #2:acknowledge(),isAcknowledged,$acknowledged)Transaction.settleWith(fn): hand the transaction off to a new registry that holds the optimistic overlay open untilsync, allowing us to resolve the handler earlier, and give the acknowledgement to the UI and offloading the responsibility for the optimistic overlay to a framework construct.Transaction.isSettled: new alias forisPersisted(soft deprecated). Matches the language of "settleWith" and avoids confusion for situations where the original acknowledgement indicates persistedness. The framework can't know the exact persistence milestone, only when the request resolves and when the sync comes back. You might also call itisSyncedto match the naming of$syncedvirtual prop state.For side-effects at either milestone (toast, navigation), await
tx.isAcknowledged/tx.isSettled.isPersistedstill exists but is now unclear on which event it refers to.Adapter —
@tanstack/electric-db-collection:(Whether Electric adopts this is up to the Electric/TanStack folks — it's here as because it was a clear demonstration of the easy improvement this enables for maintainers and sync-builders.)
Why it's still non-breaking
settleWithkeeps the txpersistinguntil synced, soisSettled/isPersistedfire at exactly the same moment as today — real collections settle viacommit()unchanged.isPersistedstays a working, exact alias ofisSettled— the deprecation is a JSDoc@deprecated, not a removal.On naming
This PR keeps
$syncedexactly as-is. The only existing name it changes isisPersisted→isSettled(the operationally-defined one). The proposal suggests — but deliberately does not do — a future$synced→$settledrename for full parallelism (the acknowledgement can itself carry synced data, so "synced" is also a little overloaded, in s similar way to isPersisted). That's flagged for maintainers to decide separately; "sync" and "settle" are close enough that this PR ships fine without it.Trade-off vs #2
This PR's approach to decoupling the overlay from the mutation handler lifecycle feels more like the correct shape. The mutation's job is done once it gets back a 200. But it adds more surface and touches
isPersisted. #2 is the conservative alternative: onlyacknowledge()+$acknowledged, nothing renamed.(This one also seems to provide a better surface to solve future edge cases like sync timeout messiness. But that may be speculative.)
Tests
packages/db/tests/transaction-settle.test.ts(new):settleWithreturns the handler at the ack and holds the overlay until the framework step resolves; sync failure rejectsisSettled/isPersistedand rolls back (ack not retracted);isPersistedis an exact alias ofisSettled.acknowledgedstate for optimistic mutations #2 acknowledge tests.Verification:
@tanstack/dbtypechecks clean, builds, full suite 2409 passed / 5 skipped.@tanstack/electric-db-collection463 passed, 13 files (the onlytscerrors are the pre-existingCannot find modulefrom the unbuilt e2e suite, present onmain). Lint: 0 errors.🤖 Generated with Claude Code