Skip to content

fix: include sessionKey in session_start/session_end hook context#23525

Closed
p697 wants to merge 1 commit intoopenclaw:mainfrom
p697:fix/session-hook-add-sessionkey
Closed

fix: include sessionKey in session_start/session_end hook context#23525
p697 wants to merge 1 commit intoopenclaw:mainfrom
p697:fix/session-hook-add-sessionkey

Conversation

@p697
Copy link

@p697 p697 commented Feb 22, 2026

Problem

PluginHookSessionContext (used by session_start and session_end hooks) was missing sessionKey, while other hook context types like PluginHookAgentContext already included it. This made it impossible for plugins to call session-scoped APIs such as enqueueSystemEvent from session lifecycle hooks.

Changes

  • Add sessionKey?: string to PluginHookSessionContext type definition
  • Pass sessionKey in both runSessionStart and runSessionEnd calls in session.ts
  • Update wired-hooks-session.test.ts to verify sessionKey is forwarded

Use Case

Plugins that need to inject system messages on session start (e.g., reminding the agent to read context files after /new or /reset) currently cannot do so because enqueueSystemEvent requires a sessionKey that the hook context doesn't provide.

Testing

  • npx vitest run src/plugins/wired-hooks-session.test.ts — 3/3 passed
  • npx vitest run src/auto-reply/reply/session.test.ts — 34/34 passed
  • npx tsc --noEmit — no new errors

Greptile Summary

Added sessionKey to PluginHookSessionContext to enable session-scoped API calls like enqueueSystemEvent from session_start and session_end hooks. This aligns session hook contexts with other hook contexts (PluginHookAgentContext and PluginHookToolContext) which already include sessionKey.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is a straightforward addition of an optional field to a context type with corresponding implementation and test updates. The field aligns with existing patterns in other hook contexts, tests pass, and the use case is well-documented
  • No files require special attention

Last reviewed commit: 2fd6979

(4/5) You can add custom instructions or style guidelines for the agent here!

Copy link
Contributor

@arosstale arosstale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct fix. session_start and session_end hooks were missing sessionKey in the payload, making it impossible for plugins to correlate hook events back to a specific session or routing context. Import ordering cleanup is cosmetic but welcome.

@p697
Copy link
Author

p697 commented Feb 22, 2026

Thanks @arosstale! Good catch on the import ordering — that was actually unintentional. Our local oxfmt was on 0.32.0 while CI uses 0.34.0, so the pre-commit hook reformatted imports with the wrong rules. Updated to 0.34.0 and pushed a fix.

The PluginHookSessionContext type was missing sessionKey, making it
impossible for plugins to use session-scoped APIs (e.g.
enqueueSystemEvent) from session lifecycle hooks.

- Add sessionKey to PluginHookSessionContext type
- Pass sessionKey in runSessionStart and runSessionEnd calls
- Update tests to verify sessionKey is forwarded
@p697 p697 force-pushed the fix/session-hook-add-sessionkey branch from 7db7482 to 90379df Compare February 22, 2026 12:21
@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Feb 28, 2026
@openclaw-barnacle
Copy link

Closing due to inactivity.
If you believe this PR should be revived, post in #pr-thunderdome-dangerzone on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

@openclaw-barnacle openclaw-barnacle bot closed this Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XS stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants