openclaw - 💡(How to fix) Fix Plugin hooks (before_agent_start, agent_end) don't fire for per-channel-peer sessions [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#56760Fetched 2026-04-08 01:48:06
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Timeline (top)
commented ×1

Fix Action

Workaround

Switch dmScope to "main" — all DMs route through the main session where hooks fire normally. Downside: all users share the same session context window.

RAW_BUFFERClick to expand / collapse

Bug

When session.dmScope is set to per-channel-peer, plugin hooks (before_agent_start, agent_end) never fire for the per-channel-peer sessions (e.g. agent:main:telegram:direct:<user_id>). They only fire for:

  • agent:main:main (base session)
  • agent:main:cron:* (cron-spawned sessions)

This means plugins like openclaw-mem0 cannot perform recall injection or post-conversation capture for per-channel-peer DM sessions — the primary use case for multi-user bots.

Reproduction

  1. Set "session": { "dmScope": "per-channel-peer" } in openclaw.json
  2. Configure openclaw-mem0 with autoCapture + autoRecall enabled
  3. Have a user send DMs to the Telegram bot
  4. Observe gateway logs:
    • injecting N memories and capture ran entries appear ONLY for agent:main:main and agent:main:cron:*
    • Zero plugin hook events for agent:main:telegram:direct:<user_id> despite active conversation (3.1MB transcript)

Expected behavior

Plugin hooks should fire for all session types, including per-channel-peer sessions.

Workaround

Switch dmScope to "main" — all DMs route through the main session where hooks fire normally. Downside: all users share the same session context window.

Environment

  • OpenClaw version: 2026.3.24
  • Plugin: openclaw-mem0 (open-source mode)
  • Channel: Telegram
  • Node: v22.22.1
  • macOS

extent analysis

Fix Plan

To fix the issue, we need to modify the plugin hook system to fire for per-channel-peer sessions.

  • Update the openclaw-mem0 plugin to listen for session events on all session types, not just the base session.
  • Modify the before_agent_start and agent_end hooks to check the session ID and handle per-channel-peer sessions accordingly.

Example code:

// In openclaw-mem0 plugin
const sessionEvents = require('openclaw').sessionEvents;

// Listen for session events on all session types
sessionEvents.on('session:start', (session) => {
  if (session.id.startsWith('agent:main:telegram:direct:')) {
    // Handle per-channel-peer session start
    console.log(`Per-channel-peer session started: ${session.id}`);
    // Perform recall injection and post-conversation capture
  }
});

sessionEvents.on('session:end', (session) => {
  if (session.id.startsWith('agent:main:telegram:direct:')) {
    // Handle per-channel-peer session end
    console.log(`Per-channel-peer session ended: ${session.id}`);
    // Perform post-conversation capture
  }
});

Verification

To verify the fix, follow these steps:

  1. Update the openclaw-mem0 plugin with the modified code.
  2. Set "session": { "dmScope": "per-channel-peer" } in openclaw.json.
  3. Configure openclaw-mem0 with autoCapture and autoRecall enabled.
  4. Have a user send DMs to the Telegram bot.
  5. Observe gateway logs for injecting N memories and capture ran entries for per-channel-peer sessions.

Extra Tips

  • Make sure to test the fix thoroughly to ensure that plugin hooks fire correctly for all session types.
  • Consider adding logging or debugging statements to verify that the modified code is executing as expected.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Plugin hooks should fire for all session types, including per-channel-peer sessions.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Plugin hooks (before_agent_start, agent_end) don't fire for per-channel-peer sessions [1 comments, 2 participants]