Skip to content

Require analytics limiter configuration in production - #8009

Merged
lawrencecchen merged 3 commits into
mainfrom
task-fix-analytics-events-5xx
Jul 14, 2026
Merged

lawrencecchen merged 3 commits into
mainfrom
task-fix-analytics-events-5xx

Conversation

@lawrencecchen

@lawrencecchen lawrencecchen commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • require the analytics Firewall rule ID during Vercel production builds
  • cover the production environment contract with a red-then-green regression test
  • document the live incident evidence and configuration recovery in the investigation

Testing

  • cd web && bun test tests/client-config-env.test.ts tests/analytics-events-route.test.ts
  • cd web && bun run typecheck
  • production POST /api/analytics/events with an empty batch returns 200 after enabling the cmux-analytics Firewall rule and environment variable
  • local Next.js server on port 9400 returns 200 for /, /handler/sign-in, redirected /handler/after-sign-in, and an empty analytics batch

Issues


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Require CMUX_ANALYTICS_RATE_LIMIT_ID for Vercel production only; keep it optional for development and preview. Adds tests to enforce this and prevent 5xxs on POST /api/analytics/events.

  • Migration
    • Set CMUX_ANALYTICS_RATE_LIMIT_ID in Vercel production to the analytics Firewall rule ID and ensure the rule is enabled.
    • No changes needed for Vercel development or preview.

Written for commit 8eb9f64. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened production deployment environment validation to require the analytics rate-limit setting.
    • Preview deployments remain allowed without this additional configuration.
    • Improved failure behavior so missing production settings report the specific missing variable clearly.
  • Tests
    • Updated and expanded environment validation tests to cover both required-production and allowed-development scenarios.

@vercel

vercel Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
cmux Ready Ready Preview, Comment Jul 14, 2026 1:16am

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

CMUX_ANALYTICS_RATE_LIMIT_ID now uses conditional Vercel production validation. Production tests require the variable, verify failure when omitted, and confirm development deployments may omit it.

Changes

Analytics rate-limit validation

Layer / File(s) Summary
Production rate-limit requirement
web/app/env.ts, web/tests/client-config-env.test.ts
The analytics rate-limit ID is required for Vercel production deployments, while preview and development configurations may omit it; tests cover valid, missing, and development configurations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: austinywang, azooz2003-bit


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Cmux User-Facing Error Privacy ❌ Error env.ts emits a stderr validation error with the internal env var name and Vercel provider, which the rule forbids for user-facing command output. Replace the message with product-neutral wording (e.g. "A required production configuration value is missing.") and update the stderr assertion accordingly.
✅ Passed checks (24 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Cmux Swift Actor Isolation ✅ Passed PR only changes web env validation/tests; no Swift files or actor-isolation-sensitive code were modified.
Cmux Swift Blocking Runtime ✅ Passed No Swift files changed in the PR; the diff only updates web/app/env.ts and a TS test, so the Swift blocking-runtime rule is not implicated.
Cmux Browser Automation Off-Main ✅ Passed Diff only touches env validation and its tests; no browser.* automation, WebKit/AppKit routing, or socket-worker policy code was changed.
Cmux Expensive Synchronous Load ✅ Passed No Swift files changed; the diff only touches web env/tests, so the expensive synchronous Swift load rule is not applicable.
Cmux Cache Substitution Correctness ✅ Passed The diff only tightens env validation/tests; it doesn't replace any fresh authoritative read with a cached/opportunistic value in a persistence/history path.
Cmux No Hacky Sleeps ✅ Passed The diff only changes env validation and tests; it adds no sleeps, timers, polling, or wall-clock waits.
Cmux Algorithmic Complexity ✅ Passed The PR only adds constant-time env checks in web/app/env.ts and test updates; no scalable collection scans or hot-path complexity changes were introduced.
Cmux Swift Concurrency ✅ Passed Diff only changes web/app/env.ts and a web test; no Swift files or concurrency patterns are present, so the Swift modernization check is not applicable.
Cmux Swift @Concurrent ✅ Passed The PR only changes web/app/env.ts and a web test; no Swift files are in the diff, so the Swift concurrent-annotation check is not applicable.
Cmux Swift File And Package Boundaries ✅ Passed Diff only changes web TypeScript files; no Swift files or package-boundary issues are present.
Cmux Swiftpm Lockfiles ✅ Passed PR only changes web/app/env.ts and a test file; no SwiftPM/Xcode/.gitignore/workflow/dependency files are in the diff, so the lockfile rule doesn’t apply.
Cmux Swift Logging ✅ Passed Diff only touches web TypeScript and tests; no Swift runtime code or logging APIs were added or changed.
Cmux Full Internationalization ✅ Passed The PR only changes env validation and tests; it adds no user-facing UI, metadata, locale, or message-catalog text requiring translation.
Cmux Swiftui State Layout ✅ Passed The PR diff only changes web/app/env.ts and a web test; no Swift files or SwiftUI state/layout changes are present, so the rule is not applicable.
Cmux Architecture Rethink ✅ Passed PASS: The PR only changes TypeScript env validation and tests; no Swift files or Swift lifecycle/architecture changes are present, so the Swift-specific rule doesn't apply.
Cmux Swift Auxiliary Window Close Shortcuts ✅ Passed PASS: The diff only touches web/app/env.ts and web/tests/client-config-env.test.ts; no Swift/window code is changed, so the auxiliary-window shortcut rule is not applicable.
Cmux Source Artifacts ✅ Passed Only hand-written source and test files changed; no artifact, cache, temp, or build-output paths appear in the diff.
Cmux No Test Or Debug Seam In Production Source ✅ Passed Diff only changes web/app/env.ts and web/tests/client-config-env.test.ts; no Swift production Sources/ files were touched, so the seam rule is not applicable.
Cmux No Ambient Global State ✅ Passed PASS: The PR only changes web/app/env.ts and its test; no Swift files or new app-scope state/singletons are in the diff, so the Swift-only ambient-global-state rule doesn't apply.
Title check ✅ Passed The title accurately summarizes the main change: requiring analytics limiter config in production.
Description check ✅ Passed The description covers the main Summary and Testing needs and provides incident context, with only some noncritical template sections missing.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task-fix-analytics-events-5xx

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.

@greptile-apps

greptile-apps Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR requires analytics limiter configuration for Vercel production deployments. The main changes are:

  • Adds production-only validation for CMUX_ANALYTICS_RATE_LIMIT_ID.
  • Keeps Vercel development and preview deployments exempt.
  • Adds tests for production success, production failure, and development success.

Confidence Score: 5/5

This looks safe to merge.

  • The production check now excludes Vercel development deployments.
  • Tests cover the corrected development case and both production outcomes.
  • No blocking issue remains in the updated code.

Important Files Changed

Filename Overview
web/app/env.ts Adds production-specific Vercel validation for the analytics limiter ID.
web/tests/client-config-env.test.ts Covers production and development behavior for analytics limiter validation.

Reviews (2): Last reviewed commit: "Keep analytics limiter optional in Verce..." | Re-trigger Greptile

Comment thread web/app/env.ts Outdated
CMUX_FEEDBACK_RATE_LIMIT_ID: z.string().min(1),
CMUX_CLIENT_CONFIG_RATE_LIMIT_ID: requireVercelNonPreviewValue("CMUX_CLIENT_CONFIG_RATE_LIMIT_ID"),
CMUX_ANALYTICS_RATE_LIMIT_ID: z.string().min(1).optional(),
CMUX_ANALYTICS_RATE_LIMIT_ID: requireVercelNonPreviewValue("CMUX_ANALYTICS_RATE_LIMIT_ID"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Development Deployments Require Production Rule

When VERCEL="1" and VERCEL_ENV="development", this helper requires CMUX_ANALYTICS_RATE_LIMIT_ID even though the intended contract is production-only. The local environment loader does not provide this analytics rule ID, so Vercel development processes that load app/env.ts can fail validation and prevent unrelated routes from initializing.

Suggested change
CMUX_ANALYTICS_RATE_LIMIT_ID: requireVercelNonPreviewValue("CMUX_ANALYTICS_RATE_LIMIT_ID"),
CMUX_ANALYTICS_RATE_LIMIT_ID: z.string().min(1).optional().superRefine((value, context) => {
if (process.env.VERCEL === "1" && process.env.VERCEL_ENV === "production" && !value) {
context.addIssue({
code: z.ZodIssueCode.custom,
message: "CMUX_ANALYTICS_RATE_LIMIT_ID is required for Vercel production runtimes",
});
}
}),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 8eb9f64. The analytics env validator now targets Vercel production only, while the existing client-config validator keeps its non-preview contract. A subprocess test covers VERCEL_ENV=development without the analytics rule ID.

— Claude Code

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/app/env.ts`:
- Line 40: Update the environment-validation message in the relevant
`web/app/env.ts` diagnostic to use product-neutral wording without exposing the
environment-variable name or deployment provider, while retaining exact
configuration details only in internal diagnostics. Update the corresponding
stderr assertion to match the sanitized message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: bdf732db-4849-4efb-b5f6-da7b8bb17487

📥 Commits

Reviewing files that changed from the base of the PR and between c3f2f2f and 8eb9f64.

📒 Files selected for processing (2)
  • web/app/env.ts
  • web/tests/client-config-env.test.ts

Comment thread web/app/env.ts
@lawrencecchen
lawrencecchen merged commit 3e68d79 into main Jul 14, 2026
34 checks passed
@lawrencecchen
lawrencecchen deleted the task-fix-analytics-events-5xx branch July 14, 2026 01:28

This branch was successfully deployed

1 active deployment
Preview – cmux — 8eb9f646 Deployed Jul 14, 2026 by vercel[bot]
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