fix(heartbeat): propagate sessionKey in exec/hooks to fix async context loss#1094
Open
BingqingLyu wants to merge 2 commits into
Open
fix(heartbeat): propagate sessionKey in exec/hooks to fix async context loss#1094BingqingLyu wants to merge 2 commits into
BingqingLyu wants to merge 2 commits into
Conversation
…xt loss Exec completion events enqueued under cron or channel-specific session keys were invisible to the heartbeat runner, which always checked the agent's main session key. This caused exec results to silently vanish instead of being relayed back to the originating channel. 1. Propagate sessionKey through scopedHeartbeatWakeOptions in bash exec, ACP spawn, gateway/node exec, and CLI watchdog paths 2. Add resolveEventSessionKey to remap cron session keys to the originating agent's main session key for event enqueueing Scope was previously broader. Dropped per maintainer review feedback on openclaw#50818 (issuecomment-4322767117): - The forceLastTargetWhenNone override for resolveHeartbeatDeliveryTarget, which routed exec completions to the session's last target even when heartbeat.target was explicitly "none". Current main and its regression tests intentionally keep target="none" internal-only, so this routing change is left for a separate focused PR if it is ever revisited. - The openclaw#39978 hook-cancel handling has already shipped via upstream PR openclaw#70258, so it is no longer part of this PR's scope. The PR now closes openclaw#52305 only. Closes openclaw#52305. Related: openclaw#18237. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes openclaw#52305. Related: openclaw#18237, openclaw#14191 (closed as stale).
Async exec completion events silently vanish instead of being relayed to the originating channel. The root cause is a session key mismatch: events are enqueued under cron or channel-specific session keys, but the heartbeat runner always checks the agent's main session key.
Changes
Propagate
sessionKeyin wake requests — exec/hook/ACP paths now passsessionKeythroughscopedHeartbeatWakeOptions(), which scopes agent sessions correctly while preserving unscoped behavior for non-agent keys.Cron session key remapping — new
resolveEventSessionKey()centralizes cron→agent-main remapping for event enqueueing. All affected enqueue sites updated: bash exec runtime, node exec events, ACP spawn stream.Custom
mainKeythreading —scopedHeartbeatWakeOptions()now accepts optionalmainKeyso cron wake targets align with enqueue targets in customsession.mainKeyconfigurations.Exec completion delivery override — when a pending exec completion event is detected,
resolveHeartbeatDeliveryTargetoverridestarget: "none"to fall back to the session's last delivery target, so exec results reach the user. Respects upstream fix(heartbeat): keep exec-event runs on the non-owner tool surface openclaw/openclaw#57652 auth blocking (ForceSenderIsOwnerFalse). Note: this overlaps with fix(auto-reply): restore route replies for exec-event completions openclaw/openclaw#70258'slastChannel/lastTofallback, but operates at the heartbeat-delivery-target layer rather than the auto-reply route-resolution layer — they may be complementary or one may make the other redundant. Verification pending.Exec completion detection — start-anchored regex matching for both
exec finished(gateway/node approval path) andExec completed/failed/killed(backgrounded allowlisted commands). Supports word-based session slugs fromcreateSessionSlug().Test plan
target: nonerelay to last channel withForceSenderIsOwnerFalseresolveEventSessionKeyunit tests: cron remapping with custom mainKeymain(post-fix(auto-reply): restore route replies for exec-event completions openclaw/openclaw#70258), confirm tests still demonstrate uncovered scenarios for [Bug]: async task completion reports can be lost because system event/wake is not reliably session-targeted openclaw/openclaw#52305🤖 Generated with Claude Code