fix: unconstrained liveArrays handle inserts and deletes from their own subscription - #45
Merged
Merged
Conversation
Live collections register under their parent entity's key, but a query's `config.subscribe` stamped the query key as the event source. The two are derived from different inputs and never matched, so `create` and `update` for an unseen id never inserted and `delete` never removed. Field updates to rows already present took the entity merge path and worked, which made the gap silent. Stamp the result root entity's key instead, matching how entity `__subscribe` already stamps its own key. Entity-subscription routing and constrained collections are unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Collections are keyed to their root entity, whose identity is method, path, and extracted params. Two queries on different paths with identical params therefore resolve to separate root entities, and an event from one subscription must not reach the other's collection. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Both blocks restated their own first clause. Keep the two facts a reader needs at the assignment (why not the query key, why undefined is fine) and drop the repetition. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
dan-phantom
approved these changes
Aug 4, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What was broken
A
liveArraydeclared withoutconstraintsnever gained or lost rows in response to its own query'ssubscribe. Updates to rows already in the list did apply, which made the failure easy to miss: values changed, but nothing was ever added or removed.subscribeupdateto a row already in the listupdatethat changes the sort fieldupdatefor a row not in the listcreatefor a row not in the listdeleteThis is the shape a paginated list with a live stream wants: fetch a page over REST, then keep it current from a subscription.
Why
A live collection is registered against the entity that owns it. For a query result that owner is the result's root entity, but a query's
subscribetagged its events with the query key instead. The two are derived from different inputs, so the tag matched no collection and membership events were dropped.Row updates still worked because they take the entity merge path, which doesn't depend on that tag.
The fix
Tag events with the root entity's key, which is what the collection is actually registered under. Entity
__subscribealready works this way, so this makes the query path consistent with it.Nothing else changes. Constrained collections, entity subscriptions, and external mutation events behave exactly as before, and an unconstrained collection still ignores everything except its own source.
Tests
updateand acreateinsert,deleteremoves, sort order is maintained throughout.Full suite passes: 1247 passed, 2 skipped, 65 files.
Implementation notes
createLiveCollectiongives an unconstrained collection the default constraint[[EVENT_SOURCE_FIELD, parent.key]], meaning "events originating from my own source."reconcileSubscriptionset__eventSourcetoqueryKey(a hash of the query definition and raw params), while the root entity's key comes from the injectedQUERY_ID(a hash of extracted params).ConstraintMatcher.routeEventtherefore computed a hash matching no registered binding.rootEntityis undefined until the first apply, andreconcileSubscriptiondeliberately runs before the first fetch so stream-resolved adapters are subscribed in time. Events in that window leave the source undefined, which skips collection routing while still merging into the entity store. There is no collection to route into yet, and__eventSourceis already optional on all three event types.No changes were needed below the routing layer.
LiveArrayInstance.onEventalready handlescreate,updatewhen the key is absent, anddelete, with_keysguards making both directions idempotent.Supersedes #44, which pinned the previous behavior.
🤖 Generated with Claude Code