Harden reply-topic creation against a hardcoded replicas=0#694
Open
wbarnha wants to merge 1 commit into
Open
Conversation
_reply_topic() (the ephemeral topic backing agent .ask()/reply_to) hardcoded replicas=0. #76 reported this crashing topic creation with InvalidReplicationFactorError on brokers that reject a replication factor of 0 -- most do, via min.insync.replicas. On current code the acute crash no longer reproduces: Topic.declare() already falls back to app.conf.topic_replication_factor whenever `self.replicas` is falsy (`if self.replicas: ... else: ...`), and 0 is falsy in Python, so the hardcoded 0 was already being silently replaced by the configured default (1) before reaching the broker. That's a coincidence of Python truthiness, not an intentional contract -- nothing stops a future change to that fallback (e.g. distinguishing an explicit 0 from an unset value) from reintroducing today's crash. Pass app.conf.topic_replication_factor explicitly instead of the magic 0, consistent with how every other topic faust creates picks up its replication factor. No longer relies on the fallback to mask the wrong value. The existing test_reply_topic asserted the old, wrong value (topic.replicas == 0); updated to assert the topic gets a real, broker-acceptable replication factor. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #694 +/- ##
=======================================
Coverage 94.14% 94.15%
=======================================
Files 104 104
Lines 11136 11136
Branches 1201 1201
=======================================
+ Hits 10484 10485 +1
+ Misses 551 550 -1
Partials 101 101 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Note: Before submitting this pull request, please review our contributing guidelines.
Description
Relates to #76.
ReplyConsumer._reply_topic()(faust/agents/replies.py) — the ephemeral topic backing agent.ask()/reply_to— hardcodedreplicas=0. #76 originally reported this crashing topic creation withInvalidReplicationFactorErroron brokers that reject a replication factor of0(most do, viamin.insync.replicas).What I found investigating this
The acute crash from #76 no longer reproduces on current code, so I'm not claiming this closes #76 outright — worth verifying against a real broker before closing it.
Topic.declare()(faust/topics.py) already has a fallback:0is falsy in Python, so the hardcodedreplicas=0was already being silently replaced by the configured default (topic_replication_factor, default1) before ever reaching the broker. I verified this directly: constructing the reply topic and tracingdeclare()'s branch logic resolves toreplicas=1, not0.Why this PR is still worth doing
That's a coincidence of Python truthiness, not an intentional contract — nothing stops a future change to that fallback (e.g. distinguishing an explicit
0from an unset value, which would be a reasonable thing to want) from silently reintroducing today's crash. It's also just confusing to read: the line says "0 replicas" and means "use the app default."Fix
Pass
app.conf.topic_replication_factorexplicitly instead of the magic0, consistent with how every other topic Faust creates picks up its replication factor. No longer relies on the fallback to mask the wrong value.Tests
test_reply_topicasserted the old, wrong value (topic.replicas == 0) — updated to assert the topic gets the app's configured replication factor (and that it's> 0).AssertionError: assert 0 == 1.flake8,black --check,isort --check-onlyclean. Fulltests/unit/agentssuite passes (123 passed, 1 pre-existing skip unrelated to this change).🤖 Generated with Claude Code
Generated by Claude Code