fix(hooks): skip summary relay when hook agent turn already delivered#20242
fix(hooks): skip summary relay when hook agent turn already delivered#20242artwist-polyakov wants to merge 1 commit into
Conversation
When dispatchAgentHook calls runCronIsolatedAgentTurn with deliver:true, the isolated run delivers its output via the subagent announce flow or direct outbound payloads. After the run completes, the handler unconditionally posts a summary to the main agent session via enqueueSystemEvent and wakes the heartbeat via requestHeartbeatNow. This causes the main agent to wake up and generate a second response that is also delivered to the target channel, resulting in duplicate messages. Guard the enqueueSystemEvent + requestHeartbeatNow calls behind `!result.delivered`, mirroring the same fix applied to executeJobCore in the cron service path (ea95e88). Fixes openclaw#20196 See also: openclaw#15692 Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
The failing check ( All relevant checks pass:
This PR only changes |
…p NO_REPLY hook context pollution Fixes openclaw#21343 Related: openclaw#20242, openclaw#20199, openclaw#20678
|
This could be relevant to what you're working on. PR #20199 by @zerone0x seems to address the same problem. When a hook agent turn delivered via the announce flow, a duplicate delivery occurred because Both approaches have merit — might be worth coordinating. Related issue(s): #20196 If any of these links don't look right, let me know and I'll correct them. |
Fixes #20196
Summary
enqueueSystemEvent+requestHeartbeatNowindispatchAgentHookbehind!result.delivered, preventing duplicate messages when hook agent turns deliver via the announce flowexecuteJobCorein the cron service path (ea95e88, [Bug]: cron isolated agentTurn with delivery.mode=announce posts duplicate messages with different content (extra agent run triggered) #15692)Problem
When
/hooks/agentis called withdeliver: trueand a specificagentId+totarget, the isolated agent turn delivers the response correctly via the subagent announce flow. However,dispatchAgentHookthen unconditionally posts a summary to the main agent session viaenqueueSystemEventand wakes the heartbeat viarequestHeartbeatNow. This causes the main agent to wake up, process the system event, and generate a second response — resulting in duplicate messages delivered to the target channel (or to the main agent's last active chat).Fix
The
RunCronAgentTurnResult.deliveredflag already exists and is documented:The cron service path (
timer.ts) already honors this flag since ea95e88. This PR applies the same guard to the hooks handler.Test plan
deliver: truetargeting a non-default agent → verify response arrives only in the target chatdeliver: false→ verify summary still posts to main session and heartbeat wakes🤖 Generated with Claude Code