Repository navigation
perf(connectors): attribute turn messages in one pass (STA-18015) - #48587
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…ablyai#48587) (cherry picked from commit 43fb152) (cherry picked from commit 4ee71fb4827ee6cf410422ede01b9661d973dec7)
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.tsnow passes the turn it already read into the act path (actAsBot, the body ofconnector.actlifted out unchanged), so a react no longer reads the journal twice.git diff -wshows the move is a few lines.Test
bot-turn-messages.test.tskeeps 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.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.