Closed
Description
Description
The message:sent internal hook (hooks.internal.handlers) stops firing after a Discord WebSocket reconnect event (close code 1005). The hook module is loaded at gateway startup and works correctly until a WebSocket disconnection occurs. After the gateway auto-reconnects, the hook never fires again for the remainder of the process lifetime.
Reproduction
- Configure an internal hook handler for
message:sentinopenclaw.json:
"hooks": {
"internal": {
"enabled": true,
"handlers": [
{
"event": "message:sent",
"module": "hooks/my-hook.mjs"
}
]
}
}- Add debug logging to the hook to confirm it fires:
import("node:fs").then(fs => {
fs.appendFileSync("/tmp/openclaw-hook-debug.log",
`[${new Date().toISOString()}] hook fired\n`
);
});- Send messages — hook fires correctly ✅
- Wait for a Discord WebSocket disconnect (code 1005) — these happen naturally every few hours
- After reconnect, send messages — hook never fires again ❌
Evidence
Debug log from production:
# Hook fires normally through 7:45 AM UTC
[2026-03-26T14:45:52.118Z] hook fired: type=message action=sent sessionKey=agent:main:discord:channel:...
# WebSocket crash at 7:34 AM PDT (14:34 UTC):
[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
# Zero hook fires from 7:45 AM onward despite 5+ hours of active conversation
Gateway log shows 5 WebSocket disconnects (code 1005) between 3:58 AM and 7:34 AM PDT. After the final reconnect, the hook module is effectively dead.
Expected Behavior
Internal hook handlers should survive WebSocket reconnects. Either:
- Re-register handlers after reconnection, or
- Ensure the event emitter pipeline remains intact across reconnects
Environment
- OpenClaw version: 2026.3.24
- Node: v22.22.0
- OS: macOS 23.6.0 (x64)
- Channel: Discord (WebSocket-based)
Workaround
Manual observer calls (fire-and-forget HTTP POST) as a fallback — but this is discretionary and defeats the purpose of the forced hook pattern.
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Priority
None yet
Activity
steipete commentedon Apr 25, 2026
Closing this as implemented after Codex review.
Current main already has the hook-runtime and Discord reconnect cleanup needed for this report: internal hook registrations are now process-global, outbound delivery still dispatches
message:sent, and the Discord 1005 reconnect-exhausted path is covered by supervisor/lifecycle regression tests. The shipped changelog also records the hook-registry stability fix, so this looks implemented rather than an open current-main bug.What I checked:
internal-hooks.tsstores handler registrations in aglobalThissingleton so registration and dispatch stay aligned even if bundling creates duplicate module copies. (src/hooks/internal-hooks.ts:189, 95b7a85f0607)triggerInternalHook()reads the shared registry and invokesmessage:sentlisteners without any reconnect-specific reset path. (src/hooks/internal-hooks.ts:286, 95b7a85f0607)message:sent: Outbound delivery continues to calltriggerInternalHook(createInternalHookEvent("message", "sent", ...))for sent messages. (src/infra/outbound/deliver.ts:648, 95b7a85f0607)extensions/discord/src/monitor/gateway-supervisor.test.ts:107, 95b7a85f0607)globalThissingleton so hook registration/dispatch remain consistent across duplicate module copies, which matches this symptom pattern. (CHANGELOG.md:3829, a9797214338b)So I’m closing this as already implemented rather than keeping a duplicate issue open.
Review notes: reviewed against 95b7a85f0607; fix evidence: release v2026.4.23, commit a9797214338b.