Repository navigation
fix(topic): tie subscribe lifecycle to consumer-read, not send() - #32
Merged
Merged
Conversation
The default TopicQuery.getConfig.subscribe only defined the cleanup half and depended on _topicAdapter being set inside TopicQueryAdapter.send. Whenever send short-circuited (pre-fulfilled topic via fulfillTopic, or in-memory cache within staleTime), subscribe never fired but unsubscribe still fired on consumer unmount, tearing down adapter state that was never registered. Set the adapter on the execution context eagerly in QueryResult.getOrCreateExecutionContext, implement both halves of the default subscribe, and drop the now-redundant subscribe call from send. reconcileSubscription is also called unconditionally on activation so that subscribe runs before the first fetch awaits. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop the internal-mechanism sentence and the restatement; CHANGELOG readers don't have the internal symbols and the first sentence already covers what changes for them. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
pzuraq
approved these changes
May 22, 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.
Summary
TopicQuery's intuitive contract is that subscribe/unsubscribe to a topic tracks consumer-read lifecycle: while any consumer is reading the relay, the topic is subscribed on the wire; when the last consumer goes away, it's unsubscribed. Pre-fulfillment and cache are orthogonal optimizations for data freshness and should not affect the subscribe lifecycle.Today the subscribe is wired to the fetch path:
TopicQueryAdapter.sendcallsadapter.subscribe(topic), and the defaultTopicQuery.getConfig.subscribeonly defines the cleanup half (depending on_topicAdapterbeing set insidesend). So wheneversendshort-circuits (pre-fulfilled topic viafulfillTopic, or cache withinstaleTime), subscribe never fires, but the cleanup still fires on consumer unmount and tears down adapter state that was never registered.Fix
ctx._topicAdaptereagerly inQueryResult.getOrCreateExecutionContextso the defaultsubscribecan reach the adapter without depending onsendhaving run.TopicQuery.getConfig.subscribe, and remove the now-redundant subscribe call fromsend.reconcileSubscriptionalso runs unconditionally on activation so subscribe wires up before the first fetch awaits.Test plan
tsc --noEmitclean.