Discord: fix chunk delivery order for long messages#32819
Discord: fix chunk delivery order for long messages#32819haosenwang1018 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
When delivering chunked Discord replies, bypass sendMessageDiscord for the bot-send path and call sendDiscordText directly with a pre-resolved channel ID and retry runner. This eliminates per-chunk overhead (channel-type GET request, recipient resolution, re-chunking, client creation) that caused ordering issues under RequestClient queue contention or rate limiting. Fixes openclaw#32743
Greptile SummaryThis PR fixes Discord chunk delivery ordering by pre-resolving the channel ID and retry runner once in Key observations:
Confidence Score: 4/5
Last reviewed commit: 3f58840 |
| const request: RetryRunner | undefined = channelId | ||
| ? createDiscordRetryRunner({}) | ||
| : undefined; |
There was a problem hiding this comment.
The retry runner is created whenever channelId resolves, but it is only consumed in sendDiscordChunkWithFallback when both params.request and params.rest are provided (line 117). When params.rest is undefined, the runner is allocated but never used. Consider checking params.rest to avoid unnecessary allocation:
| const request: RetryRunner | undefined = channelId | |
| ? createDiscordRetryRunner({}) | |
| : undefined; | |
| const request: RetryRunner | undefined = channelId && params.rest | |
| ? createDiscordRetryRunner({}) | |
| : undefined; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/discord/monitor/reply-delivery.ts
Line: 200-202
Comment:
The retry runner is created whenever `channelId` resolves, but it is only consumed in `sendDiscordChunkWithFallback` when both `params.request` and `params.rest` are provided (line 117). When `params.rest` is undefined, the runner is allocated but never used. Consider checking `params.rest` to avoid unnecessary allocation:
```suggestion
const request: RetryRunner | undefined = channelId && params.rest
? createDiscordRetryRunner({})
: undefined;
```
How can I resolve this? If you propose a fix, please make it concise.|
Superseded by #33226 (combined Discord chunk ordering + retry fixes). |
Summary
deliverDiscordReplynow pre-resolves the channel ID and retry runner once, then sends each text chunk directly viasendDiscordTextinstead of routing through the fullsendMessageDiscordpipeline per chunk. This eliminates per-chunk overhead (channel-type GET, recipient re-resolution, re-chunking, client creation) that caused ordering issues under RequestClient queue contention or rate limiting.sendMessageDiscordfunction itself, and thesendDiscordTextinternal implementation are all untouched. The fallback tosendMessageDiscordremains for cases whererestis not provided (e.g., CLI/outbound sends).Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Discord message chunks now arrive in the correct sequential order when a long reply is split into multiple messages.
Security Impact (required)
Repro + Verification
Environment
textChunkLimit: 2000,maxLinesPerMessage: 17)Steps
Expected
Actual
Evidence
sends text chunks in order via sendDiscordText when rest is providedverifies chunk orderingfalls back to sendMessageDiscord when rest is not providedverifies fallback pathHuman Verification (required)
Compatibility / Migration
Failure Recovery (if this breaks)
sendMessageDiscordis still present whenrestis not providedsrc/discord/monitor/reply-delivery.tssendDiscordTextmock path has a type mismatch)Risks and Mitigations
sendDiscordTextdoes not perform forum/media channel detection (whichsendMessageDiscorddoes viaresolveDiscordChannelType)sendMessageDiscordfor outbound sends.