fix: routed-agent context management not respecting history, summarization, compression, and seahorse bootstrap - #3316
Open
j-v wants to merge 4 commits into
Open
Conversation
…orse) Issue sipeed#3301: routed-chat sessions are invisible to the context managers because both resolve the owning agent via GetDefaultAgent() instead of resolving per-session ownership. Legacy tests (context_manager_test.go): TestLegacyAssemble_RoutedAgent (Assemble must read from routed store), TestLegacyCompact_Summarize_RoutedAgent (maybeSummarize against routed store), TestLegacyCompact_Overflow_RoutedAgent (forceCompression drops oldest turns in routed store, default store untouched). Seahorse test (context_seahorse_test.go): TestSeahorseBootstrap_RoutedAgent (constructor must import pre-existing history for all registered agents, not just default). These fail against the current code and pass once the fixes land.
Legacy: Assemble, maybeSummarize, and forceCompression all read from the default agent's session store via GetDefaultAgent(), so routed-agent sessions were stateless: history never loaded, summarization never triggered, and emergency compression operated on the wrong store. Resolve the owning agent with agentForSession (same as Clear already does). Seahorse: the constructor bootstrapped pre-existing history only from the default agent's store, so routed sessions started with empty context on the first seahorse turn. Bootstrap all registered agents' stores, passing the owning store into bootstrapSession.
This was referenced Aug 3, 2026
|
This PR has had no activity for 7 days and has been marked as stale. If you are still working on it, please push an update or leave a comment; otherwise it will be closed automatically in 7 days. |
Author
|
Still active |
This was referenced Aug 11, 2026
This was referenced Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📝 Description
Bug: I set up dispatch rules to route an agent to a specific discord channel, and noticed it wasn't remembering anything from previous messages, and auto-compaction never triggered regardless of the number of messages or tokens used in the session for that agent & channel.
This PR fixes routed-agent context management so that per-agent context (history, summarization, compression, and seahorse bootstrap) operates on the owning agent's session store instead of the default agent's.
For sessions owned by a routed (non-default) agent, three code paths incorrectly used
registry.GetDefaultAgent():context_legacy.go—Assemble: read history/summary from the default agent's store, so routed agents always saw empty history (the bug reported in [BUG] /clear and session auto-compression don't work in chats routed to non-default agent via dispatch rules #3301).context_legacy.go—maybeSummarize/forceCompression: summarization and overflow compression ran against the default agent's store, leaving the routed agent's context unbounded and uncompressed.context_seahorse.go— constructor: bootstrapped only the default agent's sessions, so routed agents never got their session metadata initialized.Fix:
Assemble,maybeSummarize, andforceCompressionnow resolve the owning agent viaagentForSession(sessionKey)(the same patternClearalready used), with fallback to the default agent preserved when the session can't be resolved.registry.ListAgentIDs()), passing the owning store intobootstrapSession.Tests: 4 repro tests added covering routed-agent Assemble, summarize, overflow-compression, and seahorse bootstrap — each failed against the old code and passes with the fix.
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
Fixes #3301
📚 Technical Context (Skip for Docs)
agentForSession) were being serviced by the default agent's context store in three paths:Assemble(history reads),maybeSummarize/forceCompression(compaction writes), and the seahorse constructor (session bootstrap). For any deployment with routed agents this meant empty history on every turn, no summarization/compaction, and uninitialized seahorse session metadata. The fix follows the existingClearpattern: resolve the owning agent per-session and fall back to the default agent only when unresolvable.🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
Full CI run (fork validation before opening this PR) — all green:
Checks: Tests ✅, Linter ✅, Integration ✅, Security ✅, Cross-Compile (linux/arm64) ✅, gitleaks ✅
☑️ Checklist