Skip to content

[ef-38] feat: add SessionEnd hook + fix Notification policy in example#39

Merged
NiveditJain merged 1 commit into
mainfrom
ef-38-notification-session-end
Apr 7, 2026
Merged

[ef-38] feat: add SessionEnd hook + fix Notification policy in example#39
NiveditJain merged 1 commit into
mainfrom
ef-38-notification-session-end

Conversation

@NiveditJain

@NiveditJain NiveditJain commented Apr 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Add slack-on-session-end policy for SessionEnd events in the notification example
  • Await fetch with AbortSignal.timeout(5000) so Slack requests complete before process.exit() is called
  • Return instruct() instead of allow() so Claude knows the notification was sent
  • Remove the idle-only filter — the handler now fires on all notification types

Test plan

  • Set SLACK_WEBHOOK_URL and run failproofai p -i -c examples/policies-notification.js; let Claude go idle — confirm Slack message arrives
  • Exit a Claude session with the hook active — confirm session-end Slack message arrives
  • Unset SLACK_WEBHOOK_URL — confirm both policies return allow() silently

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Slack notifications now posted for idle events and session end events
    • Enhanced notification reliability with timeout protection and improved error handling

- Add `slack-on-session-end` policy for SessionEnd events
- Await fetch with AbortSignal.timeout(5000) so requests complete before process.exit()
- Return instruct() instead of allow() so Claude knows the notification was sent
- Remove idle-only filter — notify on all notification types

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 58761858-4319-4bee-beb4-94ad24a5fa74

📥 Commits

Reviewing files that changed from the base of the PR and between 799025a and 830539a.

📒 Files selected for processing (1)
  • examples/policies-notification.js

📝 Walkthrough

Walkthrough

Updated an example policy file to enhance Slack notifications by replacing fire-and-forget fetch calls with awaited requests that include 5-second timeouts and error handling. Added a new policy rule to notify Slack on SessionEnd events, and modified the idle notification handler to always post messages and return instruct() instead of allow().

Changes

Cohort / File(s) Summary
Notification Handler Enhancement
examples/policies-notification.js
Modified idle notification handler to remove type filtering, post to Slack with timeout/retry logic, and return instruct(). Added new slack-on-session-end policy rule for SessionEnd events with similar awaited Slack posting and error-swallowing pattern.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop-hop, the notifications now flow,
With Slack messages reaping what our sessions sow,
No more fire-and-forget, we await with grace,
SessionEnd and Idle both find their place,
A timeout of five brings peace to our race! 🔔


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@NiveditJain NiveditJain merged commit bf8b7e3 into main Apr 7, 2026
8 checks passed
@NiveditJain NiveditJain deleted the ef-38-notification-session-end branch April 21, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant