Skip to content

perf(slack): show Pensando faster by parallelizing reactions and prep work#441

Open
JonasJesus42 wants to merge 1 commit into
mainfrom
slack-faster-thinking
Open

perf(slack): show Pensando faster by parallelizing reactions and prep work#441
JonasJesus42 wants to merge 1 commit into
mainfrom
slack-faster-thinking

Conversation

@JonasJesus42
Copy link
Copy Markdown
Contributor

@JonasJesus42 JonasJesus42 commented May 14, 2026

Summary

Each Slack message handler used to serialize four Slack RTTs before the user saw the "Pensando..." (thread starter) message:

addReaction → sendThinkingMessage → removeReaction → [resolveUserName → buildLLMMessages → isLLMAvailable] → LLM

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):

  • Reactions are fire-and-forget via a new shared fireReactionCycle helper — add + remove run in the background and never gate anything; errors are swallowed.
  • sendThinkingMessage is started immediately, its promise is awaited only right before the LLM call (or warning-msg cleanup). No more waiting on addReaction before "Pensando..." shows.
  • resolveUserName, buildLLMMessages (Slack history fetch), isLLMAvailable are awaited together in a single Promise.all alongside the thinking promise — total wait becomes max(slowest) instead of sum(all).

Latency impact

  • Time-to-thread/Pensando: ~3 RTTs → 1 RTT (just sendThinkingMessage).
  • Time-to-LLM-call: previously sum(thinking + name + history + available) ≈ 4 RTTs. Now max(...) ≈ 1 RTT (history fetch is usually the slowest, others fit inside it).

Test plan

  • Send a DM → "Pensando..." appears under your message in well under 1s.
  • 👀 reaction still appears and disappears (no visual regression).
  • LLM response still streams into the thinking message in place.
  • @mention in a channel still threads correctly.
  • Reply inside an existing bot thread → bot responds in that thread.
  • If the connection isn't ready, the warning is shown in-thread and the thinking message is cleaned up.

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.

  • Refactors
    • Added fireReactionCycle to add/remove 👀 in the background; errors are ignored.
    • Start sendThinkingMessage immediately; await only before the LLM call or cleanup.
    • Run resolveUserName, buildLLMMessages (history fetch), isLLMAvailable, and the thinking message together via Promise.all in handleAppMention, handleDirectMessage, and handleThreadReply.

Written for commit 830778b. Summary will update on new commits.

…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>
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