Repository navigation
feat(llm-analytics): dedicated rate limit for prompt fetch endpoints - #108384
Conversation
|
😎 Merged successfully - details. |
🤖 CI report
|
| First copy | Second copy | Lines | Tokens |
|---|---|---|---|
posthog/api/llm_prompt.py:120 |
products/skills/backend/api/skills.py:591 |
13 | 78 |
✅ Duplication (TypeScript) — clean
New TypeScript code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.
|
[Medium risk] The PR appears safe to merge, with a non-blocking concern about sustained use of expensive list queries. Reviews (1) · Last reviewed commit: "feat(llm-analytics): dedicated rate limi..." |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: PostHog/posthog/.coderabbit.yaml Review profile: QUIET Plan: Enterprise Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review. 📝 WalkthroughWalkthroughThe Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to Prompt fetches now have a dedicated per-key 600-per-minute limit, with publishing and other API throttle behavior unchanged. No material merge-blocking risk was found; proceed with normal checks. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Prompt reads gain a higher sustained allowance. Access remains tied to existing credentials and project permissions, but the higher allowance could increase backend load, particularly for searches and resolved lists. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Approved.
Contained, reversible throttle change on read-only prompt fetch endpoints. It uses the same base class as the throttles it replaces, is covered by a parameterized test, and the author is on the owning team.
- Author wrote 0% of the modified lines and has 52 merged PRs in these paths (familiarity MODERATE).
- 👍 on the PR from greptile-apps[bot].
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 22L, 2F substantive, 39L/3F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1b-small (39L, 3F, single-area, feat) |
| stamphog 2.3.0 | .stamphog/policy.yml @ 7040b9a · reviewed head 7040b9a |
Problem
SDK clients that poll prompts on a fixed interval hit the shared API budget's sustained cap (4,800/hour) and get 429s, even after batching every poll into one
get_all()request. A fleet polling every 5 minutes reaches the cap at around 400 processes. Internal metrics show several teams' prompt fetches rejected by this cap over the last 30 days.Feature flags solved the same problem for
remote_configwith a dedicated per-minute throttle.Changes
update_by_name) keeps its existing stricter throttles.Design rationale: the limit is per-minute only because polling is steady, not bursty; an hourly cap is what rejects a fleet that polls on an interval. This copies the
feature_flag_remote_configthrottle shape. A prompt fetch is a cheap indexed Postgres read that the SDK caches for 300 seconds, so the endpoint does not need the general API budget's protection.Nothing user-visible changes except fewer 429s for SDK prompt polling.
How did you test this code?
Extended the existing
get_throttlestests intest_llm_prompt.py: one parameterized test over the three fetch actions asserts each uses exactly the dedicated throttle. It catches a regression that routes prompt fetches back onto the shared budget, which silently reintroduces the hourly cap.Not tested: an end-to-end 429 at the 601st request in a minute. The counting is DRF
SimpleRateThrottlebehavior already exercised by the framework and by existing throttles.Automatic notifications
Docs update
The public rate limiting docs live in posthog.com; a follow-up PR there will document the dedicated prompt fetch limit.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Agent: Claude Code, Fable 5 (claude-fable-5)
Skills invoked: /wt, /improving-drf-endpoints, /writing-tests, /writing-code-comments, /reviewing-with-coderabbit, /writing-pr-descriptions.
CodeRabbit CLI: signed out; the user chose to skip the local pass, so the PR opened without one.
Duplicate search found no open PR touching prompt fetch rate limiting. The limit was sized against production request metrics for the prompt fetch views reviewed during the session. The work originates from customer feedback about prompt polling 429s; no customer material appears in the diff or this description.