Skip to content

bug: webapp rejects API_RATE_LIMIT_METRICS_BUCKET_SECONDS=15 although the schema says divisors of 60 are valid #4983

Description

@breken-ai

Provide environment information

Not environment-specific: found in the webapp source at main @ c2b7a72 and reproduced with the webapp's own Vitest suite (macOS arm64, pnpm).

Describe the bug

The webapp refuses to start with API_RATE_LIMIT_METRICS_BUCKET_SECONDS=15, although the schema's own rule says 15 is valid.

In apps/webapp/app/env.server.ts:777-785:

API_RATE_LIMIT_METRICS_BUCKET_SECONDS: z.coerce.number().int().positive()
  .multipleOf(10)
  .refine((seconds) => 60 % seconds === 0 || seconds % 60 === 0, {
    message: "must divide or be a multiple of 60 so buckets align to minute boundaries",
  })

The refine accepts any divisor or multiple of 60, which is the alignment the metrics aggregator needs. .multipleOf(10) runs first, though, and rejects the minute-aligned divisors 15 (and 1–6, 12). Environment parsing fails at startup with a Zod "multiple of 10" error.

Expected: 15 (and 120) parse, 7 is still rejected.

Reproduction repo

N/A (schema test against this repo, below)

To reproduce

  1. Set API_RATE_LIMIT_METRICS_BUCKET_SECONDS=15 and start the webapp. Env validation fails.
  2. Or, as a test: parse "15" with the schema entry above. It fails with Number must be a multiple of 10.

Additional information

A fix is ready on the breken-ai/trigger.dev fork (breken/fix-rate-limit-metrics-bucket-validation):

  • It drops the contradictory .multipleOf(10) and moves the schema into app/utils/apiRateLimitMetricsBucketSecondsSchema.ts, so it can be tested.
  • The regression test asserts 15 and 120 parse and 7 fails. It's red on main and green with the fix.
  • Env + new schema tests: 19 passed. oxfmt, oxlint and webapp typecheck are clean.

I'll open it as a draft PR with fixes #<this> once the account is vouched.

Prepared with AI assistance (Claude) from the breken-ai account.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions