hotfix: add missing agent source modules (events, reasoning, schemas)#85
hotfix: add missing agent source modules (events, reasoning, schemas)#85DsThakurRawat merged 1 commit intomainfrom
Conversation
…ols/file_edit_tool.py These modules are imported by agents/__init__.py (merged in PR #83) but were not included in that PR. Also includes the updated file_edit_tool with 3-tier fuzzy matching.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 52 minutes and 48 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ 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.
Code Review
This pull request introduces a typed event system for agent communication, a multi-turn reasoning chain with validation retries, structured Pydantic schemas for various agent roles, and a high-precision file editing tool. Feedback includes addressing a path traversal vulnerability in the file edit tool, improving error handling in the reasoning chain's retry logic to avoid redundant validation attempts, and hardening the default security configuration in the CTO schema by removing wildcard CORS origins.
| replace_all: If True, replace all occurrences. If False, fail on | ||
| multiple matches (for safety). | ||
| """ | ||
| full_path = os.path.join(self.working_dir, file_path) |
There was a problem hiding this comment.
The file_path parameter is joined with working_dir without validation, which can lead to path traversal vulnerabilities. An agent could potentially read or modify files outside the intended workspace by providing paths like ../../etc/passwd. Use os.path.abspath to resolve the path and verify it starts with the absolute path of the working_dir.
full_path = os.path.abspath(os.path.join(self.working_dir, file_path))
if not full_path.startswith(os.path.abspath(self.working_dir)):
return ToolResult(
success=False, output="", error=f"Access denied: {file_path} is outside working directory"
)| try: | ||
| output = json.loads(raw) | ||
| except json.JSONDecodeError: | ||
| pass # Try validation again with the old output |
There was a problem hiding this comment.
If the LLM's response for a schema fix is not valid JSON, json.loads will raise a JSONDecodeError. Currently, this error is caught and ignored, causing the loop to proceed and attempt to validate the original invalid output again. This wastes a retry attempt. Using continue ensures the loop moves to the next retry iteration.
| try: | |
| output = json.loads(raw) | |
| except json.JSONDecodeError: | |
| pass # Try validation again with the old output | |
| try: | |
| output = json.loads(raw) | |
| except json.JSONDecodeError: | |
| logger.warning("reasoning_chain.fix_parse_failed", raw=raw[:200]) | |
| continue |
|
|
||
|
|
||
| class SecurityConfig(BaseModel): | ||
| cors_origins: list[str] = Field(default_factory=lambda: ["*"]) |
There was a problem hiding this comment.
Defaulting cors_origins to ["*"] in a security configuration model is an insecure default. It is better to default to an empty list, forcing explicit configuration of allowed origins.
| cors_origins: list[str] = Field(default_factory=lambda: ["*"]) | |
| cors_origins: list[str] = Field(default_factory=list) |
Fix
PR #83 updated
agents/__init__.pyto import from.events,.reasoning, and.schemas, but those source files were not included. This broke CI.Also adds
tools/file_edit_tool.py(3-tier fuzzy matching) needed bytest_file_edit_tool.py.