Skip to content

Add bounded size limit to _pending_tool_calls dictionary#125

Merged
nikhilNava merged 3 commits intonikhilc/OpenAIAutoInstrumentation-fixattributesfrom
copilot/sub-pr-122
Jan 21, 2026
Merged

Add bounded size limit to _pending_tool_calls dictionary#125
nikhilNava merged 3 commits intonikhilc/OpenAIAutoInstrumentation-fixattributesfrom
copilot/sub-pr-122

Conversation

Copy link
Contributor

Copilot AI commented Jan 21, 2026

The _pending_tool_calls dictionary accumulates tool call IDs without bounds when tool calls are captured but never consumed by matching FunctionSpans. In long-running applications, this causes unbounded memory growth.

Changes

  • Added size cap: Introduced _MAX_PENDING_TOOL_CALLS = 1000 constant, matching the pattern used for _MAX_HANDOFFS_IN_FLIGHT
  • Converted to OrderedDict: Changed _pending_tool_calls from dict to OrderedDict to enable FIFO eviction
  • Implemented eviction logic: Updated capture_tool_call_ids() to enforce max size by removing oldest entries when limit is exceeded
# In OpenAIAgentsTraceProcessor.__init__
self._pending_tool_calls: OrderedDict[str, str] = OrderedDict()

# In capture_tool_call_ids()
pending_tool_calls[key] = call_id
while len(pending_tool_calls) > max_size:
    pending_tool_calls.popitem(last=False)  # Remove oldest

This mirrors the existing bounded approach used for _reverse_handoffs_dict, ensuring consistent memory safety across the trace processor.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 21, 2026 17:45
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
@nikhilNava nikhilNava marked this pull request as ready for review January 21, 2026 17:47
@nikhilNava nikhilNava requested a review from a team as a code owner January 21, 2026 17:47
Copilot AI changed the title [WIP] Address feedback on OpenAI auto instrumentation PR Add bounded size limit to _pending_tool_calls dictionary Jan 21, 2026
Copilot AI requested a review from nikhilNava January 21, 2026 17:47
@nikhilNava nikhilNava merged commit 52f6cb1 into nikhilc/OpenAIAutoInstrumentation-fixattributes Jan 21, 2026
1 check passed
@nikhilNava nikhilNava deleted the copilot/sub-pr-122 branch January 21, 2026 17:47
nikhilNava added a commit that referenced this pull request Jan 21, 2026
* fix input and output messages for invoke span and fix tool call messages

* add test for invoke agent auto instrumented

* Add bounded size limit to _pending_tool_calls dictionary (#125)

* Initial plan

* Implement bounded size for _pending_tool_calls to prevent memory growth

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>

* Fix trailing empty line in test file

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>

* Fix code formatting with ruff (#126)

* Initial plan

* Fix formatting with ruff format

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>

---------

Co-authored-by: Nikhil Chitlur Navakiran (from Dev Box) <nikhilc@microsoft.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants