Repository navigation
Description
Describe the bug
BatchTraceProcessor implements a relative scheduling deadline using time.time():
- Initial deadline:
openai-agents-python/src/agents/tracing/processors.py
Lines 572 to 576 in 000a96b
# The queue size threshold at which we export immediately. self._export_trigger_size = max(1, int(max_queue_size * export_trigger_ratio)) # Track when we next *must* perform a scheduled export self._next_export_time = time.time() + self._schedule_delay - Deadline comparison/reset:
openai-agents-python/src/agents/tracing/processors.py
Lines 653 to 665 in 000a96b
def _run(self): while not self._shutdown_event.is_set(): current_time = time.time() queue_size = self._queue.qsize() # If it's time for a scheduled flush or queue is above the trigger threshold if current_time >= self._next_export_time or queue_size >= self._export_trigger_size: self._export_batches() # Reset the next scheduled flush time self._next_export_time = time.time() + self._schedule_delay else: # Sleep a short interval so we don't busy-wait. time.sleep(0.2)
Wall-clock time is adjustable. If the clock moves backward, a scheduled batch can remain queued much longer than schedule_delay. If it moves forward, a flush can be triggered immediately. This class already uses time.monotonic() for shutdown deadlines, so its two elapsed-time mechanisms currently follow inconsistent clocks.
Debug information
- Agents SDK version: v0.19.1
- Audited commit:
000a96b602889b00f7cfaa210c41e1a74be65272 - Python version: Python 3.10+
- Evidence type: static scheduling inspection
Repro steps
A deterministic unit regression can patch the clock sources:
- Construct a processor with a long queue threshold so only scheduled export triggers.
- Enqueue an item.
- Advance the monotonic clock past
schedule_delaywhile moving the wall clock backward. - Under the current implementation, the scheduled comparison remains false and the item is not exported.
- Repeat with a forward wall-clock jump to show an early trigger.
The test need not sleep in real time; the scheduling decision can be isolated with a recording exporter and controlled clock values.
Expected behavior
A configured delay should measure elapsed process time and should be unaffected by NTP corrections, host time synchronization, daylight/time configuration, or manual clock changes. All relative deadlines in the processor should use a monotonic clock.
Why this matters
Tracing is commonly buffered specifically to reduce request overhead. Unexpectedly delayed batches increase the chance that telemetry remains in memory and is lost during abnormal termination; premature batches undermine batching efficiency.
Suggested scope
Use time.monotonic() consistently for _next_export_time initialization, comparison, and reset. Add a controlled-clock regression test.
I searched current tracing issues and PRs for scheduled flush clocks, monotonic deadlines, and clock adjustment and found no active duplicate.
Activity