feat(core): Add remove_conversation
to ConversationManager
for ma…
#2613
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does
This PR introduces a new public method, remove_conversation(conversation_id: Uuid), to the ConversationManager. This allows consumers of the codex-core library to manually remove a conversation from the manager's in-memory storage.
Why this change is needed
I am currently adapting the Codex client to run as a long-lived server application. In this server environment, ConversationManager instances persist for extended periods, and new conversations are created for each incoming user request.
The current implementation of ConversationManager stores all created conversations in a HashMap indefinitely, with no mechanism for removal. This leads to unbounded memory growth in a server context, as every new conversation permanently occupies memory.
While an automatic TTL-based cleanup mechanism could be one solution, a simpler, more direct remove_conversation method provides the necessary control for my use case. It allows my server application to explicitly manage the lifecycle of conversations, such as cleaning them up after a request is fully processed or after a period of inactivity is detected at the application level.
This change provides a minimal, non-intrusive way to address the memory management issue for server-like applications built on top of codex-core, giving developers the flexibility to implement their own cleanup logic.