Skip to content

feat(consumer): auto-create stream on pull_subscribe NotFoundError (#169)#516

Merged
mvillmow merged 1 commit into
mainfrom
169-stream-auto-create-fallback
May 14, 2026
Merged

feat(consumer): auto-create stream on pull_subscribe NotFoundError (#169)#516
mvillmow merged 1 commit into
mainfrom
169-stream-auto-create-fallback

Conversation

@mvillmow
Copy link
Copy Markdown
Contributor

Summary

  • Wrap js.pull_subscribe in _pull_subscribe_with_auto_create so that a missing JetStream stream is created automatically and the subscribe is retried once.
  • Add REQUIRED_STREAMS mapping (hi_agentshi.agents.>, hi_taskshi.tasks.>) so the auto-create call uses the correct subject filter.
  • Cover the new helper with 4 unit tests (happy path, auto-create + retry, unknown stream falls back to subject, second NotFoundError propagates, add_stream failure propagates).

Previously, when hi_agents or hi_tasks did not exist on the JetStream server, pull_subscribe raised NotFoundError, 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 — clean
  • CI green on PR

Generated with Claude Code

)

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>
@mvillmow mvillmow enabled auto-merge (squash) May 14, 2026 02:59
@mvillmow mvillmow merged commit a935204 into main May 14, 2026
20 checks passed
@mvillmow mvillmow deleted the 169-stream-auto-create-fallback branch May 14, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add stream auto-create fallback for pull_subscribe NotFoundError

1 participant