Skip to content

ref(fan-out): Map bounded work with mapBounded - #3646

Merged
BYK merged 4 commits into
mainfrom
perf/map-bounded
Nov 18, 2026
Merged

BYK merged 4 commits into
mainfrom
perf/map-bounded

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Bounded fan-out was written out by hand at dozens of sites: build a pLimit limiter, map the list, and wrap each call in the limiter inside Promise.all. This PR replaces that pattern with one call and adds a lint rule that rejects the hand-written form.

Helper. mapBounded(items, fn, concurrency = FAN_OUT_CONCURRENCY) in packages/junior/src/chat/fan-out.ts maps a list with at most concurrency calls at once. Results keep the order of the input. It wraps pLimit(n).map.

Converted sites.

  • 43 core sites now call mapBounded. They keep the same cap (8) and the same concurrency.
  • 5 junior-github sites now call pLimit(N).map(...) with their existing caps, because plugins cannot import core.

Exceptions that keep their own limiter.

  • A limiter that several lists share, so that they use one cap together.
  • Promise.allSettled, because mapBounded rejects on the first error.
  • A limiter that bounds only one step of a larger callback, such as the one in listChildAgentsWithoutAgentInvocations.
  • The dashboard's attention-page reads.

Lint rule. The new oxlint rule junior/prefer-map-bounded flags a p-limit limiter that only wraps the callback of one Promise.all(list.map(...)). It catches both a single-use const limit = pLimit(N) and an inline pLimit(N)(...). The message points to mapBounded in core and to pLimit(N).map in plugins. The rule is on for packages/*/src and for the dashboard's src, with no baseline and no disables. policies/performance.md and the bounded-fan-out message now point to the helper.

Nothing breaks: the behavior and caps are unchanged.

via @BYK.

--

View Session [Sentry]

sentry-junior Bot and others added 3 commits November 18, 2026 01:40
The pLimit-then-Promise.all(list.map(limit(...))) pattern repeats at
most fan-out sites. Add mapBounded(items, fn, concurrency?) to
chat/fan-out.ts, defaulting to FAN_OUT_CONCURRENCY, and use it at each
core site with one limiter per list. Plugins use pLimit(N).map. Sites
that share one limiter across lists keep pLimit.
Flag a p-limit limiter that only wraps the callback of one
Promise.all(list.map(...)), and convert the last core site.

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 18, 2026 08:22
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 18, 2026 10:17am UTC

Request Review

@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

9 screenshot changes — 9 changed · 0 added · 0 removed

Review screenshots in Frameshift

Automation Run Details · Desktop
Automation Run Details · Desktop
Changed
Automations Expanded Row · Desktop
Automations Expanded Row · Desktop
Changed
Automations Expanded Row · Mobile
Automations Expanded Row · Mobile
Changed
Automations Expanded Row Light · Desktop
Automations Expanded Row Light · Desktop
Changed
Automations Expanded Row Light · Mobile
Automations Expanded Row Light · Mobile
Changed
Conversation Fork Dialog · Desktop
Conversation Fork Dialog · Desktop
Changed
Show 3 more changed screenshots
Conversation Fork Dialog · Mobile
Conversation Fork Dialog · Mobile
Changed
Conversation Question Stepper · Desktop
Conversation Question Stepper · Desktop
Changed
Person Profile · Desktop
Person Profile · Desktop
Changed

@BYK
BYK enabled auto-merge (squash) November 18, 2026 10:09
Keep both new oxlint rules and convert the hand-written limiters that main
added in slack-work, agent, task-execution state, agent-invocation stop and
event-automation runs to mapBounded.
@BYK
BYK merged commit 1d86e42 into main Nov 18, 2026
49 of 50 checks passed
@BYK
BYK deleted the perf/map-bounded branch November 18, 2026 10:28
BYK added a commit that referenced this pull request Nov 18, 2026
#3635 merged after #3646 last took
`main`, so `main` fails `junior/prefer-map-bounded` at six single-use
limiters from #3635. This converts them to `mapBounded` with the default
cap. The results stay in the same order.

- `chat/events/store.ts`: `collectEventMatchKeys` index reads.
- `chat/skills.ts`: skill discovery and `loadSkillsByName`. Before, one
limiter was shared by the directories of every root. Discovery now lists
all roots first, then reads every skill directory under one cap, so the
total cap stays the same. The first root that has a skill name still
wins.
- `chat/slack/app-home.ts`: provider connection reads.
- `chat/ingress/slack-conversation-unfurl.ts`: link unfurls.
- `chat/conversations/pending-cards.ts`: terminal Turn event reads.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A7e1432c2f4a2110ee7bb48718f8b6fad -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A7e1432c2f4a2110ee7bb48718f8b6fad)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A7e1432c2f4a2110ee7bb48718f8b6fad/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — deead08a Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant