[FIXED] Improve KeyValue and ObjectStore watchers: Fix watching past history replay#644
Merged
caspervonb merged 3 commits intonats-io:mainfrom Feb 20, 2026
Merged
Conversation
Contributor
Author
|
Sorry meant to open as a draft. I will address the build failure issues then mark as ready. |
fc0d9d5 to
1ada326
Compare
Include StopIterSentinel oops
1ada326 to
a19307d
Compare
Contributor
Author
|
I rebased this on top of current main since it's been a while. Using it live in some of our projects. |
evertheirbaut
approved these changes
Jul 29, 2025
Contributor
Author
|
Crap, I just realized this was still open, I will take a look in a bit at what the conflicts are now that it is approved |
Signed-off-by: Casper Beyer <casper@synadia.com>
caspervonb
reviewed
Feb 20, 2026
| def __init__(self, js): | ||
| self._js = js | ||
| self._updates: asyncio.Queue[KeyValue.Entry | None] = asyncio.Queue(maxsize=256) | ||
| self._updates: asyncio.Queue[KeyValue.Entry | None | StopIterSentinel] = asyncio.Queue(maxsize=256) |
Collaborator
There was a problem hiding this comment.
Newer python, has this built into asyncio.Queue, but given our version requirements right call.
caspervonb
approved these changes
Feb 20, 2026
wallyqs
pushed a commit
to wallyqs/nats.py
that referenced
this pull request
Feb 20, 2026
The original PR was split and merged as separate commits (nats-io#734, nats-io#822, nats-io#823, nats-io#824, nats-io#644). Server pool changes were dropped. Re-checked all 40 issues against current main (a9bfe71): 0 of 33 in-scope issues were addressed. Added review of new commit nats-io#644 (watcher sentinel fix). https://claude.ai/code/session_014UCS5Nmn5ZM9RoAxEKd3mA
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.
Overview
This PR enhances the KeyValue and ObjectStore watchers in
nats.pyby introducing a few key improvements:1. StopIterSentinel for Watchers
StopIterSentinel) and enqueue it on the watcher’s queue to signal termination (e.g., whenstop()is called).StopAsyncIteration) without conflating aNonemarker with an end-of-stream condition.2. Ensure Watchers Do Not Break on
NoneNonein the queue as a termination signal. But for the JetStream KV watchers,Noneis also used internally to indicate “no more pending updates” as part of the initial replay.StopIterSentinel.3. Minor Cleanups in Watchers
KeyWatcherandObjectWatcherpush theStopIterSentinelto their_updatesqueue and raiseStopAsyncIterationinside__anext__()if the sentinel is dequeued.Note
test_kv_simplethat doesassert 2 == 1. That specific test (from the official suite) checks behavior around purge vs. expected message count, which can differ in certain server versions. If this is not due to the version mismatch I will fix or close this.Linked Issues
This PR might relate to or address:
(References and discussion around ephemeral watchers,
Nonehandling, or improvements to KV watchers.)Impact and Compatibility
test_kv_simplemismatch.Usage Example
Below is an example of usage for a KV watcher now that watchers keep running beyond the initial replay:
Contributing Statement
• This contribution is my original work.
• I license the work to the NATS project under the project’s Apache 2.0 license.
Thanks for your consideration! If any further adjustments or clarifications are needed, please let me know. I tried to adhere to the ADR and existing code practices as closely as possible.
Cheers,
Fielding