Repository navigation
Description
Summary
When the reload policy accepts a change, the subscription handler drops the cache entry and calls self.get(uri) before calling on_change. If that refetch fails (server briefly unavailable, auth error) the exception escapes the handler and on_change is never called. The same happens when a callable reload policy raises.
Impact
The app silently misses the change notification: its own reload logic never runs, and since the event is consumed nothing retries. Push is documented as best-effort, but losing the callback because of a transient refetch error undermines the reload= feature in exactly the situations (server restarts, deploys) where changes are likely.
Steps to reproduce
pip install "priompt-sdk[nats]"- Run this script. It replaces
natswith a minimal fake so the handler can be invoked directly, and points gRPC at a port with no server so the refetch fails:import sys, types, asyncio, json cbs = [] fake = types.ModuleType("nats") class NC: async def subscribe(self, subject, cb=None): cbs.append(cb) async def connect(url, error_cb=None): return NC() fake.connect = connect sys.modules["nats"] = fake from priompt_sdk import PromptClient c = PromptClient(host="127.0.0.1:1", cache_ttl=30, nats_url="nats://127.0.0.1:4222") calls = [] c.subscribe("priompt://acme/x", lambda v, k: calls.append((v, k)), reload={"minor edit"}) msg = types.SimpleNamespace( data=json.dumps({"version": "abc", "classification": "minor edit"}).encode()) try: asyncio.run(cbs[0](msg)) except Exception as e: print("handler raised:", type(e).__name__, e.code()) print("on_change calls:", calls)
Actual:
handler raised: _InactiveRpcError StatusCode.UNAVAILABLE
on_change calls: []
With a real broker, nats-py passes the exception to the error callback, which logs a warning; on_change is still not called.
Expected behavior
on_change(version, classification) is called for every event. A failing reload policy or refetch is logged (with the URI) and does not prevent the callback.
Where to look
priompt_sdk/client.py#L202-L218handler: policy call, cache pop,self.get(uri), thenon_changepriompt_sdk/client.py#L184-L191where escaped exceptions end up (logged only)
Suggested approach
- Wrap the reload policy call and the refetch in
try/except Exception, log a warning, and always continue toon_change. - Run the blocking refetch off the event loop (
await asyncio.get_running_loop().run_in_executor(None, self.get, uri)) so a slow refetch does not stall later events.
Acceptance criteria
- If the refetch raises,
on_changeis still called once with the event's version and classification, and a warning is logged. - If a callable
reloadraises,on_changeis still called and no refetch is attempted. - Tests cover both cases using a faked
natsmodule (as above) and a failing stub.
Activity
maoji-y commentedon Dec 2, 2026
Could you assign this to me? I'd like to keep
on_changenotifications working when the reload policy or refetch fails, with offline regression tests. I'm using Codex and will wait for assignment before opening a PR.sujal-maheshwari2004 commentedon Dec 2, 2026
Assigned to @maoji-y