fix(mcp): 仅取消指定 job 并确认脚本已停止 - #1
Open
xPeiPeix 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.
cancel_job(jobId)目前会先把任务标记为CANCELED,再调用全局stopAllScript()。MCP 启动的脚本运行在应用主进程,而这个停止调用通过Binder 操作的是独立脚本进程,因此目标脚本可能继续运行,也可能影响其他脚本。
这个修改保存
run_script和run_script_file返回的ScriptExecution,取消时只停止对应 job 的脚本引擎,并在确认引擎退出后再返回
CANCELED。同时增加原子状态转换和单 job 取消串行化:停止超时不会误报成功,重复取消可在
超时后重试,并发取消不会启动第二次停止操作。
补充了
JobTracker单元测试和 MCP 使用文档,覆盖定向取消、终态保护、停止失败、停止超时、重试和并发取消。
验证:
./gradlew :mcp:testDebugUnitTest(12 tests)./gradlew :mcp:lintDebug(0 errors)./gradlew :app:assembleV7Debug7.2.1-mcp-cancel-fix1后,通过run_script_file启动一个持续运行脚本,连续 3 次查询均为
RUNNING;调用cancel_job返回CANCELED,随后连续3 次查询均为
CANCELED,message 为engine stopped真机已覆盖单 job 的启动与停止路径;并发取消、停止失败和停止超时边界由单元测试覆盖。