Skip to content

fix: enforce min trigger size=1 to prevent immediate exports #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2025

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
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