feat(hooks): add session:patch hook event to listen for session changes#23910
Closed
graciegould wants to merge 1864 commits intoopenclaw:mainfrom
Closed
feat(hooks): add session:patch hook event to listen for session changes#23910graciegould wants to merge 1864 commits intoopenclaw:mainfrom
graciegould wants to merge 1864 commits intoopenclaw:mainfrom
Conversation
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
sessions.patchcalls, preventing integrations from reacting to session property changesSessionsPatchParamsSchema. This hook allow users to sync session metadata to their dashboards, databases, and workflows.session:patchinternal hook event that fires whensessions.patchRPC is called, following a similar pattern asmessage:*events (feat(hooks): bridge plugin message hooks to internal hooks system #9387)Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
message:sent/message:receivedevents (feat(hooks): bridge plugin message hooks to internal hooks system #9387)User-visible / Behavior Changes
Users can now create hooks that listen for
session:patchevents.Hook event context:
Available patch fields (from
SessionsPatchParams):label,model,thinkingLevel,verboseLevel,reasoningLevelresponseUsage,elevatedLevelexecHost,execSecurity,execAsk,execNodespawnedBy,spawnDepth,sendPolicy,groupActivationExample hook:
Common use cases:
Security Impact
Environment
Evidence
Code changes:
src/gateway/server-methods/sessions.ts- 9 lines (hook trigger)docs/automation/hooks.md- ~60 lines (documentation + examples)src/gateway/server.sessions.gateway-server-sessions-a.e2e.test.ts- 150 lines (3 new tests)Tests:
Verified:
Compatibility
Risks
Risk: User hooks could call
sessions.patchrecursivelyMitigation: Documented in hooks.md to avoid (same as
message:sentpattern)Risk: Expensive hook operations could slow patch responses
Mitigation: Hooks run async, don't block RPC response
Meta
Greptile Summary
This PR adds a
session:patchinternal hook event that fires when session properties are modified via thesessions.patchRPC. The implementation follows the established pattern for hook events (similar tomessage:sent/message:receivedfrom #9387) and correctly integrates with the existing security boundary that blocks WebChat clients from patching sessions (PR #20800).Key changes:
src/gateway/server-methods/sessions.tsafter successful patch (9 lines)docs/automation/hooks.mdwith TypeScript types and examples (~60 lines)Implementation is sound:
Minor observation:
The PR description example code shows
patch.key, but sinceevent.sessionKeyis available directly on the event object, that would be the cleaner approach. However, this is only in the PR description - the actual documentation example correctly avoids this pattern.Confidence Score: 5/5
Last reviewed commit: f831d03
(2/5) Greptile learns from your feedback when you react with thumbs up/down!