Skip to content

perf(connectors): attribute turn messages in one pass (STA-18015) - #48587

Merged
Jinwoo-H merged 1 commit into
mainfrom
perf/sta-18015-turn-messages-one-pass
Nov 25, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
perf/sta-18015-turn-messages-one-pass

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes STA-18015.

What

Every agent connector action works out whom the running turn acts for, on the Electron main process. Part of that, turnMessages, scanned every loaded user message once per turn, so a chat whose whole history is loaded (an old send left pending or unknown by a crash, or a long run of worker-mail-only turns that widens the read window) cost O(turns × messages) per action.

  • src/main/bots/bot-turn-messages.ts: one pass. Invert the turn anchors once (opener → turns), bucket each message under the turns it opens and the turn it was steered into, then map the requested turns to their buckets. Output is identical, including the order of messages and a message that both opens and is scoped to the same turn (taken once).
  • connector-react.ts now passes the turn it already read into the act path (actAsBot, the body of connector.act lifted out unchanged), so a react no longer reads the journal twice. git diff -w shows the move is a few lines.

Test

bot-turn-messages.test.ts keeps the old per-turn scan as an oracle and compares it with the new code on generated 1,000- and 10,000-turn chats that mix typed and Codex-aliased openers, steers, pending and unknown held sends, worker-mail-only runs, commands, unscoped and subagent rows, steers into unloaded turns, and a turn named twice. It fails if the turn-record ordering check or the same-turn dedup is removed.

Performance

Real readBotActingTurnWithin (the per-action attribution read), main thread, Node 24, M-series Mac; 3 rows per turn. Before = origin/main, after = this branch, same bench.

Rows (turns) Whole history loaded: before after Normal (newest 8 turns): before after
1,000 (333) 1.05 ms 0.48 ms 0.24 ms 0.27 ms
10,000 (3,333) 80.3 ms 3.6 ms 2.1 ms 2.6 ms
100,000 (33,333) 10,560 ms 69.5 ms 41 ms 46 ms

The normal column is within run-to-run noise (repeat runs swapped which side was faster); it is dominated by work this change doesn't touch.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​204 $\color{#cf222e}{\Huge{\mathbf{−}}}$​174 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30

@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

turnMessages now groups journal messages into per-turn buckets in one pass. New tests compare its results with a per-turn scan oracle across large turn sets and mixed journal rows. The connector action flow is now available through actAsBot, which accepts an optional running turn. connector.act delegates to this function, and connector.react passes the current turn when available.

Merge Risk: Minimal · up to ce722

This change groups turn messages in a single pass and lets reactions reuse the turn they already read. The result should be faster for long chat histories without changing which messages belong to each turn. No concrete defects were found in the supplied evidence, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: turnMessages now attributes turn messages in a single pass, which is the performance fix the description and objectives describe. The title follows the conventional co…
Description check Passed The description follows the repository template. It has a Performance section with a concrete reason and benchmark table, a Testing section that describes the oracle-based test, and a What section tha…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: turnMessages now attributes turn messages in a single pass, which is the performance fix the description and objectives describe. The title follows the conventional commit style and is 65 characters long. It does not mention the connector.react refactor, but that is secondary.

Full details: Description check

Explanation

The description follows the repository template. It has a Performance section with a concrete reason and benchmark table, a Testing section that describes the oracle-based test, and a What section that explains the mechanism. The ELI5, Why, Linked Issue, Visual Proof, Risk, AI Disclosure, and Review sections are missing or incomplete. The Testing checkboxes are unchecked, and the Risk level is not set. The Linked Issue section uses 'Fixes STA-18015' in the body, not the template's 'Fixes #' line. Visual Proof is not marked N/A, though the change is not a UI change. The description is mostly complete, so the check passes, but the author should fill in the missing sections.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1aa6c1d4-7848-472a-91bc-bebd9e8cbee1
Commits

Reviewing files that changed from the base of the PR and between e408971 and ce722bf.

Files selected for processing: 5

  • src/main/bots/bot-turn-for.ts
  • src/main/bots/bot-turn-messages.test.ts
  • src/main/bots/bot-turn-messages.ts
  • src/main/runtime/rpc/methods/connector-act.ts
  • src/main/runtime/rpc/methods/connector-react.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@Jinwoo-H
Jinwoo-H merged commit 43fb152 into main Nov 25, 2026
56 checks passed
saltyfireball pushed a commit to saltyfireball/orca that referenced this pull request Nov 25, 2026
…ablyai#48587)

(cherry picked from commit 43fb152)
(cherry picked from commit 4ee71fb4827ee6cf410422ede01b9661d973dec7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant