feat(bridge): batch rapid-fire IM messages for same session#265
Open
lowmiaq-gmail wants to merge 1 commit intoop7418:mainfrom
Open
feat(bridge): batch rapid-fire IM messages for same session#265lowmiaq-gmail wants to merge 1 commit intoop7418:mainfrom
lowmiaq-gmail wants to merge 1 commit intoop7418:mainfrom
Conversation
When a user sends multiple messages quickly from an IM channel (Feishu, Telegram, Discord), they are now aggregated into a single Claude prompt instead of being queued for serial one-by-one processing. Problem: - Messages for the same session were serialized via processWithSessionLock - Each Claude call takes 30s-5min, so message 2 waited for message 1 - No acknowledgment was sent, making users think messages were lost Solution: - Add pendingBatches Map to BridgeManagerState for per-session aggregation - scheduleOrProcess() checks if session has active lock; if busy, buffers the message and sends an immediate "⏳ received" acknowledgment - 2-second batch window (BATCH_WINDOW_MS) allows collecting multiple rapid-fire messages before flushing - flushBatch() merges queued messages into a single prompt with --- separators, concatenates attachments, and processes as one request - processWithSessionLock.finally() auto-flushes any messages that accumulated during processing Behavior: - Single message, session free → processed immediately (no change) - Multiple messages while session busy → batched + ack sent per message - Batch flushed after 2s window or when current processing completes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Someone is attempting to deploy a commit to the op7418's projects Team on Vercel. A member of the Team first needs to authorize it. |
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
When a user sends multiple messages quickly from an IM channel (Feishu, Telegram, Discord), they are now aggregated into a single Claude prompt instead of being queued for serial one-by-one processing.
Problem
processWithSessionLock— each Claude call takes 30s–5min, so message 2 waits for message 1 to fully completeSolution
pendingBatchesMap toBridgeManagerStatefor per-session message aggregationBATCH_WINDOW_MSallows collecting multiple rapid-fire messages before flushingprocessWithSessionLock.finally()automatically flushes any messages that accumulated during processingBehavior
Key functions added
scheduleOrProcess()— routes messages to direct processing or batch queueflushBatch()— merges queued messages (text joined with---separators, attachments concatenated) into a singlehandleMessagecallPendingBatchinterface +BATCH_WINDOW_MSconstantTesting
tsc --noEmit)---separator, attachments concatenated🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com