Repository navigation
ref: Add mapBounded and lint against await in loops - #2773
Merged
Merged
Conversation
Add `mapBounded(items, fn, concurrency)` in `src/lib/fan-out.ts`, a thin wrapper over `pLimit(concurrency).map` that keeps input order, and turn on Oxlint's `no-await-in-loop` for `packages/cli/src`. The 82 files that already await in a loop are listed in an override that turns the rule off for them, so new code is checked while existing loops get fixed file by file. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BYK
requested changes
Dec 2, 2026
BYK
left a comment
Member
There was a problem hiding this comment.
I'm 100% sure there are violations in the repo. I want these fixed
| "packages/cli/src/lib/wizard/sourcemaps/tools/sentry-cli.ts", | ||
| "packages/cli/src/lib/wizard/utils/clack/index.ts", | ||
| "packages/cli/src/lib/wizard/utils/clack/mcp-config.ts", | ||
| "packages/cli/src/lib/wrangler.ts" |
Member
There was a problem hiding this comment.
Why are we listing files one by one? This should apply to the entire repo
Move `no-await-in-loop` from the `packages/cli/src` override to the root rules and drop the per-file off list. Test files keep the rule off, by glob: their loops are table-driven assertions that run in order. Independent work now fans out with `mapBounded` or `Promise.all`: CLI lookups across orgs and projects, dashboard widget queries, assemble batches, local file reads and hashes, alert rule detector lookups in mcp-core, and file reads and writes in build and check scripts. Loops that must stay sequential (cursor pages, polling, retries, ordered writes, first match wins, prompts, scope checks) keep their await with a disable comment that gives the reason.
…sites" This reverts commit cb82197. The same change follows as one commit per area, so each can be reviewed on its own.
Run independent per-item work with `mapBounded` or `Promise.all` instead of one item at a time, keeping result order and error behaviour: alert rule and workflow lookups, project listing across orgs, DSN project access, dashboard widget queries, assemble batches, chunk encoding, DSN cache and `.sentryclirc` checks, and local file reads and hashes. API fan-out is capped at `ORG_FANOUT_CONCURRENCY`, local file work at `CONCURRENCY_LIMIT`. Loops that must stay sequential get a disable comment with the reason.
`getAccessibleProjects` now caps its fan-out with `ORG_FANOUT_CONCURRENCY`, which these mocks replace with `undefined`.
File reads in the doc, env, error-pattern, fragment, patch and stale-reference checks, chunk hashing, bundle and doc page writes, generated schema modules and command module imports run concurrently, keeping output order. Benchmarks, evals, ordered generation steps and shared-file rewrites stay sequential with a reason.
Skill scope validation and UI resource reads in scripts run concurrently. Pagination, polling, retries, redirect hops, dependent link fields and project scope checks stay sequential with a reason. Detector lookups for an alert rule stay one at a time, since mcp-core has no fan-out cap.
http computes the `authorization` digest once, after the header copy. Grammar generation, nightly manifest checks and envelope directory walks run concurrently. Retries, stream reads, prompts, polling and replays stay sequential with a reason.
Move `no-await-in-loop` from the `packages/cli/src` override to the root rules and drop the per-file off list. Test files keep the rule off by glob: their loops are table-driven assertions against shared state.
BYK
approved these changes
Dec 2, 2026
This branch was successfully deployed
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.
An
awaitinside a loop runs independent work one item at a time, so a list of N API calls takes N round trips. This PR adds a bounded fan-out helper, turns on Oxlint's built-inno-await-in-loopfor the whole repo, and fixes every place the rule flags. The commits are split by area (CLI src, CLI tests, CLI scripts, mcp-core, the remaining packages, lint config) so each can be reviewed on its own.8dfd11f5reverts an earlier all-in-one commit that those commits replace.Helper
mapBoundedinpackages/cli/src/lib/fan-out.ts:It's a thin wrapper over
pLimit(concurrency).map(...)(p-limitis already a CLI dependency). Results come back in input order, and the first rejection rejects the whole map, likePromise.all. Callers pass the cap:ORG_FANOUT_CONCURRENCYfor API calls, orCONCURRENCY_LIMIT(lib/scan/constants.ts) for local files.Lint rule
no-await-in-loopis in the rootrulesof.oxlintrc.json. Test files (*.test.*,packages/cli/test/**,test-utils/) turn it off with one glob override: their loops are table-driven assertions against shared state, and running them in order is the point.Loops that now run concurrently
Each rewrite keeps result order and error behaviour.
alert metrics view,project listacross orgs, DSN project access, dashboard widget queries (mapBoundedreplaces fixed batches of 5, so one slow widget no longer holds back the next batch), debug-file assemble batches, chunk encoding within an upload request, DSN cache mtime checks,.sentryclirchash checks, and local file reads and hashes for sourcemaps, ProGuard, JVM bundles, asset catalogs and bash-hook tracebacks. API fan-out is capped atORG_FANOUT_CONCURRENCY.authorizationdigest is computed once, after the header copy.Loops that stay sequential
Each one has a
// oxlint-disable-next-line no-await-in-loop -- <reason>comment, or a disable/enable pair around a loop with several awaits. The reasons fall into a few groups: cursor pagination, polling and retries, stream reads, generator drivers, ordered or shared-file writes, first match in priority order, interactive prompts, project scope checks that must stop before more lookups go out, benchmarks, and external calls kept one at a time for rate limits. Detector lookups for an alert rule in mcp-core stay one at a time, since mcp-core has no fan-out cap.packages/cli/AGENTS.mdlistsmapBoundedamong the helpers to reuse and states the rule.via @BYK.
--
View Session [Sentry]