fix(agent): clear _session_messages in AIAgent.close() (#42123)

close() is the hard teardown for true session boundaries (/new, /reset,
session expiry).  It already closes the OpenAI client and child agents but
left the conversation-history list intact.  Mirror the soft-eviction path
(_release_evicted_agent_soft clears _session_messages) so a held reference
to a closed agent — e.g. a draining background task — doesn't pin tens of
MB of tool outputs until the agent object itself is collected.
This commit is contained in:
Teknium 2026-06-08 07:03:39 -07:00 committed by GitHub
parent cb13723f53
commit 5e06c9ffef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3087,6 +3087,17 @@ class AIAgent:
except Exception:
pass
# 6. Free conversation history. Mirrors _release_evicted_agent_soft's
# soft-eviction clear — close() is the hard teardown for true session
# boundaries (/new, /reset, session expiry), so the message list won't
# be reused. Drops the reference proactively rather than waiting for
# the agent object itself to be collected, which matters when a caller
# still holds the closed agent (e.g. a draining background task).
try:
self._session_messages = []
except Exception:
pass
def _hydrate_todo_store(self, history: List[Dict[str, Any]]) -> None:
"""
Recover todo state from conversation history.