Skip to content

perf(chat): run independent sandbox, plugin and tool work at once - #3631

Merged
BYK merged 2 commits into
mainfrom
perf/await-in-loop-chat-sandbox
Nov 18, 2026
Merged

BYK merged 2 commits into
mainfrom
perf/await-in-loop-chat-sandbox

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Sequential awaits on independent work add latency to each turn, prompt build and report. This is the next step of the no-await-in-loop burn-down after #3584. It covers the sandbox group in packages/junior/src/chat: sandbox, egress, plugins, MCP, credentials, providers, tools, attachments, local and cache warming. The baseline drops from 290 sites in 88 files to 187 sites in 53 files.

Runs at once now (22 sites), through pLimit(FAN_OUT_CONCURRENCY):

  • Plugin systemPrompt, userPrompt, operationalReport and profileReport hooks. runPluginHooksAtOnce keeps the outcomes in plugin order, so the size budgets, logs and output order do not change.
  • Plugin conversationSidebar and unfinishedWork hooks. Sidebar annotations still merge in plugin order. A failed hook still fails open.
  • Slack steering decisions for a batch of messages.
  • Skill file reads in skill-sync.ts, attachment stores and uploads, cache-warming image reads and segment appends, MCP auth-store deletes and reads, MCP client close, and sandbox snapshot-builder deletes (Docker and Vercel).

Stays in order (the rest), each with a disable comment that says why: stream reads, cursor pages, polls and retries, sandbox preparation (plugins share the sandbox), beforeToolExecute (each hook gets the arguments that the hook before it replaced), afterToolExecute (a denial stops the hooks after it), ordered migrations and installs, and Slack reply posts (a failed post stops the rest).

stopWatchingResources with no id stays sequential: each stop takes the shared timer index lock, and parallel stops could not get it.

Nothing breaks for plugin authors. Hooks of different plugins can now overlap in time, so a plugin must not depend on another plugin's prompt or report hook to finish first.

via @BYK.

--

View Session [Sentry]

Burn down the no-await-in-loop baseline for the sandbox group in
packages/junior/src/chat. Independent work runs through
pLimit(FAN_OUT_CONCURRENCY). Loops that must stay in order get a
disable comment that says why.

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 18, 2026 00:05
@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 12:08am UTC

Request Review

@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 18, 2026
Co-Authored-By: BYK <[email protected]>

# Conflicts:
#	packages/junior/src/chat/egress/credentialed.ts
#	scripts/await-in-loop-baseline.json
@BYK
BYK enabled auto-merge (squash) November 18, 2026 00:09
@github-actions

Copy link
Copy Markdown
Contributor

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

Review screenshots in Frameshift

Automation Run Details · Desktop
Automation Run Details · Desktop
Changed
Automations Runs Filters · Desktop
Automations Runs Filters · Desktop
Changed
Conversation Attachment Zoom · Desktop
Conversation Attachment Zoom · Desktop
Changed
Conversation Attachment Zoom · Mobile
Conversation Attachment Zoom · Mobile
Changed

@BYK
BYK merged commit 629bd91 into main Nov 18, 2026
51 of 52 checks passed
@BYK
BYK deleted the perf/await-in-loop-chat-sandbox branch November 18, 2026 00:22
BYK added a commit that referenced this pull request Nov 18, 2026
…3633)

Sequential awaits on independent work slow down stops, Turn setup and
heartbeats. This is the next step of the `no-await-in-loop` burn-down
after #3631. It covers the task-execution group in
`packages/junior/src/chat`: task-execution, agent invocations, agent
dispatch, agent, and Scheduled and Event automations. The baseline drops
from 187 sites in 53 files to 81 sites in 35 files. It does not touch
`chat/automations/` (2 sites).

**Runs at once now (11 sites):**
- `readChildMessageSenders` reads the sender of each mailbox message
with one legacy query, not one query for each message. A stop,
`hasOpenChildWork` and the loop-reply drop use it.
- A stop drops unread loop replies and stops child Conversations at
once, one task for each Conversation.
- Turn setup records active MCP providers at once. A stop clears pending
Slack reactions at once.
- The activity-index list reads Conversations at once. It still removes
invalid entries one at a time.
- Event automation settling reads dispatch records at once. It still
records runs in order.

**Stays in order (95 sites)**, each with a disable comment that says
why: the worker slice loop and the agent step loop, lock polls,
paused-Turn resume (it stops at the first Turn that resumes), MCP
restore (it stops at the first provider that needs sign-in), mailbox
appends and queued invocations (message order), statements in one
transaction, and the tree lock walk. `runsOnConversationLoop` routes one
input at a time, because its callers already run each child under the
fan-out cap.

Event automation dispatch, plugin heartbeats and dispatch-append
recovery stay sequential on purpose. Each dispatch takes the
pending-append index lock in `agent-dispatch/store.ts`, and
`acquireLock` fails at once when another holder has it. A parallel
version would fail dispatches.

<!-- 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 — bb2eb54f 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