fix: route system-event-triggered heartbeats to configured session#1542
Open
BingqingLyu wants to merge 12 commits into
Open
fix: route system-event-triggered heartbeats to configured session#1542BingqingLyu wants to merge 12 commits into
BingqingLyu wants to merge 12 commits into
Conversation
Change __migrated from a boolean to a per-run migrationId (UUID) so that skip-restore only removes events migrated by the current run. Events tagged by a prior failed run are left intact, preventing silent data loss when an earlier migration didn't fully drain before a later skip.
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
System-event-triggered heartbeats (e.g. from exec
notifyOnExit) were running in the originating session instead of the configuredheartbeat.session. This caused heartbeat duties to execute inside active DM conversations, polluting the session with unrelated memory updates and email checks.Root Cause
In
resolveHeartbeatSession(), theforcedSessionKey(originating session) was checked before the configuredheartbeat.session. When an exec completion system event triggered an immediate heartbeat, the originating DM session was passed asforcedSessionKeyand always won over the user's explicit session config.Fix
1. Session resolution priority reorder (
heartbeat-runner.ts)heartbeat.sessionconfig is now resolved beforeforcedSessionKey, so the user's explicit configuration always wins. When noheartbeat.sessionis configured, behavior falls back toforcedSessionKeyas before.2. Cross-session event migration (
heartbeat-runner.ts)When the resolved heartbeat session differs from the originating session, pending system events are migrated:
session-maintenancewarnings) stay in the originating session — identified viacontextKeyskipDedup: trueto bypass consecutive-duplicate suppressionmigrationIdvia the__migratedfield onSystemEventtrustedflag is preserved through migration3. Skip-restore path (
heartbeat-runner.ts)When a heartbeat is skipped after migration (e.g. empty
HEARTBEAT.md), migrated events are restored to the originating session:migrationIdare removed from the heartbeat sessioncontextKey+textare not confused with migrated events thanks to stable__migratedidentity4. Wake-trigger event tagging (multiple files)
System events are now tagged with
contextKeyat their source to enable migration classification:bash-tools.exec-runtime.ts→contextKey: "exec"cli-runner/execute.ts→contextKey: "cli:watchdog"server-methods/system.ts→contextKey: "system"server-restart-sentinel.ts→contextKey: "restart"server/hooks.ts→contextKey: "hook"session-maintenance-warning.ts→contextKey: "session-maintenance"5. System event infrastructure (
system-events.ts)skipDedup?: booleantoSystemEventOptions— bypasses consecutive-duplicate guard for cross-session migration__migrated?: stringtoSystemEventandSystemEventOptions— stable per-run migration identity markerTests
New test file
heartbeat-runner.session-routing.test.tscovering:forcedSessionKeywhen no session configuredFixes openclaw#41165