Skip to content

feat: cap each org's GitOps requests at a configurable RPM (default 100) - #95

Open
roshan-vapi wants to merge 5 commits into
mainfrom
devin/1794906324-org-max-gitops-rps
Open

roshan-vapi wants to merge 5 commits into
mainfrom
devin/1794906324-org-max-gitops-rps

Conversation

@roshan-vapi

@roshan-vapi roshan-vapi commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Value

V.A.L.U.E. tier: medium. It changes behavior on every Vapi request path: 11 call sites plus VapiConnection now go through one limiter. The fixed 700ms write gap is removed, so writes are paced by the same limit. Nothing deletes or overwrites data.

  • Problem: since perf(setup): download an org in about 2s instead of 30s #93, GETs have no request gap. Several commands (cleanup, call, rollback, setup, interactive pull, sim/check/promote via VapiConnection) call fetch directly with no limit at all. An org's Vapi API limit is 200 requests per minute by default, so a large pull or check run can hit 429s, and nothing per org lets you cap that.
  • Who it affects: everyone running gitops commands against an org, especially orgs on the default API limit and CI jobs touching several orgs (promote, check).

How it works

  1. One setting per org, committed. resources/<org>/.vapi-org.json gets an optional maxGitopsRpm. It's named "GitOps RPM" so it isn't mistaken for the Vapi org limit. Resolution order:

    shell VAPI_MAX_GITOPS_RPM
      > .env.<org> / .env.<org>.local / .env.local VAPI_MAX_GITOPS_RPM
      > .vapi-org.json maxGitopsRpm
      > 100   (DEFAULT_MAX_GITOPS_RPM, half the 200 RPM API default)
    

    Values must be positive integers. Only the source that wins is validated, so a typo in an overridden file doesn't block. An invalid winning value stops the command before its first request with a one-line error naming the file, and no stack trace. .env files, including API key loading, are now read with one shared parser (src/env-file.ts, node:util parseEnv). Ordinary unquoted or quoted keys and URLs resolve the same as before. These inputs change:

    Input Before Now
    KEY=value # note / KEY=value#x comment kept in value comment stripped (quote values containing #)
    export KEY=value key named export KEY key KEY
    Same key twice in one file first wins last wins
    Double-quoted \n or multiline literal / truncated newline / full value
    Backtick-quoted backticks kept backticks removed

    Precedence across files is unchanged: the first file that sets a key wins.

  2. One choke point. limitedVapiFetch(limiter, url, init) in src/vapi-fetch.ts waits on the org's token bucket, then sends the request with User-Agent and x-vapi-client. Caller headers are normalized with new Headers(init.headers), so Headers objects and arrays keep Authorization. If the request's signal aborts while it's queued, it throws instead of sending. The sim create POST passes the run's signal and the cancel PATCH doesn't, so an interrupted check reports incomplete: not started: interrupted and starts no paid work. Every direct Vapi fetch and vapiFetchJson goes through it. The GitHub status call doesn't.

  3. Per-org token bucket (src/rate-limit.ts). It refills at rpm / 60 per second and bursts up to max(1, min(20, floor(rpm / 5))), which is 20 at the default. The most it allows in any minute is burst + rpm = 120, still under the 200 RPM API default. The limit is read once per org, when the bucket is created. There is one bucket per org per process, so promote/check across several orgs pace each org separately. Retries, probes, reads and writes all spend tokens. The fixed 700ms write gap in api.ts and the fixed sleeps in cleanup.ts are removed, so writes use the same bucket as reads. 429/5xx backoff is unchanged.

  4. 429 warning, once per org. If Vapi still returns a 429, GitOps warns that maxGitopsRpm may be set higher than the org's API limit, and names the org and the value in effect. It links to the one dashboard page for the base URL's region: dashboard.eu.vapi.ai/settings/organization for api.eu.vapi.ai, dashboard.vapi.ai/settings/organization otherwise.

  5. Org pin keeps settings. Writing .vapi-org.json now merges orgId into the existing file instead of replacing it, so maxGitopsRpm survives a re-pin. A file holding only maxGitopsRpm counts as unpinned.

  6. Setup is unchanged for the user. The wizard validates the key with a default-limit bucket before the org slug is known, then switches to that org's bucket. Prompt order is the same as before.

Tradeoff: a plain pull (about 11 list GETs) fits in the burst of 20, so #93's speed is kept. Sustained traffic beyond the burst runs at one request every 0.6s, so writes get slightly faster than the old 0.7s gap. Orgs with a higher API limit can raise maxGitopsRpm.

Not covered: the limit applies within one process. Two developers or CI jobs on the same org each get the full budget, so a true org-wide cap would need enforcing in the API.

Verification

  • Bypass guard: tests/user-agent-coverage.test.ts now fails if any Vapi fetch in src/ doesn't go through limitedVapiFetch.
  • tests/rate-limit.test.ts (fake clock and local stub server): burst then sustained spacing, per-org isolation, each precedence level, export/quoted/commented .env values, invalid values exiting with status 1 and no stack trace, the 429 warning text, and US/EU link selection.
  • tests/org-pin.test.ts: re-pinning keeps maxGitopsRpm and other fields.
  • tests/api-write-pacing.test.ts: back-to-back POST/PATCH/DELETE are spaced only by the limiter.
  • Review follow-ups: a create aborted in a 1 RPM queue never sends its POST; Headers objects and arrays keep Authorization; burst bounds; cached limiters don't re-read config; only the winning source is validated; example-style .env files resolve the same API key and base URL.
  • npm run build passes, and npm test passes 605/605.
  • Not covered: a live run against a Vapi org.

Link to Devin session: https://app.devin.ai/sessions/61e79a6b4f514652bde5a9ef21286d2c
Open in Devin Desktop: https://app.devin.ai/desktop/session/61e79a6b4f514652bde5a9ef21286d2c?variant=devin
Requested by: @roshan-vapi

devin-ai-integration Bot and others added 2 commits November 17, 2026 09:11
Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>
Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Devin Review

🟢 Devin Review found nothing to fix · View findings

Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>
@devin-ai-integration devin-ai-integration Bot changed the title feat: cap per-org GitOps requests with configurable max GitOps RPM feat: cap each org's GitOps requests at a configurable RPM (default 100) Nov 17, 2026
Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>

@scott-lowe-vapi scott-lowe-vapi 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.

Approving, with the inline changes below to make before merge. Also smoke-test against a test org: one pull, one small push, and one sim interrupted with Ctrl-C partway through.

Comment thread src/vapi-fetch.ts Resolved
Comment thread src/vapi-fetch.ts Resolved
Comment thread src/rate-limit.ts Resolved
Comment thread src/rate-limit.ts Resolved
Comment thread src/rate-limit.ts Resolved
Comment thread src/config.ts Resolved
Comment thread improvements.md Resolved
Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>
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