Skip to content

fix(backend): rate-limit GET /v1/personas/twitter/initial-message (#12781) - #12784

Merged
kodjima33 merged 1 commit into
mainfrom
watchdog/issue-12781-twitter-initial-message-rate-limit
Sep 5, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
watchdog/issue-12781-twitter-initial-message-rate-limit

Conversation

@kodjima33

@kodjima33 kodjima33 commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

GET /v1/personas/twitter/initial-message runs a billable, tracked LLM call (track_usage(uid, Features.PERSONA)) but had neither a quota gate nor a rate limit -- the only billable route in backend/routers/apps.py with neither (per #12781's own audit table). track_usage only attributes spend, it does not block, so a free user past the monthly cap could call it indefinitely.

This wires the same rate limiter its sibling generate-prompts already has: auth.with_rate_limit(auth.get_current_user_uid, "apps:twitter_initial_message"), 30/hour, matching apps:generate_prompts. Whether persona spend should also count against the chat quota is a separate billing-policy question the issue explicitly defers to a maintainer -- this PR only adds the request bound, per the issue's own "cheapest correct step" framing.

Test plan

  • Added test_twitter_initial_message_endpoint_rate_limited in backend/tests/unit/test_rate_limiting.py (fails on main, passes with this diff), and updated test_all_router_policies_exist / test_apps_router_has_rate_limit for the new policy.
  • Ran backend/tests/unit/test_rate_limiting.py: 85 passed, 1 skipped (unrelated fakeredis-only test, skips without the optional dependency on both main and this branch).

Failure-Class: none

Line-Count-Exception: backend/routers/apps.py | 2468 -> 2471 | multi-line Depends() signature to fit the new rate-limit wrapper call within the line-length limit; no logic added beyond the one new Depends() dependency

🤖 automated by hourly watchdog — tested and merged

Review in cubic

…2781)

This is the only billable route in backend/routers/apps.py with neither
a quota gate nor a rate limit: it runs a tracked LLM call
(track_usage(uid, Features.PERSONA)) but track_usage only attributes
spend, it does not block, so a free user past the monthly cap could
call it indefinitely.

Wire the same rate limiter its sibling generate-prompts already has
(auth.with_rate_limit(..., "apps:twitter_initial_message"), 30/hour,
matching apps:generate_prompts). Whether persona spend should also
count against the chat quota is a separate billing-policy question the
issue explicitly leaves to a maintainer -- this only adds the request
bound, per the issue's own "cheapest correct step" framing.

Tested: added test_twitter_initial_message_endpoint_rate_limited
(fails on main, passes with this diff) plus updated
test_all_router_policies_exist / test_apps_router_has_rate_limit. Ran
the full backend/tests/unit/test_rate_limiting.py suite: 85 passed, 1
skipped (unrelated fakeredis-only test).

Failure-Class: none

🤖 automated by hourly watchdog — tested and merged

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@kodjima33
kodjima33 merged commit 2cdb89f into main Sep 5, 2026
42 checks passed
@kodjima33
kodjima33 deleted the watchdog/issue-12781-twitter-initial-message-rate-limit branch September 5, 2026 07:44
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