fix(hooks): thread agentId into after_tool_call hook context#30527
Closed
scoootscooob wants to merge 2 commits intoopenclaw:mainfrom
Closed
fix(hooks): thread agentId into after_tool_call hook context#30527scoootscooob wants to merge 2 commits intoopenclaw:mainfrom
scoootscooob wants to merge 2 commits intoopenclaw:mainfrom
Conversation
3 tasks
Contributor
Greptile SummaryThis PR successfully threads
This enables third-party plugins (like Confidence Score: 5/5
Last reviewed commit: fa819f4 |
The after_tool_call hook in handleToolExecutionEnd was passing `sessionKey: undefined` in the ToolContext, even though the value is available on ctx.params. This broke plugins that need session context in after_tool_call handlers (e.g., for per-session audit trails or security logging). - Add `sessionKey` to the `ToolHandlerParams` Pick type - Pass `ctx.params.sessionKey` through to the hook context - Add test assertion to prevent regression Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Follow-up to openclaw#30511 — the after_tool_call hook context was passing `agentId: undefined` because SubscribeEmbeddedPiSessionParams did not carry the agent identity. This threads sessionAgentId (resolved in attempt.ts) through the session params into the tool handler context, giving plugins accurate agent-scoped context for both before_tool_call and after_tool_call hooks. Changes: - Add `agentId?: string` to SubscribeEmbeddedPiSessionParams - Add "agentId" to ToolHandlerParams Pick type - Pass `agentId: sessionAgentId` at the subscribeEmbeddedPiSession() call site in attempt.ts - Wire ctx.params.agentId into the after_tool_call hook context - Update tests to assert agentId propagation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fa819f4 to
aad01ed
Compare
18 tasks
Member
Member
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
Follow-up to #30511 — threads
agentIdthrough the session params chain so theafter_tool_callhook context receives the resolved agent identity instead ofundefined.agentId?: stringtoSubscribeEmbeddedPiSessionParams"agentId"to theToolHandlerParamsPick typesessionAgentId(resolved inattempt.tsviaresolveSessionAgentIds()) at thesubscribeEmbeddedPiSession()call sitectx.params.agentIdinto theafter_tool_callhook context (replacing hardcodedundefined)Motivation
Third-party plugins (e.g.
openclaw-plimsoll-security) usectx.agentIdin bothbefore_tool_callandafter_tool_callhooks for agent-scoped audit trails and per-agent security policies. Without this fix,agentIdis alwaysundefinedin the hook context, forcing plugins to fall back tosessionKeyor a hardcoded default.Test plan
wired-hooks-after-tool-call.test.ts— assertscontext.agentIdequals the provided valueagentIdisundefinedwhen not provided (no-agentId path)tsc --noEmit)Files changed
src/agents/pi-embedded-subscribe.types.tsagentId?: stringfieldsrc/agents/pi-embedded-subscribe.handlers.types.ts"agentId"toToolHandlerParamsPicksrc/agents/pi-embedded-runner/run/attempt.tsagentId: sessionAgentIdtosubscribeEmbeddedPiSession()src/agents/pi-embedded-subscribe.handlers.tools.tsctx.params.agentIdinto hook contextsrc/plugins/wired-hooks-after-tool-call.test.tsDepends on #30511.
🤖 Generated with Claude Code