Skip to content

fix(backend): cap GET /v1/action-items at 12/min per uid - #11965

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
Git-on-my-level:fix/action-items-list-rate-limit
Aug 22, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
Git-on-my-level:fix/action-items-list-rate-limit

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Cap first-party GET /v1/action-items at 12 requests / 60s / uid via existing with_rate_limit (Redis, multi-instance). Rejects in Depends() before Firestore.

Old Windows main-process taskSyncEngine listed this route in a tight loop (~120 qps fleet) with only Authorization — no X-App-Platform / X-App-Version, so a version gate cannot see it. A global 429 would also hit Mac/mobile.

12/min is above Mac/Flutter hydrate + a few pagination pages; a tight loop dies after 12 calls.

Does not force clients to update. /ids census is unchanged.

Failure-Class

Failure-Class: none

Root Cause

Windows main-process listing storm on GET /v1/action-items with no client version header. Instrumented action_items_list was ~1k/day because Cloud Run backend is not scraped.

How to Verify

  1. Unit: test_action_items_list_caps_tight_loops and existing router-policy scan.
  2. After deploy: 429 with Retry-After on the 13th listing GET in a minute for one uid; Firestore read ops on this route should fall.

Test Plan

  • Policy tuple test
  • Existing test_rate_limiting router scan (CI)
  • Prod: listing 429s for a hot uid; Mac/Flutter hydrate still works

Risk Assessment

Medium — legitimate rapid pagination >12/min gets 429 for the rest of the window. First-party limiter fail-opens if Redis is down. /ids and writes are not capped by this policy.

Review in cubic

Old Windows main-process listing stormed this route (~120 qps fleet)
without X-App-Platform/X-App-Version. Reuse with_rate_limit so Redis
rejects before Firestore.

Failure-Class: none

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backend bug fix, confidence 5/5: real production incident (Windows listing storm), scoped diff (12 lines), CI green, test added, mirrors existing rate-limit pattern. Confirmed not fixed on main.

@kodjima33
kodjima33 merged commit c622d3d into BasedHardware:main Aug 22, 2026
34 checks passed
Git-on-my-level added a commit that referenced this pull request Aug 26, 2026
The (12, 60) per-uid cap on `action_items:list` shipped in #11965, but the
serving revision carries RATE_LIMIT_BOOST=100, so get_effective_limit()
resolves it to 1,200/60s and it has never fired once. Meanwhile ~82 stale
omi-windows/1.0.0 clients hot-loop GET /v1/action-items at ~97 req/min/uid,
which is 48.8% of every billable Firestore document read in the project
(~$328/day marginal at $0.05395/100k).

Add BOOST_EXEMPT_POLICIES, honored in get_effective_limit(): an exempt
policy always serves its base limit and ignores the boost, including an
explicitly passed boost= argument. Seeded with action_items:list only;
the other ~40 policies keep the boost, and a test asserts that.

This restores an already-approved cap rather than choosing a new number,
needs no client release, and cuts the loop from ~97 to 12 req/min/uid
(~88%, ~$290/day). Enforcement runs in Depends() before the handler, so a
429 costs one Cloud Run request and zero Firestore reads.

The exemption list is env-escapable in the module's existing style:
RATE_LIMIT_BOOST_EXEMPT="" puts every policy back under the boost and
restores byte-for-byte today's behaviour via a Cloud Run env change on a
new revision -- no build, no image push, no revert. Unknown names are
resolved against RATE_POLICIES and dropped, so a typo cannot crash import.

Tradeoff: stale Windows clients will now see 429s on /v1/action-items.
Their data stays correct -- 12/min is still ~150x more often than the
app's own post-fix 5-minute sync design (6524990).

+10 unit tests: non-exempt policies still boost, the exempt policy binds
at (12, 60) under RATE_LIMIT_BOOST=100, env override and typo handling,
and the 429 carries X-RateLimit-Limit: 12 (the enforced cap, not 1,200).

Co-authored-by: Claude Fable 5 <[email protected]>
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.

2 participants