fix: guard FallbackChatGenerator.warm_up() against repeated initialization - #11977
Closed
rautaditya2606 wants to merge 1 commit into
Closed
Conversation
|
@rautaditya2606 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
See comment here #11976 (comment) |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes repeated initialization in FallbackChatGenerator by guarding warm_up() / warm_up_async() so wrapped generators aren’t warmed up on every run() / run_async() call.
Changes:
- Add a
_warmed_upflag to makewarm_up()idempotent. - Apply the same guard to
warm_up_async(). - Add regression tests ensuring warm-up is only delegated once across multiple runs, plus a release note.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
haystack/components/generators/chat/fallback.py |
Adds _warmed_up guard to prevent repeated warm-up on every run. |
test/components/generators/chat/test_fallback.py |
Adds sync + async regression tests for “warm up only once across multiple runs”. |
releasenotes/notes/fix-fallback-warm-up-lifecycle-da9d4b4af6a25872.yaml |
Documents the lifecycle semantic fix in release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
98
to
+106
| async def warm_up_async(self) -> None: | ||
| """Warm up all underlying chat generators on the serving event loop.""" | ||
| for gen in self.chat_generators: | ||
| if hasattr(gen, "warm_up_async"): | ||
| await gen.warm_up_async() | ||
| elif hasattr(gen, "warm_up"): | ||
| gen.warm_up() | ||
| """Warm up all underlying chat generators on the serving event loop (called at most once).""" | ||
| if not self._warmed_up: | ||
| for gen in self.chat_generators: | ||
| if hasattr(gen, "warm_up_async"): | ||
| await gen.warm_up_async() | ||
| elif hasattr(gen, "warm_up"): | ||
| gen.warm_up() | ||
| self._warmed_up = True |
Comment on lines
62
to
+63
| self.chat_generators = list(chat_generators) | ||
| self._warmed_up = False |
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.
Related Issues
Fixes #11976
Proposed Changes
self._warmed_up = FalsetoFallbackChatGenerator.__init__.warm_up()withif not self._warmed_up: ... self._warmed_up = Trueso wrapped generators are initialized at most once, matching the lifecycle semantics of other Haystack components.warm_up_async().test_warm_up_only_called_once_across_multiple_run_callstest_warm_up_async_only_called_once_across_multiple_run_async_callsHow did you test it?
All 32 tests passed.
Notes for the reviewer
This PR fixes a lifecycle contract inconsistency in
FallbackChatGenerator.run()andrun_async()currently invokewarm_up()on every execution. Unlike other Haystack components that perform one-time lazy initialization,FallbackChatGeneratorrepeatedly delegateswarm_up()to its wrapped generators. This means a custom generator with non-idempotent initialization logic may be reinitialized every time it is used throughFallbackChatGenerator.This change introduces a
_warmed_upguard, consistent with the pattern already used by components such asAgentand other generators. Wrapped generators are now warmed up at most once, while preserving existing behavior for generators whosewarm_up()implementations are already idempotent.Checklist