openllmetry icon indicating copy to clipboard operation
openllmetry copied to clipboard

Responses API: Clean up completed responses from the global responses dictionary

Open archiep867-sys opened this issue 1 month ago • 1 comments

Description

The OpenAI Responses API instrumentation stores response trace data in a module-level responses dictionary. However, completed responses are not removed after their spans end.

In long-running applications, this causes the dictionary to grow with every Responses API call, resulting in unbounded memory growth.

Expected Behavior

Response entries should be removed from the responses dictionary when the corresponding response completes or fails and its span ends.

Proposed Fix

  • Remove the response entry using responses.pop(response_id, None) when the span ends.
  • Apply the cleanup consistently to the synchronous, asynchronous, and streaming response paths.
  • Add tests to verify that completed responses are removed from the dictionary.

archiep867-sys avatar Oct 06 '26 16:10 archiep867-sys

already fixed in #4531

doronkopit5 avatar Oct 06 '26 18:10 doronkopit5