Repository navigation
feat: cap each org's GitOps requests at a configurable RPM (default 100) - #95
Open
roshan-vapi wants to merge 5 commits into
Open
roshan-vapi wants to merge 5 commits into
roshan-vapi wants to merge 5 commits into
Conversation
Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>
Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>
Contributor
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
Contributor
Devin Review🟢 Devin Review found nothing to fix · View findings |
Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>
Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>
scott-lowe-vapi
approved these changes
Nov 17, 2026
scott-lowe-vapi
left a comment
Contributor
There was a problem hiding this comment.
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.
Co-Authored-By: Roshan Manjaly <roshan@vapi.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Value
V.A.L.U.E. tier: medium. It changes behavior on every Vapi request path: 11 call sites plus
VapiConnectionnow go through one limiter. The fixed 700ms write gap is removed, so writes are paced by the same limit. Nothing deletes or overwrites data.cleanup,call,rollback,setup, interactive pull,sim/check/promoteviaVapiConnection) callfetchdirectly 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.promote,check).How it works
One setting per org, committed.
resources/<org>/.vapi-org.jsongets an optionalmaxGitopsRpm. It's named "GitOps RPM" so it isn't mistaken for the Vapi org limit. Resolution order: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.
.envfiles, including API key loading, are now read with one shared parser (src/env-file.ts,node:utilparseEnv). Ordinary unquoted or quoted keys and URLs resolve the same as before. These inputs change:KEY=value # note/KEY=value#x#)export KEY=valueexport KEYKEY\nor multilinePrecedence across files is unchanged: the first file that sets a key wins.
One choke point.
limitedVapiFetch(limiter, url, init)insrc/vapi-fetch.tswaits on the org's token bucket, then sends the request withUser-Agentandx-vapi-client. Caller headers are normalized withnew Headers(init.headers), soHeadersobjects and arrays keepAuthorization. If the request'ssignalaborts 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 reportsincomplete: not started: interruptedand starts no paid work. Every direct VapifetchandvapiFetchJsongoes through it. The GitHub status call doesn't.Per-org token bucket (
src/rate-limit.ts). It refills atrpm / 60per second and bursts up tomax(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, sopromote/checkacross several orgs pace each org separately. Retries, probes, reads and writes all spend tokens. The fixed 700ms write gap inapi.tsand the fixed sleeps incleanup.tsare removed, so writes use the same bucket as reads. 429/5xx backoff is unchanged.429 warning, once per org. If Vapi still returns a 429, GitOps warns that
maxGitopsRpmmay 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/organizationforapi.eu.vapi.ai,dashboard.vapi.ai/settings/organizationotherwise.Org pin keeps settings. Writing
.vapi-org.jsonnow mergesorgIdinto the existing file instead of replacing it, somaxGitopsRpmsurvives a re-pin. A file holding onlymaxGitopsRpmcounts as unpinned.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
tests/user-agent-coverage.test.tsnow fails if any Vapifetchinsrc/doesn't go throughlimitedVapiFetch.tests/rate-limit.test.ts(fake clock and local stub server): burst then sustained spacing, per-org isolation, each precedence level,export/quoted/commented.envvalues, 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 keepsmaxGitopsRpmand other fields.tests/api-write-pacing.test.ts: back-to-back POST/PATCH/DELETE are spaced only by the limiter.Headersobjects and arrays keepAuthorization; burst bounds; cached limiters don't re-read config; only the winning source is validated; example-style.envfiles resolve the same API key and base URL.npm run buildpasses, andnpm testpasses 605/605.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