From e7de4db46871b9d048ebdb225973ad88c139e58a Mon Sep 17 00:00:00 2001 From: cosine <1726697408@qq.com> Date: Tue, 17 Nov 2026 16:18:29 +0800 Subject: [PATCH] fix(mcp): a tap by text that tapped nothing doesn't claim it had no effect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When iphone_tap_element finds nothing (or the index is out of range, or the element is fully covered) it taps nothing. With then, the answer still waited 0.7-0.8 s for the screen to settle and compared it with the tree read before the (absent) tap, so it went on to say "the screen is the same as before the action: it may not have taken effect … don't repeat the same action", as if something had been tapped. The daemon now drops the "before the action" screen when nothing was tapped, and the MCP server skips the settle in that case and lists the elements (or takes the screenshot) right away from the tree the tap just read. A tap that did happen settles and compares as before. On an iPhone 12 mini a missed tap with then=elements answers in 0.8 s instead of 1.3 s, without the misleading clause. Regression case #153. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ CHANGELOG.zh-CN.md | 2 ++ crates/ictl-daemon/src/core.rs | 8 ++++++- crates/ictl-mcp/src/lib.rs | 39 ++++++++++++++++++++++------------ docs/dev/regression-cases.md | 1 + 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d433e42..6511f70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ What changed in each release, one line per change. Versions follow [Semantic Ver ### Fixes +- `iphone_tap_element` that found nothing to tap no longer says, with `then`, that "the action may not have taken effect"; it also returns the screen without waiting for it to settle. + - A WDA probe that answers, even with an error, resets the timeout count instead of accumulating unrelated slow requests into a stall. Recovery logs state the reason, and timeout logs include the endpoint and elapsed time. ## [0.2.7] - 2026-11-15 diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index fa578f6..774f274 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -12,6 +12,8 @@ ### 修复 +- `iphone_tap_element` 没找到可点的元素时,带 `then` 不再说「操作可能没生效」,也不再等界面稳定,直接返回界面。 + - WDA 的短探测正常应答或返回远端错误时清零超时计数,不再把多个独立慢请求累计成卡死;恢复日志写明判定依据,请求超时日志包含端点和耗时。 ## [0.2.7] - 2026-11-15 diff --git a/crates/ictl-daemon/src/core.rs b/crates/ictl-daemon/src/core.rs index 6bc2b5b..81ebe9e 100644 --- a/crates/ictl-daemon/src/core.rs +++ b/crates/ictl-daemon/src/core.rs @@ -1215,8 +1215,14 @@ impl Daemon { }), Request::Tap { x, y } => self.tap(g, x, y, view).await, Request::TapElement { text, index, max_age_ms } => { - self.tap_element(g, &text, index, Duration::from_millis(max_age_ms)).await.map(|(t, missed)| { + let r = self.tap_element(g, &text, index, Duration::from_millis(max_age_ms)).await; + r.map(|(t, missed)| { outcome.tapped_nothing = missed; + // nothing was tapped: there is no "before the action" to compare the screen with, or the next + // settle would say the tap may not have taken effect + if missed { + g.dev.before_action = None; + } t }) } diff --git a/crates/ictl-mcp/src/lib.rs b/crates/ictl-mcp/src/lib.rs index 2d53ed2..f61987f 100644 --- a/crates/ictl-mcp/src/lib.rs +++ b/crates/ictl-mcp/src/lib.rs @@ -1016,7 +1016,9 @@ impl McpServer { Response::Text { text, outcome, .. } if req.is_device_action() => { // 结果里已经说了有弹窗(启动 App 被挡)就不再查 let check = wants_alert_check(&req) && !protocol::alert_reported(&text, outcome); - self.finish(text, false, then, check).await + // 按名字没点到东西:界面没动过,不用等它稳定,直接给界面(按名字点击刚读过的树) + let settle = !tap_missed(&text, outcome); + self.finish(text, false, then, check, settle).await } resp => to_result(resp), } @@ -1044,8 +1046,15 @@ impl McpServer { } /// 操作完成后:按 then 等界面稳定,再附上元素列表或截图(等稳定时顺带提醒弹窗)。 - /// 不带 then 时,`alert_check` 为真就查一下有没有系统弹窗挡着 - async fn finish(&self, mut text: String, failed: bool, opts: ThenOpts, alert_check: bool) -> CallToolResult { + /// 不带 then 时,`alert_check` 为真就查一下有没有系统弹窗挡着。`settle` 为假(什么都没点)时不等稳定 + async fn finish( + &self, + mut text: String, + failed: bool, + opts: ThenOpts, + alert_check: bool, + settle: bool, + ) -> CallToolResult { let done = |blocks: Vec| { if failed { CallToolResult::error(blocks) } else { CallToolResult::success(blocks) } }; @@ -1056,15 +1065,17 @@ impl McpServer { } return done(vec![ContentBlock::text(text)]); } - match self.call(&Request::Settle { max_ms: opts.settle_ms }).await { - Response::Text { text: t, .. } => text += &format!("\n{t}"), - Response::Error { message, .. } => { - text += &ictl_l10n::trf!( - "\n(等界面稳定失败:{message})", - "\n(waiting for the screen to settle failed: {message})" - ) + if settle { + match self.call(&Request::Settle { max_ms: opts.settle_ms }).await { + Response::Text { text: t, .. } => text += &format!("\n{t}"), + Response::Error { message, .. } => { + text += &ictl_l10n::trf!( + "\n(等界面稳定失败:{message})", + "\n(waiting for the screen to settle failed: {message})" + ) + } + Response::Image { .. } => {} } - Response::Image { .. } => {} } match then { Then::Elements(filter) => { @@ -1144,7 +1155,7 @@ impl McpServer { total - n )); } - return self.finish(lines.join("\n"), true, then, false).await; + return self.finish(lines.join("\n"), true, then, false, true).await; } Response::Text { text, outcome, .. } => { check = wants_alert_check(&req) && !protocol::alert_reported(&text, outcome); @@ -1160,12 +1171,12 @@ impl McpServer { total - n )); } - return self.finish(lines.join("\n"), true, then, true).await; + return self.finish(lines.join("\n"), true, then, true, true).await; } }, } } - self.finish(lines.join("\n"), false, then, check).await + self.finish(lines.join("\n"), false, then, check, true).await } } diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md index 5f0a9f3..7141ef1 100644 --- a/docs/dev/regression-cases.md +++ b/docs/dev/regression-cases.md @@ -149,3 +149,4 @@ | 143 | 原生:Spotlight 打开时选中上次的搜索词,再粘贴同样的词会把它替换成自己,输入框的值不变,`iphone_type_text` 报「粘贴了…但输入框里没有这段文字」(带 `submit` 时还不按回车),其实已经输进去了 | 「允许粘贴」点过之后,输入框原来就有这段文字、1.5 秒不变,算输入成功并提示截图确认;没点过「允许粘贴」时仍报错 | 单测 `a_paste_that_replaced_the_same_text_is_told_apart_from_one_that_missed` + 真机(Spotlight 留着「设置」时再输入「设置」,`run.py` 连跑两遍);真机脚本 `scenarios.py typing` | | 144 | 设备闲置时自动锁屏,下一个操作先自动解锁(iPad 经 WDA 约 15 秒,iPhone 原生约 9 秒),结果和事件日志都没说,看着像「切换设备后第一个操作慢」 | 结果第一行(截图在说明里、出错时在报错里)写「手机锁着,先自动解锁了,用时 X 秒」,事件日志记「已自动解锁」 | 单测 `an_unlock_first_is_said_on_the_answers_first_line` + 真机(锁屏后按名字点击、截图,两台设备);真机脚本 `scenarios.py lock` | | 145 | WDA 的短探测已正常应答或返回远端错误,却不清零超时计数,三个独立慢请求仍会触发重启;连接失败反而清零。日志还把长请求和短探测均未应答写成「连续 3 次」、宣称尚未检查的 `/status` 正常,请求超时本身缺端点日志 | 只有正常响应或远端错误清零,连接失败不清零;连续无应答和长请求后的失败探测分别记录原因及实际次数;超时诊断记录方法、短路径和耗时,不记录查询参数或正文 | 单测 `answered_probe_resets_stall_count_after_each_slow_request`、`connection_error_does_not_reset_unanswered_count`、`long_request_and_failed_probe_keep_the_actual_count_and_reason`、`three_short_unanswered_requests_report_a_consecutive_stall`、`answered_session_delete_does_not_mask_a_failed_probe`、`failed_request_log_keeps_endpoint_and_time_without_query`、`successful_request_log_does_not_include_response_body`;真机:同一 iPad、同一 WDA,把只读业务请求的客户端时限缩短到 20ms,短探测保留 5s,对照修复前后各 3 轮 | +| 153 | `iphone_tap_element` 没找到(或序号超出、整个被盖住)时什么都没点,带 `then` 却先等界面稳定 0.7~0.8 秒,再拿它点之前读的树比较,说「界面和操作前一样:操作可能没生效(点在了空白处…),不要原样再做一遍」,好像点过了 | 没点就清掉「操作前的界面」,不做比较;MCP 端看到没点到东西时不等稳定,直接用按名字点击刚读的树列元素或截图 | 真机(iPhone 12 mini,iOS 26.4.1:设置里按不存在的文字点,带 `then=elements` 和 `then=screenshot`,0.2.7 是 1.3~1.45 秒带那句提示,本分支 0.6~0.9 秒不带;只换守护进程(旧 MCP)时仍等稳定但也不带;按存在的文字点照常等稳定、说界面变了)|