Fix extended thinking and allow per-repo context files (AGENTS.md, CLAUDE.md, etc.) to be included as context#2387
Conversation
Review Summary by QodoSupport Claude model overrides and repository context files in AI prompts
WalkthroughsDescription• Add support for overriding Claude extended thinking models via config • Include repository context files (AGENTS.md, CLAUDE.md, etc.) in AI prompts • Extend git provider interface with repo file content retrieval capability • Add comprehensive tests for new features and fix minor code issues Diagramflowchart LR
A["Config Settings"] -->|claude_extended_thinking_models_override| B["LiteLLM Handler"]
C["Repo Context Files"] -->|repo_context_files config| D["build_repo_context"]
D -->|fetches files| E["Git Provider"]
D -->|renders context| F["Instruction Files"]
F -->|injected into| G["AI Prompts"]
B -->|uses models| G
File Changes1. pr_agent/algo/__init__.py
|
Code Review by Qodo
Context used 1. Unbounded context process cache
|
|
Persistent review updated to latest commit 2b313ad |
2b313ad to
50de2c6
Compare
|
Persistent review updated to latest commit 50de2c6 |
50de2c6 to
e93cad2
Compare
|
Persistent review updated to latest commit e93cad2 |
| cache_key = _get_repo_context_cache_key(context_files, max_lines) | ||
| process_cache_key = _get_repo_context_process_cache_key(git_provider, context_files, max_lines) | ||
| if process_cache_key is not None and process_cache_key in _repo_context_process_cache: | ||
| return _repo_context_process_cache[process_cache_key] | ||
|
|
There was a problem hiding this comment.
1. Unbounded context process cache 🐞 Bug ☼ Reliability
build_repo_context() stores repo context in a module-level _repo_context_process_cache keyed by PR URL without TTL/eviction, so long-lived servers can accumulate entries indefinitely and can keep serving stale instruction files for a PR until process restart.
Agent Prompt
## Issue description
`build_repo_context()` uses a module-level dict (`_repo_context_process_cache`) as a process-wide cache keyed by PR URL. Because it has no TTL/max-size eviction, long-lived servers will:
1) grow memory unbounded as more PR URLs are processed, and
2) potentially serve stale instruction-file contents for the same PR URL even if the repo default-branch instruction files change.
## Issue Context
This cache is independent of any single provider instance and persists for the lifetime of the Python process. The repo runs as a long-lived FastAPI/uvicorn app in webhook deployments, so the cache lifetime is effectively “forever”.
## Fix Focus Areas
- pr_agent/algo/repo_context.py[13-14]
- pr_agent/algo/repo_context.py[136-140]
- pr_agent/algo/repo_context.py[175-185]
## How to fix
- Replace `_repo_context_process_cache` with a bounded/evicting structure (e.g., `functools.lru_cache(maxsize=...)`, or a TTL cache).
- If keeping cross-instance caching, include an invalidation strategy (TTL is simplest) so updated repo instruction files eventually refresh.
- Ensure empty-string entries also follow the eviction policy to avoid permanently pinning “missing” results for long-running processes.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Resolves #2357.
I backed out my other PR because it was too many changes (previously included "de-dupe inline comments") in one PR.