Skip to content

feat(admin): send daily coding plan inventory to Slack - #4922

Merged
jeanduplessis merged 1 commit into
mainfrom
jolly-kestrel
Jul 31, 2026
Merged

feat(admin): send daily coding plan inventory to Slack#4922
jeanduplessis merged 1 commit into
mainfrom
jolly-kestrel

Conversation

@jeanduplessis

@jeanduplessis jeanduplessis commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Send a Slack summary of Coding Plans credential inventory every day at 12:00 UTC.

Why this change is needed

Coding Plans inventory requires regular operational visibility. A daily summary makes available capacity and credentials needing revocation visible without requiring administrators to inspect the Admin UI manually.

How this is addressed

  • Add a server-only Slack notification helper supporting text and Block Kit payloads.
  • Build an inventory summary with total and per-plan counts, friendly plan names, revocation warnings, and a link to the Coding Plans Admin UI.
  • Add an authenticated cron endpoint scheduled for 12:00 UTC every day.
  • Treat a missing webhook as optional configuration: log a warning and complete the cron successfully.
  • Report database, network, and Slack delivery failures as failed cron runs.
  • Keep notifications independent from Admin UI inventory mutations.

Human Verification

  • Confirmed the formatted Block Kit message renders successfully in Slack.
Argus 2026-07-31 14 22 48
Manual Slack verification
  • Sent the proposed inventory fixture through the configured incoming webhook.
  • Confirmed totals, per-plan counts, revocation warnings, and snapshot time render correctly.
  • Replaced the interactive button with a normal Slack link so the message does not require a Slack interactivity URL.

Reviewer Notes

Human Reviewer Flags

  • The report runs as an independent Vercel cron at 0 12 * * *; inventory mutations do not trigger notifications.
  • Missing webhook configuration is intentionally non-fatal. Other delivery failures remain fatal so Vercel and Sentry expose unhealthy runs.
  • The webhook must be configured as the server-only SLACK_ADMIN_NOTIFICATIONS_WEBHOOK_URL secret before deployment.

Code Reviewer Agent

Code Reviewer Notes
  • The cron endpoint uses the existing constant-time CRON_SECRET authorization helper.
  • Slack fetch errors are replaced with sanitized errors because native fetch errors may contain the secret webhook URL.
  • The fallback text field remains available to notifications and assistive clients that do not render Block Kit.
  • Unknown inventory statuses are displayed instead of being silently discarded.

@kilo-code-bot

kilo-code-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the new Slack admin-notification helper, Coding Plans inventory formatter, authenticated daily cron route, env plumbing, and tests; no security, correctness, or reliability defects found in the changed lines (high confidence).

Verification Notes

  • Webhook secret handling: fetch errors are replaced with AdminSlackNotificationError, so the webhook URL cannot leak into logs or Sentry; the response body is drained before the status check.
  • Cron authorization uses the existing constant-time isCronAuthorizationValid helper with the same module-level CRON_SECRET guard as api/cron/coding-plans-billing.
  • getEnvVariable returns '' when unset, so the missing-webhook branch in sendAdminSlackNotification is reached correctly and the cron still succeeds, matching the documented intent.
  • Inventory math checked against getKeyInventoryCounts: loaded sums all statuses, consistent with the Admin UI totalCredentialCount; unknown statuses are surfaced rather than dropped.
  • Slack mrkdwn escaping is applied to block content; unescaped plan names only reach the fallback text, and plan_id/provider_id are catalog-validated in uploadKeysToInventory, so no mrkdwn/link injection path exists.
  • formatSnapshotTime produces YYYY-MM-DD HH:MM UTC for all toISOString() output; Block Kit block/field counts stay well within Slack limits for the current 3-plan catalog.
  • Env var registered in the three expected places (config.server.ts, .env.local.example, ENVIRONMENT.md) and the cron is wired in apps/web/vercel.json at 0 12 * * *.
  • No .md image markup and no landing-page/SEO surface in this diff, so those custom rules do not apply. No new listeners, timers, or unbounded caches were introduced, so no memory-leak risk.
Files Reviewed (10 files)
  • apps/web/src/app/api/cron/coding-plans-inventory-summary/route.ts
  • apps/web/src/app/api/cron/coding-plans-inventory-summary/route.test.ts
  • apps/web/src/lib/coding-plans/inventory-slack-summary.ts
  • apps/web/src/lib/coding-plans/inventory-slack-summary.test.ts
  • apps/web/src/lib/slack/admin-notifications.ts
  • apps/web/src/lib/slack/admin-notifications.test.ts
  • apps/web/src/lib/config.server.ts
  • apps/web/vercel.json
  • .env.local.example
  • ENVIRONMENT.md
Assumptions
  • Tests were not executed (read-only review); assertions were verified by reading the code paths they exercise.
  • SLACK_ADMIN_NOTIFICATIONS_WEBHOOK_URL is assumed to be configured in Vercel before deploy, as stated in the PR description.

Reviewed by claude-opus-5 · Input: 52 · Output: 18.5K · Cached: 1.7M

Review guidance: REVIEW.md from base branch main

@jeanduplessis
jeanduplessis merged commit 1990cf0 into main Jul 31, 2026
18 checks passed
@jeanduplessis
jeanduplessis deleted the jolly-kestrel branch July 31, 2026 12:51
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.

2 participants