← Back to PRs

#18972: Fix #18880: Drop pending notifications when cron job is deleted

by jwchmodx open 2026-02-17 07:09 View on GitHub →
size: S
## Problem When a cron job is deleted, pending system-event notifications (enqueued with `contextKey: 'cron:<jobId>'`) remained in the in-memory queue and continued to be delivered on subsequent heartbeats. This caused 20+ duplicate completion notifications after job deletion. ## Solution - Added `dropSystemEventsByContextKey()` to `system-events.ts` that removes all queued events matching a given contextKey across all session queues - Called it from `remove()` in `cron/service/ops.ts` to purge stale notifications immediately when a job is deleted - Added tests for the new function Fixes #18880 <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes duplicate notification issue by clearing pending system events when cron jobs are deleted. The implementation adds `dropSystemEventsByContextKey()` that removes all queued events matching a specific contextKey across all session queues, then calls it from the cron job removal function with the job's contextKey pattern (`cron:${id}`). Tests cover single-session and multi-session cleanup scenarios. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The implementation is straightforward and correct - it properly normalizes contextKeys for case-insensitive matching, handles edge cases (empty queues, no matches), and includes comprehensive tests. The fix is well-scoped to the specific problem without affecting other functionality. - No files require special attention <sub>Last reviewed commit: 149b474</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs