Skip to content

fix(web): restore Snowflake usage analytics - #5656

Merged
pandemicsyn merged 1 commit into
mainfrom
restore-snowflake-usage
Aug 28, 2026
Merged

fix(web): restore Snowflake usage analytics#5656
pandemicsyn merged 1 commit into
mainfrom
restore-snowflake-usage

Conversation

@pandemicsyn

Copy link
Copy Markdown
Contributor

Summary

  • Reverse Revert "Revert "feat(web): serve /usage analytics from Postgres replica"" #5229 (d83bf8e687d161e8bb0955b110ed986e049ca64b) to restore Snowflake-backed personal and organization Usage summaries, timeseries, breakdowns, and tables.
  • Remove the dedicated PostgreSQL Usage pool and restore ordinary read distribution across both configured EU replicas. Preserve the independent replica-error handling fix and existing scope authorization/user lookups.
  • Resolve the later feat(ai-gateway): add managed OpenAI BYOK on Vercel #5333 BYOK conflict using SUM(user_byok_request_count), preserving the current user-provided-key definition rather than reverting to upstream/managed-provider BYOK counts.
  • Treat missing Snowflake configuration as unavailable instead of returning misleading zero/empty usage. Keep the improved error/retry UI and log only fixed failure categories, not raw upstream error bodies.

Warehouse contract checked

Current dbt source has separate byok_request_count and user_byok_request_count aggregates in both models:

This confirms the source contract, not the deployed warehouse state or credentials.

Validation

  • pnpm --filter web test --runInBand --runTestsByPath src/routers/usage-analytics-router.test.ts src/lib/drizzle.test.ts src/lib/ai-gateway/providers/vercel/index.test.ts — 3 suites, 87 tests passed against local test PostgreSQL; Snowflake calls mocked.
  • pnpm --filter web lint
  • pnpm --filter web typecheck
  • pnpm format on the four changed files and git diff --check
  • Independent code review; raw error-body logging concern resolved.
  • Before merge, verify the existing web-app Snowflake credentials can query both deployed rollups, including user_byok_request_count, and that required data is current.
  • Verify representative personal/organization Usage in the preview or staging environment.

Scope

Only #5229 is reversed. This does not restore leaderboard endpoints deleted by #5233, remove the availability banner, re-enable Snowflake replication alerts, rotate credentials, or change the external replication connector. No production credentials or live Snowflake data were accessed.

Revert #5229 (d83bf8e), retaining user BYOK semantics through Snowflake's user_byok_request_count rollup. Surface unavailable configuration instead of zero usage, avoid logging upstream response bodies, and cover the restored queries with regression tests.
@kilo-code-bot

kilo-code-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • apps/web/src/lib/drizzle.ts
  • apps/web/src/lib/drizzle.test.ts
  • apps/web/src/routers/usage-analytics-router.ts
  • apps/web/src/routers/usage-analytics-router.test.ts

Reviewed by grok-4.6 · Input: 222.3K · Output: 24.6K · Cached: 1M

Review guidance: REVIEW.md from base branch main

@pandemicsyn
pandemicsyn merged commit 7ab1e52 into main Aug 28, 2026
23 checks passed
@pandemicsyn
pandemicsyn deleted the restore-snowflake-usage branch August 28, 2026 16:30
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