fix(reasoning): use flexible regex to detect READY state to prevent agent deadlocks - #6625
fix(reasoning): use flexible regex to detect READY state to prevent agent deadlocks#6625Kikingodoy wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReadiness detection in ChangesReadiness Detection
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/crewai/src/crewai/utilities/reasoning_handler.py`:
- Line 413: Update the readiness detection in the relevant paths of the
reasoning handler to reject any case-insensitive `not` followed by one or more
whitespace characters before `ready`, including tabs, repeated spaces, and
newlines. Centralize this logic in a shared helper and replace the checks at the
`response_str` readiness sites, then add tests covering all three paths and
whitespace variants.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1a144e3e-806a-4d37-9d3c-2cf9dd69ce82
📒 Files selected for processing (1)
lib/crewai/src/crewai/utilities/reasoning_handler.py
…space in 'not ready'
|
I've pushed an update addressing the feedback! I've extracted the readiness check into a centralized I've also added a comprehensive test suite in |
gnanirahulnutakki
left a comment
There was a problem hiding this comment.
Thanks for broadening support beyond the legacy exact sentence. I reproduced a remaining semantic false-positive in the centralized helper: common unready/future-readiness prose now ends planning early. I included a protocol-based parsing direction and focused validation inline.
| """Check if the response indicates the agent is ready.""" | ||
| if re.search(r"(?i)\bnot\s+ready\b", response): | ||
| return False | ||
| return bool(re.search(r"(?i)\bready\b", response)) |
There was a problem hiding this comment.
Could we parse an explicit readiness marker instead of treating any remaining ready token as permission to execute? On this exact head, both AgentReasoning._parse_planning_response("Plan draft.\nNOT YET READY: missing token")[1] and the same call with "I need more context before I am ready." return True; never ready, hardly ready, will be ready, and NOT-READY do too. That prematurely exits the refinement loop even though the model is explicitly unready. The prompt already defines a terminal READY / NOT READY protocol, so a safer approach is to match line-anchored markers (optionally Status: / I am) and use the last marker, rather than infer intent from unrestricted prose. I validated that approach against the 16 existing cases plus six semantic-negation cases: 22 focused tests passed, along with Ruff and mypy.
This PR fixes a bug in the
AgentReasoningloop where the readiness check was hardcoded to expect the exact string"READY: I am ready to execute the task.".Newer local/open-source models, or models under slightly altered prompts, frequently output just
"READY"or some other variation, causing the planning executor to fail to detect readiness and trap the agent in an infinite planning loop.This replaces the hardcoded exact string matches with a flexible regular expression
(?i)(?<!not )\bready\bthat safely identifies when the model is ready, gracefully ignoring "not ready".