fix(extensions/feishu/src/reply-dispatcher.ts): missing cleanup in error path#50680
fix(extensions/feishu/src/reply-dispatcher.ts): missing cleanup in error path#50680Maple778 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
…ror path Pattern from PR openclaw#47902 The bug pattern 'missing cleanup in error path' describes a scenario where a resource cleanup routine (`releasePluginRouteRegistry`) is skipped if an error occurs during the shutdown sequence. The provided code context for `startStreaming` in `extensions/feishu/src/reply-dispatcher.ts` contains a function `closeStreaming` (lines 290-308) which acts as the shutdown sequence for this component. `closeStreaming` performs multiple asynchronous operations: 1. `await streamingStartPromise;` (Line 292) 2. `await partialUpdateQueue;` (Line 294) 3. `await streaming.close(...)` (Line 301) If any of these `await` operations throw an exception (e.g., network error during `streaming.close`), the execution halts immediately. The subsequent cleanup lines (`streaming = null`, `streamingStartPromise = null`, and state resets) are skipped. Consequently, the `streaming` object is not properly dereferenced/nullified, and internal state variables (`streamText`, `reasoningText`) retain stale data, leading to potential memory leaks and state corruption in subsequent retry attempts. The fix requires wrapping the body of `closeStreaming` in a `try...finally` block and moving all variable nullifications/reset operations into the `finally` block to guarantee execution regardless of failure.
Greptile SummaryThis PR adds
Confidence Score: 5/5
Last reviewed commit: "fix(extensions/feish..." |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 398fc511df
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } finally { | ||
| streaming = null; | ||
| streamingStartPromise = null; |
There was a problem hiding this comment.
Keep the streaming session until close actually succeeds
This finally block clears streaming/streamingStartPromise even when FeishuStreamingSession.close() throws. In the info.kind === "final" path, that rejection makes deliver() fail and createReplyDispatcher() immediately invokes onError, but the retry at extensions/feishu/src/reply-dispatcher.ts can no longer close the existing card because the session was already nulled out here. A transient Feishu/network failure now leaves the card stuck in streaming mode and drops the final reply instead of allowing the existing error path to retry it.
Useful? React with 👍 / 👎.
| streaming = null; | ||
| streamingStartPromise = null; | ||
| streamText = ""; | ||
| lastPartial = ""; | ||
| reasoningText = ""; |
There was a problem hiding this comment.
Reset
partialUpdateQueue when running error cleanup
The new cleanup resets the text buffers but leaves partialUpdateQueue pointing at the same promise that just failed. If an earlier streaming.update() or partialUpdateQueue await rejected, the next flushStreamingCardUpdate() still does partialUpdateQueue = partialUpdateQueue.then(...) on a rejected promise, so its callback never runs and later closeStreaming() calls fail immediately again. Because this patch is explicitly trying to make post-error retries work, omitting the queue reset leaves every subsequent streamed reply in this dispatcher broken after the first update/close error.
Useful? React with 👍 / 👎.
|
Closing as superseded by #71542. The merged follow-up wraps Feishu streaming close cleanup in a Thanks for flagging the missing cleanup path; the safer current-main version is now landed. |
The `closeStreaming` function in `extensions/feishu/src/reply-dispatcher.ts` could skip cleanup if any async operation threw an exception.
Changes: