fix: prevent shared LLM stop words mutation across agents (#5141)#5142
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
fix: prevent shared LLM stop words mutation across agents (#5141)#5142devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
When multiple agents share the same LLM instance, the executor was directly mutating the shared LLM's stop words list. This caused cross-agent state pollution where stop words would accumulate across agents and across multiple crew.kickoff() calls. Fix: create a shallow copy of the LLM before merging stop words, so each executor gets its own isolated stop word list. Only copy when new stop words are actually being added to avoid unnecessary allocations. Applied to both CrewAgentExecutor and experimental AgentExecutor. Co-Authored-By: João <[email protected]>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: João <[email protected]>
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
Fixes #5141. When multiple agents share the same LLM instance, the executor's
__init__was directly mutatingself.llm.stopon the shared object. This caused stop words to accumulate across agents and across repeatedcrew.kickoff()calls, leading to incorrect LLM behavior.The fix creates a shallow copy of the LLM via
copy.copy()before merging stop words, so each executor gets an isolated stop word list. The copy is only made when new stop words are actually being added (to avoid unnecessary allocations). Applied identically to bothCrewAgentExecutorand experimentalAgentExecutor.Review & Testing Checklist for Human
copy.copy()is safe on your LLM subclasses — shallow copy shares all internal references (connection pools, caches, provider state). Confirm no LLM subclass relies on identity (is) checks or has mutable internal state that would break when shared between original and copy. This is the highest-risk aspect of this change.LLM(model=..., stop=["X"])instance, runkickoff()multiple times, and confirm stop words don't grow on the shared LLM and each agent behaves correctly.merged_stopis built fromset(), so["A", "B"]could become["B", "A"]. The!=check againstexisting_stopis order-sensitive, meaning even when no new stop words are added but order differs, a copy is still made. This is harmless but slightly wasteful. Consider usingset()comparison instead if this matters.Notes
or []addition (getattr(self.llm, "stop", []) or []) is a minor behavioral change that converts an explicitNoneonstopto[]. This is likely correct since downstream code expects a list.tests (3.10)failure (test_custom_llm_within_crew) is a pre-existing flaky test unrelated to this change. Thetests (3.11/3.12/3.13)runs were cancelled (not failed) due to CI infrastructure behavior. Lint, type-checker (all versions), and CodeQL all pass.Link to Devin session: https://app.devin.ai/sessions/0807fced3a7b4e4ab5cbe3a6a0d7ed2e