Conversation
… context map Fixes issue #149: concurrent requests from different channels (e.g. Telegram arriving while a sub-agent is running) were misattributed because a single global _session_context_force flag caused ALL proxy requests to use the forced session context, not just the ones belonging to that sub-agent window. Replace the boolean flag with _forced_session_contexts: dict[str, dict] keyed by session_key. POST /session with force:true + session_key stores the override in the map; requests carrying a matching X-AgentWeave-Session-Key header use that entry. Unkeyed concurrent requests are completely unaffected. The global _session_context_force flag is kept for backward compatibility with callers that don't supply a session_key (legacy path). Also strips X-AgentWeave-Session-Key from upstream-forwarded headers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Prevents slow memory leak when bridge plugins orphan forced-context entries (e.g. crash mid sub-agent window). Switches the map to an OrderedDict and adds _set_forced_context that evicts the oldest entry once size exceeds _MAX_FORCED_CONTEXTS. Follow-up to PR #169 review. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
_session_context_force: boolwith_forced_session_contexts: dict[str, dict[str, str]]keyed bysession_keyPOST /sessionwithforce: true+session_keystores the override in the per-key map; the global force flag is not set, so concurrent requests from other channels are unaffectedX-AgentWeave-Session-Keyfrom incoming requests and looks up the matching forced context; unkeyed requests see neither the forced context nor its session/agent attributionX-AgentWeave-Session-Keyis added to_SKIP_HEADERS_ALWAYSso it is never forwarded upstreamsession_key) preserved for backward compatibility — global_session_context_forcestill works as beforeTest plan
test_session_key_stores_in_forced_map— POST with force+key stores in map, does NOT set global flagtest_session_key_clear_removes_from_map— POST with force:false+key removes the entrytest_unkeyed_request_not_affected_by_forced_key— request without session-key header ignores the forced context, uses its own request headerstest_keyed_request_uses_forced_context— request with matching session-key header picks up the forced agent_id/session_idtest_session_key_header_stripped_from_forwarding— header is in_SKIP_HEADERS_ALWAYStest_legacy_force_without_key_still_works— no session_key → global flag set as beforeCloses #149
🤖 Generated with Claude Code