Skip to content

Clearing a compaction session retains the previous response chain #4864

Description

@sylvesterkaczmarek

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions