fix(plugins): expose ephemeral sessionId in tool contexts for per-conversation isolation#31304
Closed
Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Closed
fix(plugins): expose ephemeral sessionId in tool contexts for per-conversation isolation#31304Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Conversation
…versation isolation The plugin tool context (`OpenClawPluginToolContext`) and tool hook context (`PluginHookToolContext`) only provided `sessionKey`, which is a durable channel identifier that survives /new and /reset. Plugins like mem0 that need per-conversation isolation (e.g. mapping Mem0 `run_id`) had no way to distinguish between conversations, causing session-scoped memories to persist unbounded across resets. Add `sessionId` (ephemeral UUID regenerated on /new and /reset) to: - `OpenClawPluginToolContext` (factory context for plugin tools) - `PluginHookToolContext` (before_tool_call / after_tool_call hooks) - Internal `HookContext` for tool call wrappers Thread the value from the run attempt through createOpenClawCodingTools → createOpenClawTools → resolvePluginTools and through the tool hook wrapper. Closes openclaw#31253 Made-with: Cursor
Contributor
Greptile SummaryAdded ephemeral
Confidence Score: 5/5
Last reviewed commit: 09834bd |
18 tasks
Member
Member
18 tasks
Member
|
Superseding this with #32273 so we can land the full follow-up scope on top of current What #32273 carries forward from this PR:
What #32273 adds to complete runtime propagation:
Thanks @Sid-Qin for the original #31304 implementation and groundwork. |
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
OpenClawPluginToolContextandPluginHookToolContext) only providesessionKey, which is a durable channel identifier (e.g.agent:main:telegram:direct:5263871946) that survives/newand/reset. Plugins like mem0 that need per-conversation isolation have no way to distinguish between conversations, causing session-scoped memories to grow unbounded.sessionId(the ephemeral UUID regenerated on/newand/reset) was available in the agent context (PluginHookAgentContext) but missing from tool contexts. Plugins registering tools viaregisterToolfactories could only accesssessionKey.sessionIdtoOpenClawPluginToolContext,PluginHookToolContext, and the internalHookContextfor tool call wrappers. Threaded the value from the run attempt throughcreateOpenClawCodingTools->createOpenClawTools->resolvePluginToolsand through thewrapToolWithBeforeToolCallHookwrapper.sessionKeyremains available for durable channel identification. All new fields are optional and backward-compatible.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
registerTool) now receivectx.sessionId(ephemeral UUID) in addition toctx.sessionKey(durable channel ID).before_tool_callandafter_tool_callhook contexts now includesessionId.sessionIdasrun_idto properly isolate session-scoped memories per conversation.Security Impact (required)
NoNoNoNoNo(sessionId is already available in agent contexts)Repro + Verification
Environment
registerToolSteps
ctx.sessionIdfrom its factory context/newto start a new conversationctx.sessionIdchanged between conversationsExpected
sessionIdchanges on/newand/reset, enabling per-conversation isolationsessionKeyremains the same (durable channel ID)Actual
sessionIdwas not available in tool contexts; plugins could only usesessionKeysessionIdis available and changes per conversationEvidence
New test case in
openclaw-tools.plugin-context.test.ts:forwards ephemeral sessionId to plugin tool context- verifies sessionId is passed throughHuman Verification (required)
Compatibility / Migration
YesNoNoFailure Recovery (if this breaks)
sessionIdfields from the 3 context types and 3 call sites. All additive changes.src/plugins/types.ts,src/agents/pi-tools.before-tool-call.ts,src/agents/pi-tools.ts,src/agents/openclaw-tools.ts,src/agents/pi-embedded-runner/run/attempt.tsRisks and Mitigations