Request limits
How sfd bounds Salesforce API fan-out, retries read calls that hit a request
limit, and reports the last-seen API usage per org. Source: src/limit.mjs
(limiter, withBackoff, LIMIT_ERRORS), src/org-session.mjs (withConn),
src/impact/source.mjs (impactSource), src/ops/ (org-list.mjs, list-metadata.mjs, status.mjs, reload.mjs), and
the status adapter in src/cli/status.mjs (the API usage line). Tests: test/limit.test.mjs, and in test/ops-org.test.mjs,
test/ops-metadata.test.mjs and test/org-session.test.mjs the cases “org list holds timed-out slots until the work settles”, “metadata
listing bounds concurrent chunks” and “limit retries apply to reads and usage is
reported and cleared”.
Bounded fan-out
| Path | Concurrency | Scope |
|---|---|---|
org list --status: non-scratch refresh checks and Dev Hub ScratchOrgInfo queries, combined |
4 | One orgList call |
list-metadata: one metadata.list per chunk of three types |
2 | One listMetadata call |
impact: Tooling and REST queries, describes and Metadata API reads (batches of up to 10 names), combined |
4 | One impact run |
limiter(max)insrc/limit.mjsreturnsrun(fn). It queues work and starts it when a slot is free. Metadata listing drains all chunks before retrying, keeping their results in order and the bound across attempts.- In
--status, the 10 s deadline starts when a check starts, not when it is queued. With 40 non-scratch orgs the worst case isceil(40 / 4) × 10 s, about 100 s, which is inside the 120 s minimum request timeout insrc/client.mjs. - A timed-out check reports
Timeoutat its deadline, but keeps its slot until the underlying call settles. A later exhausted Dev Hub limit is logged by the daemon. - The bound applies only to these fan-outs. It is not a global per-org limiter. Plugin workers use their own connections and are not covered.
impactwraps every call in one limiter, including target resolution, so the four slots are shared. Each call backs off independently throughwithBackoff.
Retrying limit errors
The limit errors are REQUEST_LIMIT_EXCEEDED, ConcurrentPerOrgLongTxn and
ExceededQuota (LIMIT_ERRORS). They are matched on errorCode, then name.
withConnruns the call throughwithBackoffwhen itsbackoffoption is true.backoffdefaults toretry, so every call that passesretry: truealso backs off.- Up to two retries, three attempts in all. Before retry n the daemon waits
1000 ms × 3^n × (0.7 + 0.6 × random), so about 1 s and then 3 s, each within ±30%. - Backed-off calls:
query,describe,org,listMetadataTypes,listMetadata,tracking,logs,logGet,record(limit errors that escape its optional reads), andrestwhen the method is a read, plus Dev HubScratchOrgInfoqueries inorg list. impactbacks off each API call inimpactSource. The overall impact collection runs once per session attempt.- Not backed off:
apex,deploy,retrieve,restwrites, andtest(backoff: false, since Apex test execution polls on its own). The non-scratchorg list --statusrefresh checks do not back off; a limit error there becomes the org’s status, which is the error name. - Session retry is a separate rule governed by the same
retryoption. See Safety policy. - Every limit error that leaves
withConnis decorated, including errors that were not retried. A missing code is prefixed to the message (CODE: ...), and the usage is appended when known:(API usage 42/100). The error keeps itsnameanderrorCode.
API usage
- After each
withConncall, success or failure, the daemon copiesconn.limitInfo.apiUsageinto an in-memory map. The key is the org alias, or the username when no alias was given. sfd statusadds anAPI usage: <org> <used>/<limit>, ...line after the log path, but only when at least one org has reported usage.sfd status --jsonalways includesapiUsage, an object keyed by org that is empty when nothing has been seen.- The values are last seen, not live. A global invalidation clears them:
sfd reload, or a login, logout, alias or config change. A session error for one org does not. Stopping the daemon discards them. See auth-cache.md. Nothing is written to disk, so the map holds no tokens. - Usage never refuses a call. There is no proactive throttling.
Known limits
- A call that never settles holds its limiter slot indefinitely. Queued
--statuschecks wait behind it. This follows the four-call bound. The alternative, releasing the slot after 30 s, was considered and not adopted. - The limit error names and the
limitInfo.apiUsageproperty are checked only against mocked connections in the test suite. Confirm them against a live org when one is available.
Changing this area
- Keep
LIMIT_ERRORSin step with the codes thatwithBackoffmatches. - A new read path that should back off passes
retry: true. A call that must not be replayed passesretry: true, backoff: falseonly with a reason written next to it, astestdoes. Writes never back off. - Create a new
limiterper operation call, so each bound is per fan-out. - Keep
sleepandrandominjectable, aswithBackoffdoes, so tests stay fast and deterministic. - Keep the summaries in Safety policy, the
sfd statusline in the README, and the concurrency numbers in Org list and Metadata listing in step with the code.