openai / openai/openai-agents-python
Clearing a compaction session retains the previous response chain
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 29.6k
- Forks
- 4.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 123
Description
Describe the bug
OpenAIResponsesCompactionSession.clear_session() clears the underlying history and cached compaction items, and resets _deferred_response_id, but it leaves _response_id and _last_unstored_response_id unchanged.
As a result, later compaction can reuse response-chain state from history the caller explicitly cleared. In previous_response_id mode, a stale response ID can still be sent to responses.compact after the session is empty.
Reproduction
session = OpenAIResponsesCompactionSession(
session_id="test",
underlying_session=mock_session,
client=mock_client,
should_trigger_compaction=lambda _context: False,
)
await session.run_compaction({"response_id": "resp-old", "store": True})
await session.clear_session()
await session.run_compaction(
{"force": True, "compaction_mode": "previous_response_id"}
)
On current main, the second call proceeds instead of raising that no response ID is available for the cleared session. A focused regression reaches the mocked compact client after the clear.
Expected behavior
A successful clear_session() should reset all response-chain state owned by the wrapper: _response_id, _deferred_response_id, and _last_unstored_response_id, in addition to the cached history.
After clear, explicit previous_response_id compaction without a newly supplied response ID should fail before any client call. If the underlying clear fails, response-chain state should remain unchanged because the old history may still exist.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with OpenAIResponsesCompactionSession.clear_session() and run_compaction(), using the reproduction to trace response-chain state before and after clearing. Add a focused regression around previous_response_id compaction and verify that a successful clear resets all three IDs, while a failed underlying clear preserves them and no client call occurs without a response ID.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, backend-api-design
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100