Skip to content

Commit 51fff06

Browse files
authored
fix: enforce min trigger size=1 to prevent immediate exports
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.
1 parent 7e632c2 commit 51fff06

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/agents/tracing/processors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __init__(
183183
self._shutdown_event = threading.Event()
184184

185185
# The queue size threshold at which we export immediately.
186-
self._export_trigger_size = int(max_queue_size * export_trigger_ratio)
186+
self._export_trigger_size = max(1, int(max_queue_size * export_trigger_ratio))
187187

188188
# Track when we next *must* perform a scheduled export
189189
self._next_export_time = time.time() + self._schedule_delay

0 commit comments

Comments
 (0)