Repository navigation
fix(mcp): stop caching a failed pnpm probe - #1507
Open
yoruuuchan wants to merge 1 commit into
Open
yoruuuchan wants to merge 1 commit into
yoruuuchan wants to merge 1 commit into
Conversation
isPnpmInstalled() stored a negative result for the lifetime of the MCPStarter instance, including when the probe could not run because the shared terminal session was not ready yet. A cold start that probed too early then made every later initBridge() with npx plugins return at the pnpm check, before deployBridge/startBridge. Cache only a successful probe. A missing session or a failed command now returns false without writing the cache, so the next call probes again once the terminal is ready. Fixes AAswordman#1433
CATMIAOZHI
self-requested a review
November 16, 2026 13:36
CATMIAOZHI
approved these changes
Nov 16, 2026
CATMIAOZHI
left a comment
Collaborator
There was a problem hiding this comment.
审计结论:✅ 批准合并
改动(1 个文件,+10/−7):MCPStarter.isPnpmInstalled() 只缓存探测成功的结果,失败(共享终端会话未就绪 / executeCommand 抛异常 / 未装 pnpm)不再写入缓存,修复冷启动时失败结果被缓存、导致同一 MCPStarter 实例内后续 initBridge() 一直在 pnpm 检查处返回、走不到 deployBridge / startBridge 的问题(Fixes #1433)。
通过的检查:
- 目标分支为
dev,符合要求。 - 缓存语义修正正确:入口改为
if (pnpmInstalled == true) return true,只有command -v pnpm命中才写缓存;会话为 null 时记一条 warn 返回 false、命令抛异常时记 error 返回 false,两路都不写缓存,与 PR 描述逐项一致。 - 改动范围与描述一致:只动私有函数内部,未碰
START_COMMAND_THROTTLE_MS、bridge 生命周期、UI、MCPBridge;无新增依赖、无字符串改动。 - 失败重试的代价可控:pnpm 确实未安装时每次启动流程会重新执行一次
command -v pnpm,开销可忽略(PR 描述中已说明此取舍)。 - 无密钥 / 权限 / 外部输入相关改动;无新增用户可见字符串;
result.contains("pnpm")的判定逻辑沿用旧代码,未改动。
问题:
- [P2]
catch (e: Exception)会吞掉CancellationException:isPnpmInstalled()是 suspend 函数,terminal.executeCommand()内部在deferred.await()上挂起,探测中的协程被取消时会以CancellationException抛出;当前 catch 会把它当作普通探测失败记一条 error 日志并返回 false,调用方随后按"pnpm 未安装"上报NODEJS_MISSING,而不是按取消处理。建议在 catch 之前加catch (e: CancellationException) { throw e }。这是该函数原有写法、本 PR 改写 try/catch 时未顺带处理,不阻塞本次合并,可后续跟进。 - [P3] 单次失败启动会探测两次:
initBridge()内isPnpmInstalled()返回 false 后,startPluginInternal()的状态映射处又调一次isPnpmInstalled(),失败结果未缓存时等于一次启动跑两遍command -v pnpm。开销可忽略,可接受;如想省一次,可把 initBridge 的探测结果往外带。
后续可跟进(不阻塞):作者已说明未在真机上复现冷启动时序、未跑 Gradle 构建与单测;改动仅限私有函数缓存语义,风险低,建议合并后在真机冷启动场景验证一次 pnpm 探测重试是否生效。
由 水晴喵的muse 审计
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.
变更说明 / Description
MCPStarter.isPnpmInstalled()把探测失败也当成确定结果缓存:无论是拿不到共享终端会话,还是terminal.executeCommand抛异常,都会写入pnpmInstalled = false。后续调用看到缓存非空就直接返回,不再重新探测。背景与动机 / Context and motivation
Issue #1433:冷启动时共享终端会话可能还没就绪,pnpm 探测失败;失败结果被缓存后,同一个
MCPStarter实例内的后续initBridge()都在 pnpm 检查处直接返回,走不到deployBridge/startBridge。缓存把「探测没做成」和「确认没装 pnpm」混成了同一种状态。改动范围 / Changes
isPnpmInstalled()只缓存成功结果,入口判断改为if (pnpmInstalled == true) return true。terminal.executeCommand抛异常时返回 false,不写缓存。START_COMMAND_THROTTLE_MS、bridge 生命周期、UI、MCPBridge([Bug] MCP 启用开关只写入配置、不启动服务器;bridge 随 App 进程组被回收,导致 MCP 恒为 0/N #1436 的范围)。兼容性与风险 / Compatibility and risks
command -v pnpm;开销可忽略,换来的是终端就绪后下一次调用会重新探测,而不是一直沿用第一次的失败结果。关联 Issue / Related issue
Fixes #1433
验证方式 / Verification
证据 / Evidence
无(未在设备上采集日志)。
检查清单 / Checklist
Candidate checks覆盖改动范围,并会处理技术失败项 /Candidate checkscovers the change scope and technical failures will be addressed