Skip to content

LAM-1287: Add notification logging to ClickHouse and Slack subscription for reports#1395

Open
laminar-coding-agent[bot] wants to merge 4 commits intodevfrom
agent/lam-1287-03cf96
Open

LAM-1287: Add notification logging to ClickHouse and Slack subscription for reports#1395
laminar-coding-agent[bot] wants to merge 4 commits intodevfrom
agent/lam-1287-03cf96

Conversation

@laminar-coding-agent
Copy link
Contributor

@laminar-coding-agent laminar-coding-agent bot commented Mar 13, 2026

Summary

  • ClickHouse notification_log table: New migration (27) creates notification_log table to record every email and Slack notification with full details (recipient, subject, body, status, error) for auditing and inspection. Records are ordered by (workspace_id, created_at) with a 90-day TTL.
  • Notification logging in app-server: NotificationHandler now writes a log entry to ClickHouse after each email/Slack send, capturing both successes and failures per recipient. Added workspace_id to NotificationMessage for queryability.
  • Slack report delivery: Report generator now sends Slack notifications (formatted with Block Kit) alongside emails when Slack targets are configured. Added ReportSummary variant to SlackMessagePayload and get_report_target_slack_channels DB query.
  • Frontend Slack subscription for reports: Reports UI now shows both an email toggle and a Slack channel selector per report. Uses discriminated-union Zod schemas for type-safe opt-in/opt-out of EMAIL and SLACK target types. Slack integration card shown when not connected.

Changed files

Backend (Rust)

  • app-server/src/ch/notification_log.rs — new CH insert module for notification_log
  • app-server/src/ch/mod.rs — register notification_log module
  • app-server/src/db/reports.rs — add get_report_target_slack_channels query
  • app-server/src/notifications/mod.rs — add ClickHouse logging after send, add workspace_id to message
  • app-server/src/notifications/slack.rs — add ReportSummary payload variant with Block Kit formatting
  • app-server/src/reports/generator.rs — push Slack notifications for reports alongside emails
  • app-server/src/main.rs — pass ClickHouse client to NotificationHandler
  • app-server/src/signals/postprocess.rs — add workspace_id field to notification message

Frontend (TypeScript)

  • frontend/lib/clickhouse/migrations/27_notification_log.sql — new ClickHouse migration
  • frontend/lib/actions/reports/index.ts — discriminated union schemas for EMAIL/SLACK opt-in/opt-out
  • frontend/components/workspace/reports/index.tsx — add Slack integration, channels, and handlers
  • frontend/components/workspace/reports/reports-list.tsx — email toggle + Slack channel selector per report
  • frontend/components/workspace/workspace.tsx — pass Slack props to reports component

Test plan

  • Verify ClickHouse migration applies on startup (notification_log table created)
  • Send a report email and verify a row appears in notification_log with channel=email
  • Configure a Slack target for a report and verify Slack message is delivered
  • Verify notification_log row for Slack delivery with channel=slack
  • Test email opt-in/opt-out from reports UI
  • Test Slack channel subscribe/unsubscribe from reports UI
  • Verify removing Slack integration cleans up report Slack targets

🤖 Generated with Claude Code


Note

Medium Risk
Adds new ClickHouse writes in the notification hot path and expands report delivery to Slack; failures or schema mismatches could affect notification processing and increase operational load.

Overview
Adds notification auditing by introducing a ClickHouse notification_log table (90-day TTL) and writing per-send entries for both email and Slack, including success/error status, recipient, and rendered body/blocks.

Extends report delivery to support Slack: report generation now reads Slack targets, enqueues report_slack messages with a new SlackMessagePayload::ReportSummary (Block Kit formatting), and the notifications worker now carries workspace_id on NotificationMessage (resolved for alerts and passed through for reports).

Updates the reports UI and API payloads to manage both email and Slack subscriptions: per-report email toggle plus Slack channel selector/unsubscribe, with server-side Zod validation via discriminated unions and one Slack channel enforced per report.

Written by Cursor Bugbot for commit d015d79. This will update automatically on new commits. Configure here.

…on for reports

- Add ClickHouse `notification_log` table (migration 27) to record every
  email and Slack notification with recipient, subject, body, status, and
  error details for auditing and inspection.
- Update NotificationHandler to write to ClickHouse after each send,
  capturing both successes and failures per recipient.
- Add `workspace_id` field to NotificationMessage so logs can be queried
  per workspace.
- Add Slack report targets: new `get_report_target_slack_channels` query
  in db/reports.rs and `ReportSummary` variant in SlackMessagePayload
  with formatted Block Kit messages.
- Update report generator to push Slack notifications alongside emails
  when Slack targets are configured for a report.
- Update frontend reports UI to show both email toggle and Slack channel
  selector per report, backed by discriminated-union Zod schemas for
  opt-in/opt-out of EMAIL and SLACK target types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use uncontrolled Select so the same channel can be re-selected after
unsubscribing. Previously selectedChannelId local state was never reset,
preventing Radix onValueChange from firing on re-selection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

olzhik11 and others added 2 commits March 13, 2026 19:24
Set notification_type to "report" or "alert" based on event_name prefix
instead of duplicating event_name. This allows filtering the audit log
by notification category as intended.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Look up workspace_id from project_id via a lightweight DB query so
signal alert notifications are logged with the correct workspace_id
in ClickHouse, making them queryable by workspace.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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