Skip to content

fix: keep tool call message pairs when trimming context#1

Merged
CompilError-bts merged 3 commits intomasterfrom
codex/implement-fix-from-issue-7225
Mar 31, 2026
Merged

fix: keep tool call message pairs when trimming context#1
CompilError-bts merged 3 commits intomasterfrom
codex/implement-fix-from-issue-7225

Conversation

@CompilError-bts
Copy link
Copy Markdown
Owner

Motivation

Description

  • Replace the previous naive two-message pop logic in AbstractProvider.pop_record with atomic-unit removal that treats an assistant message containing tool_calls plus its following tool messages as one unit.
  • Handle leading orphan tool messages by removing contiguous leading tool messages as a unit.
  • Implement helper functions (_has_tool_calls, _first_non_system_index, _pop_earliest_unit) and loop until at least two non-system records worth of content have been removed or no more removable units exist.
  • Add two unit tests in tests/test_openai_source.py to cover atomic removal of assistant(tool_calls)+tool pairs and cleanup of leading orphan tool messages.

Testing

  • Ran ruff format . and ruff check . and both succeeded.
  • Attempted pytest tests/test_openai_source.py -k "pop_record" but the run failed in this environment due to a missing test dependency (pytest_asyncio) and so the test execution could not complete.
  • Lint/format checks passed and the change was committed and is ready for CI to run full test suite (including the new async tests).

Codex Task

@CompilError-bts CompilError-bts merged commit 2cd9a49 into master Mar 31, 2026
@CompilError-bts CompilError-bts deleted the codex/implement-fix-from-issue-7225 branch March 31, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant