Skip to content

feat(kit): add hosted capacity guardrails - #269

Merged
hyochan merged 4 commits into
mainfrom
feat/kit-capacity-guardrails
Aug 2, 2026
Merged

hyochan merged 4 commits into
mainfrom
feat/kit-capacity-guardrails

Conversation

@hyochan

@hyochan hyochan commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • define hosted IAPKit as shared, community-funded, best-effort infrastructure with explicit fair-use guidance
  • guide high-volume consumers to contact OpenIAP, support capacity through GitHub Sponsors or OpenCollective, or self-host
  • add API-key, trusted-source-IP, and process-level verification concurrency protection plus Fly proxy caps

Safeguards

  • existing token buckets are documented as 600/10 req/s per key, 600/5 req/s per IP, and 5,000/100 req/s per process
  • add 8/key, 16/trusted-IP, and 32/process in-flight verification caps
  • return 503 SERVICE_BUSY with Retry-After and concurrency scope headers instead of queueing
  • set Fly request concurrency to soft 80 / hard 120 per machine
  • describe these controls as defense in depth, not DDoS immunity or an SLA

Verification

  • Kit format, lint, TypeScript, Convex typecheck, and ESLint
  • 881 Kit tests across 74 files
  • Kit production Vite/Bun build and all server smoke probes
  • Docs format, typecheck, and production build
  • 38 docs audit fixtures, audit:docs, audit:release-state, and audit:parity
  • Desktop/mobile visual review with no overflow or console errors

flyctl config validate could not be run locally because the CLI has no auth token; fly.toml parses locally and CI remains the remote validation gate.

Summary by CodeRabbit

  • New Features

    • Added concurrency safeguards for purchase verification, including per-key, per-IP, and global limits.
    • Added 503 SERVICE_BUSY responses with retry guidance and capacity headers.
    • Added configurable concurrency settings for deployments.
  • Documentation

    • Expanded guidance on fair use, hosted capacity, high-volume traffic, sponsorship, and self-hosting.
    • Updated refresh behavior to handle temporary service unavailability.
    • Clarified terms, security expectations, operational limits, and support options.
  • Bug Fixes

    • Ensured concurrency slots are released after successful or failed requests.

Document the hosted service as shared, community-funded best-effort infrastructure and guide high-volume teams toward sponsorship or self-hosting.

Add key, trusted-source-IP, and process concurrency guards for verification alongside Fly proxy limits, with SERVICE_BUSY contracts and regression coverage.
@hyochan hyochan added 🎯 feature New feature 📖 documentation Improvements or additions to documentation openiap-kit packages/kit (IAPKit SaaS) labels Aug 1, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a8e5b0c-9435-4eb8-b3c1-9574e389348c

📥 Commits

Reviewing files that changed from the base of the PR and between 2d5cf34 and 1e5badb.

📒 Files selected for processing (12)
  • packages/docs/public/llms-full.txt
  • packages/docs/public/llms.txt
  • packages/kit/.env.example
  • packages/kit/COST-SAFETY.md
  • packages/kit/README.md
  • packages/kit/public/llms-full.txt
  • packages/kit/public/llms.txt
  • packages/kit/server/api/v1/in-flight-limit.test.ts
  • packages/kit/server/api/v1/in-flight-limit.ts
  • packages/kit/server/api/v1/routes.test.ts
  • packages/kit/server/api/v1/routes.ts
  • packages/kit/src/pages/docs/sections/api.tsx
🚧 Files skipped from review as they are similar to previous changes (12)
  • packages/docs/public/llms.txt
  • packages/kit/.env.example
  • packages/kit/server/api/v1/routes.test.ts
  • packages/kit/server/api/v1/in-flight-limit.test.ts
  • packages/docs/public/llms-full.txt
  • packages/kit/server/api/v1/routes.ts
  • packages/kit/COST-SAFETY.md
  • packages/kit/src/pages/docs/sections/api.tsx
  • packages/kit/README.md
  • packages/kit/public/llms.txt
  • packages/kit/server/api/v1/in-flight-limit.ts
  • packages/kit/public/llms-full.txt

📝 Walkthrough

Walkthrough

The PR adds scoped verification concurrency limits with bounded 503 SERVICE_BUSY responses. It documents retry behavior, fair-use capacity constraints, sponsorship options, and self-hosting across implementation, API contracts, operations, legal, and user-facing content.

Changes

Hosted Capacity Controls

Layer / File(s) Summary
Verification concurrency middleware
packages/kit/server/api/v1/in-flight-limit.ts, packages/kit/server/api/v1/in-flight-limit.test.ts
Adds InFlightLimitMiddleware to enforce process-wide, per-API-key, and per-source-IP concurrency limits on verification requests. Rejects over-limit requests with 503 SERVICE_BUSY and capacity headers. Guarantees slot cleanup after completion or error. Tests cover limits, rejection, state cleanup, errors, and missing authentication.
Route integration and OpenAPI
packages/kit/server/api/v1/routes.ts, packages/kit/server/api/v1/routes.test.ts
Instantiates and adds concurrency middleware to both verification route stacks. Adds OpenAPI response headers for concurrency limit, remaining capacity, and scope identification. Documents 503 SERVICE_BUSY status and expanded response-header coverage. Expands tests to verify header presence and typing.
Configuration and environment
packages/kit/fly.toml, packages/kit/.env.example, packages/kit/server/api/v1/rate-limit.ts
Configures Fly machine-level HTTP request concurrency (soft: 80, hard: 120). Documents environment variables for verification concurrency limits. Updates rate-limit scope documentation to reflect fair-use defaults for shared hosted capacity.
Client API documentation
packages/kit/src/pages/docs/sections/api.tsx
Documents conditional refresh to honor Retry-After on both 429 and 503 responses. Explains concurrency scope headers, rate-limit scope identification, and the new SERVICE_BUSY status for exhausted verification slots. Includes retry guidance with jittered backoff.
Operations documentation
packages/kit/src/pages/docs/sections/operations.tsx
Describes per-key, per-IP, and process-wide rate and concurrency limits with environment variable configuration. Documents 503 SERVICE_BUSY responses, concurrency headers, default limits, and Fly Proxy machine limits. Adds hosted fair-use constraints and high-volume capacity-planning guidance.
Generated documentation
packages/kit/public/llms*.txt, packages/docs/public/llms*.txt
Updates generated LLM documentation with fair-use terms, shared best-effort capacity without SLA, concurrency limits, Retry-After handling, high-volume contact options, and self-hosting guidance.
User-facing capacity guidance
packages/docs/src/pages/docs/kit-backend.tsx, packages/kit/src/pages/landing.tsx, packages/kit/src/pages/sponsors.tsx, packages/kit/src/pages/auth/organization/usage.tsx, packages/kit/src/pages/blog/iapkit-joins-openiap.tsx, packages/kit/src/components/FreeTransitionNotice.tsx
Updates landing page, blog, sponsors, usage, and backend documentation to describe hosted validation and analytics as free under fair-use limits on shared, best-effort, community infrastructure. Adds GitHub Sponsors and OpenCollective support buttons. Documents sponsorship limitations, capacity-planning contacts, and self-hosting for predictable scaling.
Legal and safety documentation
packages/kit/src/content/terms-of-service.md, packages/kit/COST-SAFETY.md, packages/kit/SECURITY.md, packages/kit/convex/plans.ts, packages/kit/README.md
Adds Fair Use and Capacity section to Terms of Service defining shared infrastructure, configurable safeguards, enforcement actions, and sponsorship/self-hosting options. Updates intellectual-property section to recognize MIT license and preserve trademark rights. Updates COST-SAFETY with concurrency caps, defense-in-depth, and incident guidance. Updates SECURITY criteria to include defense-layer evasion and work amplification. Updates README and plans documentation to reflect fair-use safeguards and capacity constraints.

Estimated code review effort: 4 (Complex) | ~50 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant PurchaseVerificationRoute
  participant inFlightLimitMiddleware
  participant VerificationHandler
  Client->>PurchaseVerificationRoute: Send verification request
  PurchaseVerificationRoute->>inFlightLimitMiddleware: Apply scoped concurrency guard
  alt Capacity available
    inFlightLimitMiddleware->>VerificationHandler: Admit request, increment counters
    VerificationHandler-->>inFlightLimitMiddleware: Result or error
    inFlightLimitMiddleware->>inFlightLimitMiddleware: Decrement counters in finally
    inFlightLimitMiddleware-->>Client: Response with concurrency headers
  else Capacity exhausted
    inFlightLimitMiddleware-->>Client: 503 SERVICE_BUSY with scope and Retry-After
  end
Loading

Possibly related PRs

  • hyodotdev/openiap#234: Updates the same verifyPurchase OpenAPI response contract with API-key error responses.
  • hyodotdev/openiap#258: Updates the same conditional entitlement refresh documentation for Retry-After handling.

Suggested labels: kit

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: adding hosted capacity guardrails to Kit.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/kit-capacity-guardrails

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hyochan

hyochan commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

Preview

pr-kit-capacity-guardrails.mp4

Copilot AI 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.

Pull request overview

This PR adds explicit hosted-capacity/fair-use messaging across Kit + Docs and introduces server-side concurrency guardrails for /api/v1/purchase/verify, returning 503 SERVICE_BUSY with retry guidance when in-flight verification capacity is saturated.

Changes:

  • Added per-key / per-source-IP / per-process in-flight verification caps and surfaced new X-Concurrency-* headers in responses and OpenAPI.
  • Updated Kit + Docs content to set expectations about shared best-effort hosted capacity, funding options (GitHub Sponsors/OpenCollective), and self-hosting guidance.
  • Added Fly Proxy HTTP request concurrency limits and expanded operational/security/ToS documentation to reflect defense-in-depth safeguards.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/kit/src/pages/landing.tsx Updates landing copy + CTAs to emphasize fair-use hosted service and sponsorship/self-host options.
packages/kit/src/pages/docs/sections/operations.tsx Documents hosted fair use + new concurrency capacity limits and tuning env vars.
packages/kit/src/pages/docs/sections/api.tsx Updates client refresh guidance and documents 503 SERVICE_BUSY + concurrency headers.
packages/kit/src/pages/blog/iapkit-joins-openiap.tsx Adjusts announcement FAQ/copy to reflect fair-use safeguards and high-volume coordination.
packages/kit/src/pages/auth/organization/usage.tsx Updates usage page messaging + adds GitHub/OpenCollective/self-host links and capacity-planning contact.
packages/kit/src/content/terms-of-service.md Adds fair-use/capacity/abuse section; updates prohibited actions and renumbers sections.
packages/kit/src/components/FreeTransitionNotice.tsx Updates subscription transition notice to reference fair-use safeguards.
packages/kit/server/api/v1/routes.ts Wires inFlightLimitMiddleware, adds OpenAPI 503 + concurrency headers for verify route.
packages/kit/server/api/v1/routes.test.ts Extends OpenAPI/spec tests and asserts concurrency headers on successful verification.
packages/kit/server/api/v1/rate-limit.ts Updates comments to reflect hosted fair-use framing (no functional changes in shown diff).
packages/kit/server/api/v1/in-flight-limit.ts Introduces new middleware implementing in-flight concurrency caps with 503 SERVICE_BUSY.
packages/kit/server/api/v1/in-flight-limit.test.ts Adds tests verifying caps, anti-key-rotation behavior per IP, and slot release on errors.
packages/kit/SECURITY.md Clarifies DoS scope expectations and lists defense-in-depth controls (rate/replay/size/concurrency).
packages/kit/README.md Adds hosted fair-use/capacity-planning guidance and documents concurrency safeguards + env vars.
packages/kit/public/llms.txt Updates LLM quick reference to include fair-use, 503 behavior, and concurrency header info.
packages/kit/public/llms-full.txt Updates LLM full reference with 503 + concurrency and hosted-capacity guidance.
packages/kit/fly.toml Adds Fly HTTP service request concurrency soft/hard caps per machine.
packages/kit/COST-SAFETY.md Updates cost-safety narrative to include new concurrency controls and hosted-capacity framing.
packages/kit/convex/plans.ts Clarifies that monthly accounting is non-blocking and edge safeguards may throttle.
packages/kit/.env.example Documents new VERIFY_* env vars and retry-after config.
packages/docs/src/pages/sponsors.tsx Adds hosted IAPKit sustainability/fair-use section + OpenCollective option and CTA updates.
packages/docs/src/pages/docs/kit-backend.tsx Adds a hosted-capacity section with guidance, limits, and sponsorship/self-host recommendations.
packages/docs/public/llms.txt Updates generated timestamp.
packages/docs/public/llms-full.txt Updates generated timestamp and includes hosted-kit fair-use/concurrency guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/kit/server/api/v1/routes.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/kit/COST-SAFETY.md`:
- Line 3: Update the effective date in the COST-SAFETY document header to August
1, 2026, unless August 2, 2026 is intentionally scheduled; in that case,
explicitly label it as the future effective date.
- Around line 66-69: Update the concurrency behavior description in
COST-SAFETY.md to say requests are rejected when an axis is full or reaches its
configured limit, rather than whenever any axis is occupied; preserve the
existing 503, headers, slot-release, and idle-entry cleanup details.

In `@packages/kit/public/llms.txt`:
- Around line 124-125: Update the 429 RATE_LIMITED descriptions to document
API-key, source-IP, and process limiter buckets, so clients can use
X-Concurrency-Scope to identify the rejection; in packages/kit/public/llms.txt
lines 124-125, packages/kit/public/llms-full.txt lines 326-340, and
packages/docs/public/llms-full.txt lines 2152-2160, revise the earlier entries
with these scopes. In packages/kit/src/pages/docs/sections/api.tsx lines
603-611, update the existing 429 row to distinguish key, source-IP, process, and
replay-guard rejections.

In `@packages/kit/server/api/v1/in-flight-limit.ts`:
- Around line 89-102: Update the apiKeyHash misconfiguration branch in the
concurrency guard to return the same X-Correlation-Id and X-Concurrency-Limit,
X-Concurrency-Remaining, and X-Concurrency-Scope headers as the normal rejection
path, preserving the documented 500 response contract.

In `@packages/kit/server/api/v1/routes.test.ts`:
- Around line 73-75: Update the /purchase/verify test around the
X-Concurrency-Remaining assertion to avoid depending on sharedVerifyState call
order. Inject isolated state for the route under test, or derive the expected
remaining value from the relevant key’s current state, while preserving the
existing limit and scope assertions.

In `@packages/kit/src/pages/docs/sections/api.tsx`:
- Around line 517-522: Update the concurrency-header documentation to state that
requests must reach the in-flight guard, rather than merely pass body
validation, before receiving X-Concurrency-* headers. Apply this wording in
packages/kit/src/pages/docs/sections/api.tsx lines 517-522,
packages/kit/public/llms.txt lines 127-134, packages/kit/public/llms-full.txt
lines 318-324, and packages/docs/public/llms-full.txt lines 2148-2150.
- Around line 499-502: Update the response-header guarantee in the API
documentation paragraph near the authenticated response section so it does not
claim correlation and rate-limit headers on every authenticated response. Either
document route-level coverage for paths such as subscriptions and products admin
routes, or narrow the sentence to only the headers guaranteed by each documented
middleware chain.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 35c1ea40-b849-45e0-9a66-26115fd0a63c

📥 Commits

Reviewing files that changed from the base of the PR and between 77f91d9 and 075fe11.

📒 Files selected for processing (24)
  • packages/docs/public/llms-full.txt
  • packages/docs/public/llms.txt
  • packages/docs/src/pages/docs/kit-backend.tsx
  • packages/docs/src/pages/sponsors.tsx
  • packages/kit/.env.example
  • packages/kit/COST-SAFETY.md
  • packages/kit/README.md
  • packages/kit/SECURITY.md
  • packages/kit/convex/plans.ts
  • packages/kit/fly.toml
  • packages/kit/public/llms-full.txt
  • packages/kit/public/llms.txt
  • packages/kit/server/api/v1/in-flight-limit.test.ts
  • packages/kit/server/api/v1/in-flight-limit.ts
  • packages/kit/server/api/v1/rate-limit.ts
  • packages/kit/server/api/v1/routes.test.ts
  • packages/kit/server/api/v1/routes.ts
  • packages/kit/src/components/FreeTransitionNotice.tsx
  • packages/kit/src/content/terms-of-service.md
  • packages/kit/src/pages/auth/organization/usage.tsx
  • packages/kit/src/pages/blog/iapkit-joins-openiap.tsx
  • packages/kit/src/pages/docs/sections/api.tsx
  • packages/kit/src/pages/docs/sections/operations.tsx
  • packages/kit/src/pages/landing.tsx

Comment thread packages/kit/COST-SAFETY.md Outdated
Comment thread packages/kit/COST-SAFETY.md Outdated
Comment thread packages/kit/public/llms.txt
Comment thread packages/kit/server/api/v1/in-flight-limit.ts
Comment thread packages/kit/server/api/v1/routes.test.ts
Comment thread packages/kit/src/pages/docs/sections/api.tsx
Comment thread packages/kit/src/pages/docs/sections/api.tsx Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated no new comments.

@hyodotdev hyodotdev deleted a comment from gemini-code-assist Bot Aug 1, 2026
@hyodotdev hyodotdev deleted a comment from coderabbitai Bot Aug 1, 2026
@hyodotdev hyodotdev deleted a comment from gemini-code-assist Bot Aug 1, 2026
@hyodotdev hyodotdev deleted a comment from coderabbitai Bot Aug 1, 2026
The verification source axis trusts only Fly's `fly-client-ip`, so a
deployment that does not run behind Fly resolves every caller to one
shared "unknown" source. That makes VERIFY_MAX_IN_FLIGHT_PER_IP a second
process-wide cap below VERIFY_MAX_IN_FLIGHT, which self-hosters tuning
these values would otherwise hit without explanation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@hyochan
hyochan merged commit 2e6bb7d into main Aug 2, 2026
13 checks passed
@hyochan
hyochan deleted the feat/kit-capacity-guardrails branch August 2, 2026 08:02
@coderabbitai coderabbitai Bot mentioned this pull request Aug 2, 2026
10 tasks done
hyochan added a commit that referenced this pull request Aug 4, 2026
The apple version badge pinned a filter=2.* tag glob, so it kept rendering
v2.4.4 forever after the 3.x releases while the CocoaPods badge beside it
showed v3.0.1. It now reads $.apple from openiap-versions.json with the same
dynamic-json pattern the spec badge already uses, so a future major bump can
never strand it again. Verified against the live shields endpoint.

Also aligns the kit line with the fair-use wording adopted in #269 and lists
packages/mcp-server, which the "all OpenIAP packages" section omitted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📖 documentation Improvements or additions to documentation 🎯 feature New feature openiap-kit packages/kit (IAPKit SaaS)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants