Skip to content

Internal hooks not triggered in auto-reply path due to missing sessionKey parameter #29203

@dotberrnix

Description

@dotberrnix

Problem Description

Summary

Internal hooks are not being triggered with message:sent events when messages are sent through the auto-reply path, despite hooks being correctly registered and configured.

Evidence

  1. Hook Registration: ✅ Successful
[hooks:loader] Registered hook: glm5-token-tracker -> message:sent
[hooks] loaded 5 internal hook handlers
  1. Message Delivery: ✅ Successful
[telegram] sendMessage ok chat=-5270945987 message=6269
  1. Hook Execution: ❌ Not triggered
  • No [glm5-token-tracker] logs in gateway.log
  • No data written to tracking files
  • Other bundled hooks (command-logger, session-memory) also not working

Root Cause Analysis

Traced through source code:

File: dist/reply-D-ejYZny.js (Line 23308)

await deliverOutboundPayloads({
  cfg,
  channel: deliveryChannel,  // "telegram"
  to: deliveryTarget,
  payloads: deliveryPayloads,
  agentId: deliveryAgentId,
  // ...
  // ⚠️ Missing parameters:
  // - sessionKey
  // - mirror
});

File: dist/deliver-B2A1_Ib0.js (Line ~100)

const sessionKeyForInternalHooks = params.mirror?.sessionKey ?? params.sessionKey;

if (!sessionKeyForInternalHooks) return;  // ⚠️ Hook not triggered

triggerInternalHook(...);

Impact

  • All internal hooks listening to message:sent events fail
  • Bundled hooks affected:
    • command-logger (command events)
    • session-memory (command:new, reset events)
  • Channels affected: All (Telegram, WhatsApp, Discord, Signal, etc.)

Workaround

Currently using plugin system as alternative, which works independently of hooks.

Questions

  1. Is this a design decision or a bug?
  2. What is the expected behavior?
    • Should hooks trigger in auto-reply path?
    • Or should documentation clarify this limitation?
  3. Are there plans to fix this?
  4. Should sessionKey be passed in deliverAgentCommandResult?

Environment

  • OpenClaw version: 2026.2.23
  • Node.js version: v22.22.0
  • macOS: Darwin 22.6.0
  • Channels: Telegram

Additional Context

I've created a demo hook to track token usage, which correctly registers but never executes. Other users may encounter similar issues with bundled hooks not working.

Related Code

  • HTTP API path provides sessionKey: dist/gateway-cli-BlDZ_8TO.js (Line 12415-12450)
  • Auto-reply path does NOT: dist/reply-D-ejYZny.js (Line 23308)

Proposed Fix

Add sessionKey parameter in deliverAgentCommandResult:

// In reply-D-ejYZny.js around line 23213
const deliveryAgentId = opts.agentId ?? (opts.sessionKey ? resolveSessionAgentId({
    sessionKey: opts.sessionKey,
    config: cfg
}) : void 0);

await deliverOutboundPayloads({
    cfg,
    channel: deliveryChannel,
    to: deliveryTarget,
    payloads: deliveryPayloads,
    agentId: deliveryAgentId,
    sessionKey: opts.sessionKey,  // ✅ Add this line
    // ... existing parameters ...
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions