perf(slack): show Pensando faster by parallelizing reactions and prep work#441
Open
JonasJesus42 wants to merge 1 commit into
Open
perf(slack): show Pensando faster by parallelizing reactions and prep work#441JonasJesus42 wants to merge 1 commit into
JonasJesus42 wants to merge 1 commit into
Conversation
…okup, and history fetch Each handler used to serialize four Slack RTTs before the user saw the "Pensando..." (thread starter) message: addReaction -> sendThinkingMessage -> removeReaction -> [later work] That made the floor for time-to-thinking ~3 Slack round-trips, even though the 👀 reaction is purely cosmetic and the bot can already show "Pensando..." without it. For all three message handlers (app_mention, direct message, thread reply): - Reactions are now fire-and-forget via a shared `fireReactionCycle` helper. add + remove run in the background and never gate the response path. Errors are swallowed (a failed reaction is harmless). - `sendThinkingMessage` is started immediately, its promise is awaited only right before the LLM call (or before the warning-msg cleanup). - `resolveUserName`, `buildLLMMessages` (which fetches Slack thread history), and `isLLMAvailable` are awaited together in a single Promise.all alongside the thinking promise — so total wait becomes max(slowest) instead of sum(all). Net effect: the user sees the thread + "Pensando..." after a single Slack RTT rather than ~3 RTTs, and the LLM call starts sooner because prep work overlaps with the thinking-message RTT. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Each Slack message handler used to serialize four Slack RTTs before the user saw the "Pensando..." (thread starter) message:
That floor was ~3 round-trips for the thread to appear, even though the 👀 reaction is purely cosmetic and the bot can already show "Pensando..." without it. After the thread shows, three more sequential RTTs delayed the actual LLM call.
For all three handlers (
handleAppMention,handleDirectMessage,handleThreadReply):fireReactionCyclehelper — add + remove run in the background and never gate anything; errors are swallowed.sendThinkingMessageis started immediately, its promise is awaited only right before the LLM call (or warning-msg cleanup). No more waiting onaddReactionbefore "Pensando..." shows.resolveUserName,buildLLMMessages(Slack history fetch),isLLMAvailableare awaited together in a singlePromise.allalongside the thinking promise — total wait becomesmax(slowest)instead ofsum(all).Latency impact
sendThinkingMessage).sum(thinking + name + history + available)≈ 4 RTTs. Nowmax(...)≈ 1 RTT (history fetch is usually the slowest, others fit inside it).Test plan
Summary by cubic
Show “Pensando...” in Slack faster by parallelizing reactions and prep work. Time-to-thread drops to 1 RTT, and the LLM call starts sooner. Behavior is unchanged.
fireReactionCycleto add/remove 👀 in the background; errors are ignored.sendThinkingMessageimmediately; await only before the LLM call or cleanup.resolveUserName,buildLLMMessages(history fetch),isLLMAvailable, and the thinking message together viaPromise.allinhandleAppMention,handleDirectMessage, andhandleThreadReply.Written for commit 830778b. Summary will update on new commits.