fix(session-notification): add grace period to prevent late events from cancelling idle notifications#2376
Conversation
…om cancelling idle notifications
|
All contributors have signed the CLA. Thank you! ✅ |
|
Hi @crazyrabbit0! Thank you for your contribution in #2012 — the grace period implementation is solid and addresses a real race condition in the idle notification system. I created this new PR instead of updating the original because:
Additional changes I made on top of your work:
Could you please sign the CLA so we can get this merged? You can do so by following the instructions in the above comment. Thanks again for the fix! 🙌 |
There was a problem hiding this comment.
No issues found across 4 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: The PR introduces a 100ms grace period that changes cancellation behavior for fast activity and includes a dependency update in the lockfile, which prevents 100% certainty of no regressions.
|
I have read the CLA Document and I hereby sign the CLA |
|
Thank you again @crazyrabbit0! Sorry for the back-and-forth confusion with the different PRs and where to sign, but we did it in the end. Your contributions are much appreciated! I will merge this once all checks finish |
Fixes #2012 (rebased, conflicts resolved, additional fixes applied)
Summary
Fixed a bug where session notifications appeared on user interrupt but not when the agent idled naturally. Added a configurable grace period to ignore late-arriving activity events that incorrectly cancelled pending notifications.
Root Cause
When the agent idles naturally:
session.idlefires → notification scheduled (1500ms delay)message.updatedwith final metadata,tool.execute.after)markSessionActivity()which cancels the notificationWhen user interrupts:
session.idlefires → notification scheduledSolution
Add a grace period (default 100ms) after scheduling a notification. Activity events arriving within this window are ignored—they're stale events from before the idle state, not genuine user activity.
Changes
Original PR by @crazyrabbit0:
src/hooks/session-notification-scheduler.tsscheduledAtMap to track when notifications are scheduledactivityGracePeriodMsconfig option (default: 100ms)markSessionActivity()to ignore activity within grace periodscheduledAtstatesrc/hooks/session-notification.test.tsactivityGracePeriodMs: 0Additional fixes:
devto resolve merge conflictsactivityGracePeriodMstoSessionNotificationConfiginterface for type safetyTesting
All 18 tests pass.
Summary by cubic
Fixes idle notifications not showing on natural idle by adding a short grace period that ignores late activity events.
Bug Fixes
Dependencies
Written for commit 9b4c826. Summary will update on new commits.