Repository navigation
fix: let the reload policy decide whether subscribe refreshes the cache - #7
Merged
Merged
Conversation
Contributor
Author
sujal-maheshwari2004
force-pushed
the
fix/3-hold-keeps-cache
branch
from
October 18, 2026 14:24
f6c40d8 to
e360656
Compare
The subscribe handler dropped and refetched the cached prompt on every event, before on_change ran, so after the agent decided to hold a change, client.get() returned the new version anyway. subscribe() now takes reload=, a set of verdicts or a function (version, classification) -> bool. Only an accepted change is fetched into the cache (before on_change, so get() inside the callback sees it). Any other change is held: the cache keeps the old version until cache_ttl expires. The default holds every change, matching the fail-closed policy the docs recommend. Fixes #3 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sujal-maheshwari2004
force-pushed
the
fix/3-hold-keeps-cache
branch
from
October 18, 2026 14:29
e360656 to
60b73f8
Compare
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 wrong
The
subscribehandler dropped and refetched the cached prompt on every event, beforeon_changeran. So when an agent's reload policy decided to hold a change,client.get()returned the new version anyway (withcache_ttlset).Fix
subscribe(uri, on_change, reload=None)takes the reload policy for the client cache: a set of verdicts (e.g.{"minor edit", "localized tweak", "new"}) or a function(version, classification) -> bool.on_changeruns, soget()inside the callback returns it.cache_ttlexpires.Noneholds every change (fail closed, like the docs' policy guidance).The event parsing was also untangled so an exception raised inside
on_changeno longer triggers a secondon_changecall with the raw body. README example updated to passreload=AUTO_RELOAD.Tests
New tests use a fake
natsmodule to deliver events without a broker: held change keeps the cached version, default holds everything, accepted change is in the cache beforeon_change, and a function policy works.Real run against
priompt v0.7.2(servewith-nats-token),cache_ttl=30, an agent that holds every change, then a structural publish:Before:
After:
With
reload={"structural"}the same publish is reloaded:get()insideon_changereturns62cfb53f5f95.Fixes #3
🤖 Generated with Claude Code