Skip to content

switch to uv#1

Merged
samuelcolvin merged 6 commits intomainfrom
switch-to-uv
Oct 10, 2024
Merged

switch to uv#1
samuelcolvin merged 6 commits intomainfrom
switch-to-uv

Conversation

@samuelcolvin
Copy link
Copy Markdown
Member

No description provided.

@samuelcolvin samuelcolvin merged commit 76b318e into main Oct 10, 2024
@samuelcolvin samuelcolvin deleted the switch-to-uv branch October 10, 2024 12:46
cjermain pushed a commit to cjermain/pydantic-ai that referenced this pull request Nov 5, 2025
This commit fixes all critical and medium severity bugs identified in the
prototype code review:

CRITICAL BUG FIXES:

1. Multi-agent usage_history propagation (Bug pydantic#1)
   - Added usage_history parameter to run(), run_sync(), and iter() methods
   - Pass usage_history when creating GraphAgentState
   - Exposed usage_history in RunContext for tools to access
   - Now tools can pass ctx.usage_history to delegated agents

2. Thread safety for concurrent requests (Bug pydantic#3)
   - Added asyncio.Lock to UsageHistory class
   - Made check_per_minute_limits_before_request() async with locking
   - Made check_per_minute_limits_after_response() async with locking
   - Prevents race conditions where concurrent requests bypass limits

3. Streaming per-minute limit checks (Bug pydantic#2)
   - Updated _get_usage_checking_stream_response() to accept usage_history
   - Added per-minute limit checks during streaming
   - Pass usage_history from AgentStream to checking function
   - Now streaming responses properly enforce per-minute limits

MEDIUM SEVERITY FIXES:

4. Memory leak prevention (Bug pydantic#4)
   - Always cleanup old entries, not just when limits are enabled
   - Prevents unbounded memory growth if limits are toggled

5. Input validation (Bug pydantic#8)
   - Added validation in UsageLimits.__init__() for negative values
   - Raises ValueError if any limit is negative

TESTING:
- All 25 usage limit tests pass
- No regressions in existing tests
- Ready for integration testing with multi-agent scenarios

Changes:
- pydantic_ai/usage.py: Thread safety, validation, async methods
- pydantic_ai/_agent_graph.py: Async await, memory leak fix
- pydantic_ai/_run_context.py: Added usage_history field
- pydantic_ai/agent/abstract.py: Added usage_history parameter
- pydantic_ai/agent/__init__.py: Pass usage_history to state
- pydantic_ai/result.py: Streaming limit checks
cjermain pushed a commit to cjermain/pydantic-ai that referenced this pull request Nov 9, 2025
Conducted thorough codebase review and identified critical issues that must
be fixed before the prototype can be merged:

CRITICAL ISSUES (Must Fix):
1. BREAKING CHANGE: RunContext now requires usage_history field
   - Breaks all existing code that creates RunContext
   - All tests failing (test_toolsets.py confirmed)
   - Need to make usage_history optional with default value

2. RACE CONDITION: add_entry() not thread-safe
   - Called without lock protection in _agent_graph.py:532
   - Multiple concurrent responses can corrupt list
   - Need async add_entry_atomic() method

3. RACE CONDITION: cleanup_old_entries() not thread-safe
   - Called without lock protection in _agent_graph.py:500
   - List reassignment not atomic
   - Need async cleanup_old_entries_atomic() method

4. get_usage_in_window() not thread-safe
   - Reads list without lock, could fail if modified during iteration
   - Currently protected by caller's lock but fragile design

5. TemporalRunContext broken
   - Inherits RunContext but doesn't provide usage_history
   - Breaks all Temporal/durable execution workflows

HIGH SEVERITY:
- Multiple test files will fail
- Lock cannot be deep copied properly
- No concurrent request tests
- No multi-agent integration tests

The analysis provides detailed explanations, code examples, and recommended
fixes for each issue. Estimated 8 hours of work to make production-ready.

RECOMMENDATION: Do not merge until critical issues pydantic#1-5 are fixed.
@sarth6 sarth6 mentioned this pull request Feb 7, 2026
4 tasks
thiagohora pushed a commit to thiagohora/pydantic-ai that referenced this pull request Feb 10, 2026
majiayu000 added a commit to majiayu000/pydantic-ai that referenced this pull request Mar 16, 2026
…me, add negative tests

- Check function_tools instead of tool_defs to avoid false positives with
  ToolOutput structured output (reviewer comment pydantic#1)
- Use openai_supports_encrypted_reasoning_content (actual field) instead
  of non-existent openai_supports_reasoning
- Use real reasoning model name o3-mini instead of fictional gpt-5.4
- Add negative tests: reasoning_effort without tools and tools without
  reasoning_effort both pass validation (reviewer comment pydantic#4)

Signed-off-by: majiayu000 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant