fix(wechat): suppress buffered output after /stop - #748
Open
imMamdouhaboammar wants to merge 1 commit into
Open
Conversation
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.
Problem
Upstream issue #396 reports that WeChat
/stopaborts the agent but the handler keeps draining buffered turn output. Currentmainalready labels the final state[已停止], but it still sends buffered text after the stop flag and can send files referenced by the cancelled result.Root cause
on_message()used a per-user abort flag, but_handle()did not observe it until after its display-queue loop. That allowed buffered turn text and cancelled-result files to escape after/stop. Review also exposed two edge cases: an idle/stopcould leave a stale flag for the next task, and setting the flag afteragent.abort()left a small race where the worker could consumedonebefore the abort became visible.Fix
/stop_task_aborted[uid]before callingagent.abort()_send()calls once the abort flag is set[已停止]acknowledgement, return immediately so cancelled result files are not deliveredThe task queue, WeChat protocol, authentication, and agent abort implementation are unchanged.
Regression coverage
tests/test_wechat_stop.pyuses a fake agent and fake bot, with no WeChat network/login or LLM calls. Import stubs exist only duringwechatapp.pyimport andsys.path/HOMEare restored immediately. It covers:/stopis not sentdoneresult is not sent/stopwhile idle does not cancel the next taskagent.abort()runsTDD verification
Original issue #396 validation:
31165947230: compile/import passed; both post-stop regressions failed on currentmain31166076487: minimal fix passed compile, both regressions, andgit diff --checkReview finding, stale idle stop:
31166842462: the two original tests passed; only the idle-stop regression failed31166942104: all three tests, compile, andgit diff --checkpassedAbort ordering race:
31167274233: three existing tests passed; ordering test observed the flag asFalseinsideagent.abort()31167408972: all four tests, compile, andgit diff --checkpassed after arming the flag firstThe final PR commit is rebuilt directly from
mainusing the exact production/test blobs from the last GREEN validation, so the contribution remains one commit and two changed files.Scope
frontends/wechatapp.py: focused/stophandling changes onlyFixes #396