Repository navigation
Closed
Description
Problem
Cloudflare KV usage reached 50% of daily write limit, triggering a warning email. Investigation shows nemar-api rate limiter is the primary consumer.
Findings
KV Usage (Jan 15, 2026)
| Namespace | Worker | Today's Operations | Daily Limit | % Used |
|---|---|---|---|---|
| RATE_LIMIT | nemar-api | 619 reads + 592 writes | 1,000 writes | 59% |
| RATE_LIMITER | hed-bot/hedit | ~22 | 1,000 | <1% |
| RATE_LIMITER | osa-worker | ~12 | 1,000 | <1% |
| HED_CACHE | hed-bot/hedit | ~6 | 1,000 | <1% |
Root Cause
Each API request to nemar-api triggers:
- KV read (check rate limit)
- KV write (increment counter)
With 20+ CI test runs today, this quickly consumed the daily write quota.
Cloudflare Free Tier Limits
- 100,000 reads/day
- 1,000 writes/day
- 1 GB storage
Mitigations Already Applied
- CI path-based filtering - Tests only run when relevant files change
- CI concurrency control - Cancels duplicate runs
-
TEST_BYPASS_TOKENconfigured - Tests skip rate limiting
Recommendations
Short-term (Pick one)
-
Disable rate limiting in development
// In rateLimit.ts if (c.env.ENVIRONMENT !== 'production') { await next(); return; }
-
Use Cache API instead of KV for rate limiting (no daily limits)
const cache = caches.default; // Cache API has no operation limits
-
Increase rate limit window to reduce writes
const WINDOW_SIZE = 300; // 5 minutes instead of 60 seconds
Long-term
- Upgrade to Workers Paid ($5/month) - 10M reads, 1M writes/month
- Use Durable Objects for rate limiting - Better suited for counters
- Implement token bucket with longer persistence
GraphQL Query for Monitoring
query KvOperations {
viewer {
accounts(filter: { accountTag: "ACCOUNT_ID" }) {
kvOperationsAdaptiveGroups(
filter: {
namespaceId: "9afb2679c6ea4ed4acd1a5916cf291d7",
date_geq: "2026-01-01"
}
limit: 100
orderBy: [date_DESC]
) {
sum { requests }
dimensions { date actionType }
}
}
}
}References
Metadata
Metadata
Assignees
Labels
No labels
Activity
neuromechanist commentedon Jan 15, 2026
Resolution
Implemented the following changes to resolve KV usage concerns:
1. Switched to Cache API for Rate Limiting
2. Created Development Environment
nemar-api-devworker deployed at https://nemar-api-dev.shirazi-10f.workers.dev3. Updated CI Workflow
devbranch to workflow triggers4. Branch Strategy
devbranch for development and testingmainbranch for productionCommits
The KV namespace
9afb2679c6ea4ed4acd1a5916cf291d7is no longer used and can be deleted to clean up.neuromechanist commentedon Jan 16, 2026
Resolution Status
The KV usage issue has been addressed:
RATE_LIMITnamespace (9afb2679c6ea4ed4acd1a5916cf291d7) is no longer in useThe 50% warning received today was from usage accumulated before the fix was fully deployed. Daily KV limits reset at midnight UTC, so tomorrow's metrics should confirm near-zero KV usage from nemar-api.
Will monitor and close this issue once confirmed.
fix: surface JSON parse + git errors in version readers
fix: prune stale tags before --update --prune walk
test: cover isWorkingTreeDirty / resolveUpstreamRef / readLocalDatase…
Add --resume, --update, and BIDS entity filters to dataset download (#…
Address PR review: gate, comments, verbose unit test
fix(sandbox): migrate to S3 special remote, add --verbose (#378)
Address PR #442 review findings
Phase 2: Worker auth layer for GitHub App tokens (#437) (#442)
fix(catalog): sync nemar_catalog from enrichment + backfill historica…
fix(catalog): sync nemar_catalog from enrichment + backfill historica…
review(#644): address three criticals from multi-agent review
Fix import README stub and enrichment self-loop (#642, #643) (#644)