Skip to content

Conversation

mshsheikh
Copy link
Contributor

When max_queue_size is small (e.g., 1), max_queue_size * export_trigger_ratio could be less than 1, resulting in a zero trigger size. This would cause immediate exports after adding any item to the queue (since queue_size >= 0 is always true), defeating the purpose of batching. This change ensures the trigger size is at least 1 by using max(1, int(max_queue_size * export_trigger_ratio)).

Fix:

# Before (broken for small queues)
trigger_size = int(max_queue_size * export_trigger_ratio)

# After (fixed: min 1 item needed)
trigger_size = max(1, int(max_queue_size * export_trigger_ratio))

Key change:
Added max(1, ...) to guarantee the trigger size is never 0, so batching works even for tiny queues.

When max_queue_size is small (e.g., 1), max_queue_size * export_trigger_ratio could be less than 1, resulting in a zero trigger size.
This would cause immediate exports after adding any item to the queue (since queue_size >= 0 is always true), defeating the purpose of batching.
This change ensures the trigger size is at least 1 by using max(1, int(max_queue_size * export_trigger_ratio)).

**Fix**:  
```python
# Before (broken for small queues)
trigger_size = int(max_queue_size * export_trigger_ratio)

# After (fixed: min 1 item needed)
trigger_size = max(1, int(max_queue_size * export_trigger_ratio))
```

**Key change**:  
Added `max(1, ...)` to guarantee the trigger size is **never 0**, so batching works even for tiny queues.
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no one could set the max to 1 in reality, but the change logically makes sense. Thanks!

@seratch seratch merged commit 7a4c024 into openai:main Jul 28, 2025
6 checks passed
vcshih pushed a commit to veris-ai/openai-agents-python that referenced this pull request Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants