Skip to content

feat: fixed calendar windows for day/week/month rate limits #1951 - #1954

Merged
astsiapanay merged 2 commits into
developmentfrom
feat/issue-1951
Sep 11, 2026
Merged

astsiapanay merged 2 commits into
developmentfrom
feat/issue-1951

Conversation

@astsiapanay

Copy link
Copy Markdown
Collaborator

Converts DAY/WEEK/MONTH token, cost, and request-count rate limit windows from a floating (rolling) model to fixed calendar windows anchored to a new deployment-wide rateLimitSchedule setting (timezone, week start day, daily reset time). MINUTE/HOUR keep their existing floating behavior unchanged.

Applicable issues

Description of changes

  • Added rateLimitSchedule top-level config setting (config/RateLimitSchedule.java, WeekDay.java, @ValidTimezone validator) — defaults to UTC/Monday/00:00 if omitted, reproducing today's implicit UTC-midnight day/month behavior.
  • Added CalendarPeriod/CalendarWindowCalculator for DST-safe (ZonedDateTime-based) computation of DAY/WEEK/MONTH period boundaries.
  • Added FixedRateBucket/CostFixedRateBucket (periodStart + count), replacing the sliding-window RateBucket/CostRateBucket for DAY/WEEK/MONTH in TokenRateLimit, CostRateLimit, and the request-count limit's DAY tier; RateWindow is trimmed to MINUTE/HOUR only. Both new bucket types tolerate old floating-window JSON (ignoreUnknown = true), so previously-persisted counters are implicitly reset to zero on first read after rollout — no explicit migration step.
  • Added resetsAt (ISO-8601 offset instant) to ItemLimitStats/CostItemLimitStats, populated only for the fixed windows (DAY/WEEK/MONTH) and omitted (not null) for MINUTE/HOUR, computable even for a deployment with zero usage.
  • RateLimiter now takes a ConfigStore dependency so increase() can resolve the schedule internally without needing a ProxyContext.
  • Updated docs/dynamic-settings/roles.md, regenerated docs/open_api_core.yaml via the project's own OpenAPI generator, and added a rateLimitSchedule example to sample/aidial.config.json.
  • This is a hard cutover per the issue: no config toggle to restore the old floating day/week/month behavior.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Converts day/week/month token/cost/request-count rate limit windows from a
floating (rolling) model to fixed calendar windows anchored to a new
deployment-wide rateLimitSchedule setting (timezone, week start day, daily
reset time). Minute/hour limits keep their existing floating behavior. The
bulk limits/usage endpoints now report a resetsAt instant for each fixed
window. Pre-rollout floating-window records are implicitly treated as zero
usage on first read, with no explicit migration step.
@ai-dial-actions

This comment has been minimized.

@astsiapanay

astsiapanay commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

/deploy-review

GitHub actions run: 34593692685

Stage Status
deploy-review Success ✅
chat Success ✅

@ai-dial-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@astsiapanay
astsiapanay merged commit 4f238a8 into development Sep 11, 2026
9 checks passed
@astsiapanay
astsiapanay deleted the feat/issue-1951 branch September 11, 2026 11:57
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.

Fixed calendar windows for day/week/month rate limits

3 participants