Skip to content

feat: rate-limit personalization and retry preview 503s - #26

Merged
phatpham9 merged 1 commit into
mainfrom
feat/personalize-limit-preview-retry
Nov 13, 2026
Merged

phatpham9 merged 1 commit into
mainfrom
feat/personalize-limit-preview-retry

Conversation

@phatpham9

Copy link
Copy Markdown
Member

Summary

Two remaining AI/UX hardening items:

  • Personalization limiter: generalize the cache-miss limiter into rateLimit.ts with separate namespaces. /api/preview keeps its 20/min bucket; cache-miss /api/personalize requests now get a 10/min bucket before any embedding or LLM polish work. Cache hits bypass both. A blocked personalization request returns 429 with reason: "rate_limited" / Retry-After: 60 and logs personalize_rate_limited (no interests or IPs logged).
  • Preview retry: the client retries a preview request once after a 503 with a 500ms delay. 429s are not retried because the limiter’s Retry-After is 60 seconds.
  • Bumps app.js to v110 and the PWA shell cache to v144.

Verification

  • npm run typecheck
  • npx vitest run --exclude '.claude/**' — 18 files, 147 tests
  • node --check web-static/static/app.js
  • npm run db:migrate:local
  • wrangler deploy --dry-run — 372.97 KiB / 98.93 KiB gzip
  • Live local checks:
    • With the personalization limit temporarily set to 1, cache-miss requests returned 429 in 4–7ms with reason: "rate_limited" and logged personalize_rate_limited.
    • With the real limits, a preview returned 200 / 12 blocks and a personalization request returned 200 / llm.
  • The client retry was not forced against production 503s; it is syntax-checked and only fires on a 503. The existing abort/request-sequence checks still apply.

Notes

  • The limiter remains per-colo and fail-open; it is an abuse speed bump, not a global quota. A zone-level Cloudflare Rate Limiting rule is still the option for strict global enforcement.
  • No new environment variables.

🤖 Generated with Claude Code

Generalize the cache-miss limiter into rateLimit.ts with separate
namespaces. /api/preview keeps its 20/min bucket; cache-miss
/api/personalize requests now get a 10/min bucket before any embedding
or LLM polish work. Cache hits bypass both. Personalize 429s log
personalize_rate_limited and return Retry-After: 60.

Retry a preview request once after a 503 (Cloudflare CPU limit) with a
500ms delay. Do not retry 429s, whose Retry-After is 60 seconds. Bump
app.js to v110 and the PWA shell cache to v144.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🔎 Cloudflare preview: https://4f61938f-feedreader.phatpham9.workers.dev

Uploaded from 919afc11f948a520dac05f26fc7fd3ffd71f2959. This is a Worker version preview — it shares the production D1 database, so it reads/writes real data; it does not receive cron-triggered refreshes.

@phatpham9
phatpham9 merged commit 30d66e2 into main Nov 13, 2026
3 checks passed
@phatpham9
phatpham9 deleted the feat/personalize-limit-preview-retry branch November 13, 2026 15:47
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