feat(consumer): auto-create stream on pull_subscribe NotFoundError (#169)#516
Merged
Conversation
) The jetstream-consumer binds to streams `hi_agents` and `hi_tasks` by name. When those streams do not exist on the JetStream server, nats-py raises `NotFoundError` and the previous code surfaced it as a generic exception, falling into the outer retry loop. The retry never made progress until an operator manually created the streams. Add `_pull_subscribe_with_auto_create`, a thin wrapper around `js.pull_subscribe` that catches `NotFoundError`, calls `js.add_stream` with the expected subject filter, then retries once. The required stream configurations live in a new `REQUIRED_STREAMS` mapping at module scope. Closes #169 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
js.pull_subscribein_pull_subscribe_with_auto_createso that a missing JetStream stream is created automatically and the subscribe is retried once.REQUIRED_STREAMSmapping (hi_agents→hi.agents.>,hi_tasks→hi.tasks.>) so the auto-create call uses the correct subject filter.NotFoundErrorpropagates,add_streamfailure propagates).Previously, when
hi_agentsorhi_tasksdid not exist on the JetStream server,pull_subscriberaisedNotFoundError, fell to the outer retry loop, and never made progress until an operator created the streams manually.Closes #169
Test plan
python3 -m pytest tests/test_jetstream_consumer.py— 36 passed (32 existing + 4 new)ruff check jetstream-consumer/consumer.py tests/test_jetstream_consumer.py— cleanGenerated with Claude Code