Skip to content

KI-Aufrufe begrenzen (#343) - #345

Merged
rrolf merged 4 commits into
mainfrom
feature/ai-throttle
Nov 20, 2026
Merged

rrolf merged 4 commits into
mainfrom
feature/ai-throttle

Conversation

@rrolf

@rrolf rrolf commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Closes #343

Per-user rate limits for all staff-triggered AI endpoints.

What's in it

  • Two DRF throttle scopes (common/throttling.py), per signed-in user, staff exempt:
    • ai — generation (start/retry, one hit per job, not per chunk), distractors, rephrase, proofread, matrix/mindmap AI, word-cloud optimize, free-text summary/evaluation, AI run report. Default 120/hour (AI_THROTTLE_RATE).
    • ai_vision — AI alt-text suggestion. Default 30/hour (AI_VISION_THROTTLE_RATE).
    • off disables a scope; invalid values fall back to the default with a warning (no 500).
  • Rejected before any model call (DRF initial()); status/polling and cancel/review endpoints untouched. Not counted: participant-triggered AI (self-check grading, live word cloud incl. its presenter on/off toggle) — bounded by votes and server-side single-flight.
  • 429 with a translated detail („Sie haben die KI gerade sehr oft genutzt. Bitte versuchen Sie es in N Minuten erneut.“, singular-aware) and Retry-After (rounded up); every AI UI shows it (the walkthrough free-text summary no longer swallows it).
  • Log: one WARNING per rejection on abstimmbar.ai (scope + user id, no content).
  • Config/docs: env in dev + prod compose and .env.prod.example; deployment docs DE/EN (incl. per-process cache note), CHANGELOG.

Verification (isolated stack)

  • common.tests_throttling 13/13 (every throttled endpoint rejected before the model, staff bypass both scopes, off, invalid rates, singular message, Retry-After, word cloud not counted, log)
  • Backend suites common/live/rooms 1785 OK (full suite 2249 OK before the fix wave); ruff clean
  • Frontend tsc -b OK; e2e ai-throttle.spec.ts 1/1
  • mkdocs strict DE + EN OK
  • Task reviews, whole-branch review + re-review of its fix wave

🤖 Generated with Claude Code

rrolf and others added 4 commits November 20, 2026 00:27
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Walkthrough free-text summary shows the 429 message instead of the generic
"unavailable" text; env vars in compose files and .env.prod.example; docs
(DE/EN) and changelog; e2e for a throttled rephrase.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- wordcloud_ai no longer counted (presenter toggles it automatically)
- rejection logged at WARNING; invalid rates fall back to the default
- Retry-After rounded up; staff bypass tested for ai_vision

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rrolf
rrolf merged commit 1b6cad0 into main Nov 20, 2026
6 checks passed
@rrolf
rrolf deleted the feature/ai-throttle branch November 20, 2026 17:01
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.

KI-Aufrufe begrenzen (Throttle für alle KI-Endpunkte)

1 participant