fix(agent): preserve user_id when compression spawns continuation session - #32070
fix(agent): preserve user_id when compression spawns continuation session#32070Hewg74 wants to merge 1 commit into
Conversation
…sion The create_session() call in compress_context() did not forward agent._user_id to the new continuation session, so every session spawned by mid-conversation compression lost its user attribution. Result: platform-sourced sessions (telegram/slack/etc) that hit the compression threshold produced NULL user_id 'orphan' sessions even though the underlying human peer was unchanged. Pass agent._user_id (set during agent_init) through to create_session so the user_id lineage survives compression. getattr default of None preserves existing behavior for sessions that never had a user_id (CLI, some test paths).
|
Clean fix. The fallback means existing sessions without a attribute (pre-feature sessions) gracefully default to None rather than raising AttributeError, so this doesn't need a migration or a version gate for stored contexts. One less session attribute to lose on compression. |
|
Minor: the getattr call in the diff uses |
|
Thanks for this — the diagnosis and fix are correct for the rotation path. Context on why we're closing it: as of #52658 (#38763), Rotation now only runs as an explicit opt-out ( |
What does this PR do?
compress_context()inagent/conversation_compression.pyspawns a continuation session viaagent._session_db.create_session(...)but does not passuser_id. Result: every session created by mid-conversation compression lands withuser_id = NULLinstate.db, even though the human peer attached to the parent session is unchanged.This breaks downstream user-scoped queries (Honcho memory provider, peer-attribution logic, any consumer that filters by
user_id). Each compression turns a properly-attributed session into an orphan.The fix is one line: pass
agent._user_idthrough tocreate_session().getattr(agent, "_user_id", None)preserves existing behavior for code paths where_user_idwas never set (CLI, some test paths) — the defaultNonematches what the old call did implicitly.Related Issue
Same class of bug as #24333 (which fixes the equivalent site in
run_agent.pyfor bg/cron/delegate sessions). This PR closes the same hole at the compression site. No issue filed; happy to open one if preferred.Type of Change
Changes Made
agent/conversation_compression.py:393— adduser_id=getattr(agent, "_user_id", None)to thecreate_session()call insidecompress_context().How to Test
Reproduction (without the fix):
user_id(Telegram gateway, Slack gateway, etc.).compress_context()fires.state.db: the parent session hasuser_id = <expected>, the post-compression continuation session hasuser_id = NULL.With the fix: both sessions share the same
user_id.Discovery context: Surfaced while debugging a multi-peer Honcho integration where compressed sessions were silently becoming unattributed even though the Telegram user was unchanged. Tracked to this one line.
Checklist
Code
fix(agent): ...)pytest tests/ -qand all tests pass — couldn't run full suite from contributor environment; the change is isolated and pattern-matches fix(agent): propagate user_id to session-row creation for bg/cron/delegate sessions #24333. Happy to add a regression test mirroringtests/agent/test_session_user_id.pyif maintainers want one.Documentation & Housekeeping