Skip to content

feat(insights): harden investigations, revenue, and delivery#565

Open
izadoesdev wants to merge 11 commits into
stagingfrom
codex/insights-investigation-hardening
Open

feat(insights): harden investigations, revenue, and delivery#565
izadoesdev wants to merge 11 commits into
stagingfrom
codex/insights-investigation-hardening

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Jul 15, 2026

Copy link
Copy Markdown
Member

Deployment gate

Do not deploy the application before the additive PostgreSQL schema is present.

  1. Verify there is no organization with more than one active insight run.
  2. Apply the PostgreSQL schema additions:
    • insight_generation_configs.dispatch_due_at
    • autumn_webhook_events
    • usage_alert_log.organization_id
    • the database default for insight_run_items.config_snapshot
    • links_org_created_at_id_idx
    • the partial uniqueness/index changes included in the schema
  3. Backfill recent null usage-alert ownership only where organization ownership is unambiguous. Drain old replicas, and retain the dual legacy/org cooldown lock and null-row compatibility for at least seven days.
  4. Deploy the API, producers, and versioned queue consumers together. Keep the scheduled dispatcher and workers disabled by default.
  5. Run one manual staging investigation, then enable a small canary allowlist before any wider rollout.

This PR performs no destructive ClickHouse DDL. The two legacy hourly vitals objects remain an explicit, approval-gated cleanup for existing clusters.

What changed

  • Replaces open-ended insight generation with a deterministic evidence → policy → bounded synthesis → lifecycle pipeline.
  • Makes insight identity, comparisons, evidence coverage, retirement, and delivery replay-safe.
  • Produces short, specific cards with measured facts, concrete next steps, and explicit missing context.
  • Normalizes payment events and fixes revenue reconciliation, attribution, currency handling, sparse delivery, and refund ownership.
  • Hardens Autumn ingestion, usage-alert cooldowns, scheduler claims, queue versioning, Slack retries, URLs, webhook verification, and process failure behavior.
  • Corrects identity, funnel, link pagination, uptime, and vitals edge cases.
  • Removes retired prompt/tool/config paths and keeps the organization-level configuration surface intentionally small.
  • Enforces generated ClickHouse schema parity and documents deferred physical migrations.

Quality evidence

  • bun run lint: 1,587 files clean.
  • bun run check-types: 37/37 tasks pass.
  • bun run test: 28/28 tasks pass; AI 3,995 pass / 27 integration skips; zero failures.
  • bun run eval:insights: 14 timelines, 17 stages, 9 insights, zero gate failures; deterministic across repeats.
  • Full read-only production shadow: 23 sites × 4 historical dates, repeated; 92 cases, 38 cards, zero detection failures, 100% repeat agreement, p95/max visible length 56 words.
  • Final top-site production shadow: 16 cases, 6 cards, zero failures/incomplete/truncation, 100% repeat agreement, p95/max 41 words.
  • Disposable PostgreSQL, Redis, and ClickHouse integrations passed for scheduler/idempotency, Autumn inbox, votes/compatibility, revenue, identity, funnels, and custom events.
  • Independent red-team, release-blocker, and fresh-diff reviews found no remaining verified P0/P1/P2 code defects after fixes.

Rollout posture

The scheduler and workers stay off by default. Start with a manually inspected staging run, then a small canary. Destructive ClickHouse cleanup and the larger physical revenue-table migration are intentionally deferred.


Summary by cubic

Hardens the insights pipeline, revenue reporting, and payment diagnostics: deterministic investigations, replay‑safe billing ingestion, and safer delivery with clearer UI and docs. Rollout is gated behind new env flags with a canary allowlist.

  • New Features

    • Deterministic insights flow with idempotent scheduling, queue versioning, recovery, and replay‑safe delivery; honors Slack Retry‑After without a 5s cap and prevents duplicate worker claims.
    • Autumn webhook inbox + replay loop with leases, backoff, dead‑letter retention, and maintenance to replay deferred events, prune completed/dead letters, and alert once.
    • Stripe webhook normalization (apps/basket/src/routes/webhooks/stripe-normalization.ts) unifies sales, subscriptions, refunds, failure reasons, and attribution; revenue UI adds currency‑aware formatting/filters with a neutral fallback for invalid configs; payment failure diagnostics are scoped to active filters and only shown when data is available.
    • Safer boundaries: request‑id sanitization, strict auth callback path validation, bulk flags API limits (max 100 keys, 128‑char keys, capped query length) with private, no-store caching, and non‑reflective validation errors in production.
    • Scheduling + tests: dispatch gated by INSIGHTS_SCHEDULED_DISPATCH_ENABLED and INSIGHTS_SCHEDULED_ORGANIZATION_IDS; rollup/run tie‑breakers and recovery sweeps added; investigation upgrades (custom‑event disappearance, currency‑scoped revenue signals, revenue‑transaction confirmation); ClickHouse test doubles isolated for reliability.
  • Migration

    • PostgreSQL (additive): insight_generation_configs.dispatch_due_at, autumn_webhook_events, usage_alert_log.organization_id, default for insight_run_items.config_snapshot, links_org_created_at_id_idx, plus included partial unique/index changes.
    • Env: INSIGHTS_SCHEDULED_DISPATCH_ENABLED=false, INSIGHTS_SCHEDULED_ORGANIZATION_IDS="" (comma‑separated IDs); keep workers off by default and enable via allowlist after a manual staging run.

Written for commit ecd1173. Summary will update on new commits.

Review in cubic

@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Too many files changed for review. (208 files found, 100 file limit)

Bypass the limit by tagging @greptile-apps to review.

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
databuddy-status Ready Ready Preview, Comment Jul 15, 2026 12:08pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
dashboard Skipped Skipped Jul 15, 2026 12:08pm
documentation Skipped Skipped Jul 15, 2026 12:08pm

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 60f22dc3-8848-432e-a44f-c8ed8b04c8bf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/insights-investigation-hardening

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@unkey-deploy

unkey-deploy Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Unkey Deploy

Name Status Preview Inspect Updated (UTC)
api (preview) Ready Visit Preview Inspect Jul 15, 2026 12:08pm

@vercel vercel Bot temporarily deployed to Preview – documentation July 15, 2026 12:01 Inactive
@vercel vercel Bot temporarily deployed to Preview – dashboard July 15, 2026 12:01 Inactive
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