Skip to content

Report input delivery and collect list rows across screens - #170

Merged
Derrors merged 5 commits into
Derrors:mainfrom
Julian0197:feat/input-delivery-and-list-collection
Nov 23, 2026
Merged

Derrors merged 5 commits into
Derrors:mainfrom
Julian0197:feat/input-delivery-and-list-collection

Conversation

@Julian0197

@Julian0197 Julian0197 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What and why

An agent can lose the reply to a tap that already reached the phone. Single input tools now expose delivery (not_sent, unknown, or sent) independently of field and screen readback. A lost acknowledgement ends the call with an uncertain result so the agent can inspect the phone before repeating input.

iphone_scroll_collect reads accessible rows across successive viewports, merges adjacent overlap, and can stop at a visible text match. It leaves the match on screen for a later decision. Bounds and a stop reason make the amount of scrolling explicit.

Maintainer review follow-up

Commit b9cdfe6 addresses the five input/readback issues and the four smaller review findings. WDA no longer replays missing Return, Tab or whitespace, including during replacement. It can still repair a stable missing digit suffix in a formatted field. Read-only WDA writes retain their fallback; input writes with uncertain delivery do not replay. Native paste rechecks the system permission prompt before tapping it again and accepts trimmed field displays as unverified.

The remote bridge distinguishes connection and authorization failures from a lost reply. Scroll search retains the swipe failure stage. A connected collector interrupted between gestures receives its partial rows, and the input error text avoids repeating screen-inspection guidance.

The physical-device results below apply to 95fe042. The native paste changes in b9cdfe6 await a device retest.

Tests

1. Unit tests

  • Targeted daemon, protocol, MCP and WDA tests passed on macOS, including existing replace: true, partial field readback, failed screen readback, and incomplete list snapshots.
  • interrupted_tool_reply_reports_unknown_instead_of_hanging_or_retrying, input_delivery_is_independent_of_field_and_screen_readback, and overlap_preserves_separate_rows_in_both_directions_and_skips_fixed_content.
  • 34 Viewer tests, 20 Python helper tests, regression-case test references and the bilingual documentation build passed locally.
  • Full Rust workspace tests, Clippy with warnings denied, repository formatting and terminal PTY checks passed locally. GitHub Actions passed Linux and macOS Rust tests and Clippy, both PTY jobs, MSRV, secret scanning, packaging and the documentation build.

2. Real-device regression

  • Compared upstream a876c12 with pre-review commit 95fe042 on the same iPhone and Mac. Before each measured run, opened Clock and waited for its tabs, cleared the Spotlight query, then returned Home. Both versions ran the unchanged 16 default steps in tests/device/run.py five times. All 80 calls passed on each version.
  • tests/device/compare.py flagged zero slower steps. The sum of per-step medians was 22.73 s on main and 20.30 s on this branch. These are five-run measurements on one phone.
  • The two focused scenarios passed 7/7. The first full scenario pass completed 58/63 checks before the USB connection dropped during idle. The isolated idle rerun is recorded below. The editing scenario independently confirmed field contents after replacement with both Latin and Chinese text.
  • In the first unprepared comparison, main timed out on three Spotlight waits. The branch timed out on five waits and had one early Clock read. The passing comparison above uses explicit, identical UI preconditions on both versions.

3. Regression cases

4. Real-device proof

  • iPhone 14 (iPhone14,7), iOS 27.0.1, portrait, native backend, macOS 26.6.2 (Apple Silicon). Clock selected the requested tab. The ordinary tap reported sent and successful screen readback. The missing label reported not_sent and kept the tab selected. A local socket relay suppressed the completed daemon reply after one real tap. Both versions selected the tab exactly once. Main exposed no delivery metadata. This branch returned unknown at the reply stage.
  • One Settings scroll returned four rows seen only before the gesture and seven seen only afterwards, checked against two independent complete reads. A visible unselected Clock tab matched with zero scrolls and stayed unselected. The two focused scenarios passed 7/7 checks.

After USB reconnection, both idle cycles passed (#157, 2/2, 87.7 s). The original daemon regained the same native device in Ready state. The original Viewer and MCP status call were verified after handback.

Native portrait hardware was available. WDA, iPad, landscape, and Linux device control have not been exercised on hardware here.

Hardware retest of review fixes (b9cdfe6)

On an iPhone 14 running iOS 27.0.1 with the native backend, all seven tap and list checks passed. The Settings scan returned seven rows unique to the first viewport and six unique to the last. Pausing a separate scan after one swipe returned 25 rows, including 13 from the first viewport. Dropping the reply after a real Clock tap produced one send and no replay.

Spotlight accepted the ordinary Chinese paste and the paste with surrounding spaces. The system paste permission dialog was observed and handled. One case is still open: pasting 北京\n reported delivery as sent and field readback as failed, although an independent read showed 北京. That screen read cannot establish what happened to the trailing newline. The failed readback reproduced twice. WDA was not exercised on this phone.

Checklist

  • Existing MCP tool names and parameters remain available.
  • No dependency changes.
  • Updated the English and Chinese changelogs and guides.
  • Only aggregate test evidence will be published.

@Julian0197
Julian0197 marked this pull request as ready for review November 23, 2026 07:30

@Derrors Derrors left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review notes (each checked against 95fe042). 5 behaviour issues, 4 nits.

Should fix before merge

  1. input.rs verify_typed: trailing \n can be re-sent → Return pressed twice (duplicate sends in chat apps).
  2. native.rs: “Allow Paste” is tapped only once; a missed first tap leads to a timeout.
  3. native.rs: paste check no longer trims, so text with a trailing newline/space is reported as failed although it was typed.
  4. http.rs: Write classification applies to read-only WDA requests, removing the HID/native fallback (type_text, replace, unlock check).
  5. input.rs missing_suffix: digit fields with display spaces are no longer repaired.

Nits: bridge reports unknown for definitely-unsent requests; tap_element scroll errors overwritten as not_sent; scroll_collect drops partial rows on interruption; doubled punctuation in input error suffix.

The overall direction (delivery separate from readback, multi-viewport collection) looks good.

// 剩下的一个字一个字慢慢补
let rest: Vec<char> = text.chars().skip(k).collect();
for c in &rest {
let Some(rest) = missing_suffix(before, &reads[0], &reads[1], text) else {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return can be sent twice for text ending in a control character (WDA path).

type_text("hi\n") into a single-line field that keeps focus and content after Return: the field reads back "hi", so newly_typed fails (length differs). Both reads are stable, so missing_suffix("", "hi", "hi", "hi\n") returns "\n", and the loop below sends "\n" again. In a chat app this sends the message twice. On main the whitespace-insensitive squash comparison treated this as success.

Suggestion: never repair whitespace/control characters. E.g. bail out (Typed::Unknown) when rest contains any control char, or only repair visible characters.

Comment thread crates/ictl-daemon/src/tools/native.rs Outdated
self.native_tap(g, x, y).await?;
let screen = self.ax_snapshot(g, AX_WAIT, true).await.map_err(Error::readback)?;
let tree = self.snapshot_tree(g, &screen).await.map_err(Error::readback)?;
if answered.is_none()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“Allow Paste” is now tapped at most once.

On main the prompt was tapped on every iteration it was visible. With answered.is_none(), if the first HID tap doesn't take (prompt still animating in, or the prompt reappears), the loop never taps again and waits out PASTE_WAIT, then reports Pasted::Missing with the prompt still on screen.

Suggestion: keep tapping while the prompt is present; if the goal is to avoid hammering, rate-limit by time since answered instead of tapping only once.

PasteTarget::Append(old) => {
paste_seen(elements::field_values(&tree.elements).as_deref(), old, text.trim())
PasteTarget::Append(Some((object, old))) => {
append_seen(focused_text_field(&screen), object, old, text)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paste verification dropped the text.trim() from main.

newly_typed requires the field to grow by exactly text.len() bytes. A single-line field strips newlines (and some fields trim surrounding spaces), so native type_text("北京\n") shows 北京, paste_seen returns Missing, and after PASTE_WAIT the call fails with a readback error even though the text went in. submit is also skipped.

Suggestion: normalise leading/trailing whitespace and newlines (as main did with trim()) before the newly_typed check.

sock.write_all(&req).await.map_err(not_sent)?;
sock.flush().await.map_err(not_sent)?;
// After writing starts, a failed write/flush isn't evidence that the phone didn't act.
let write_failed = |e: std::io::Error| std::io::Error::new(WRITE_FAILED, e);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write failures are now WdaError::Write for read-only requests too.

Before, a failed write/flush mapped to NotConnected → Unavailable, which read-only callers treat as "WDA not reachable, fall back". Now every request gets Write, including GET /wda/keyboard, focused_field, element-tree reads, and the lock check in ictl-unlock:

  • type_text: keyboard_shown() returning Write is no longer the Unavailable arm, so it fails instead of falling back to HID/native.
  • wda_replace: untouched only treats Unavailable as untouched, so Write becomes a preflight failure.
  • ictl-unlock::ensure_unlocked: Unavailable → NotLocked, but Write now propagates as an error.

A request that didn't fully write can't have been executed by a request that only reads, so it's safe to keep those as Unavailable. Suggestion: only classify as Write when acts(method, path); or have read-only callers treat Write like Unavailable.

let want = squash(text);
values.iter().any(|v| squash(v).contains(&want))
/// Repair only an observed append of the exact leading characters, stable across two fresh reads.
pub(super) fn missing_suffix<'a>(before: &str, first: &str, second: &str, text: &'a str) -> Option<&'a str> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Digit fields with display spacing are no longer repaired.

newly_typed strips whitespace for all-digit text, but missing_suffix uses the raw strings. A phone field formatted as 138 0013 8 never matches strip_prefix against 13800138000, so a dropped tail becomes Mismatch instead of being re-typed. main's typed_prefix squashed first and repaired this.

Suggestion: when text is all ASCII digits, strip whitespace from before/first/second before computing the suffix.

@@ -123,7 +123,23 @@ impl Link {
if let Err(e) = self.send(&msg, id.as_ref()).await {
match id {
Some(id) => {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: every send() failure for an input tool is reported as delivery: unknown, stage: transport, including cases where the remote certainly didn't act: r.send() failing to connect, or a non-2xx status such as 401/403/404 from remote::failure. The agent is then told to inspect the screen when it could simply fix auth and retry. Consider returning a distinct error from send() for "request not delivered / rejected" and mapping that to not_sent.

Comment thread crates/ictl-daemon/src/tools/input.rs Outdated
break;
}
let next = Box::pin(self.search_scroll(g, s.down)).await?;
let next = Box::pin(self.search_scroll(g, s.down)).await.map_err(Error::preflight)?;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: .map_err(Error::preflight) wraps whatever search_scroll returned into not_sent/preflight, discarding its own classification (e.g. a WDA Write/Timeout swipe is unknown). After one or more scrolls the screen has already moved, so not_sent tells the agent it's safe to repeat from scratch. Same for the scroll-back at the !s.down call below. Suggestion: once scrolled > 0 (or always for the swipe itself), propagate the original Error::Action instead of overriding it.

Comment thread crates/ictl-daemon/src/tools/scroll.rs Outdated
if !may_continue() {
return Err(ictl_l10n::trf!(
"滚动已中断,已滑动 {scrolls} 次",
"Collection interrupted after {scrolls} scrolls"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: on pause / cancel / takeover this returns a plain Msg error, so the rows already collected (and scrolls) are lost and the agent has to restart the scan. Consider returning the partial Data::ScrollCollection with a new ScrollStop::Interrupted, or at least including the collected rows in the text.

Comment thread crates/ictl-mcp/src/lib.rs Outdated
}
Ok(match (resp, input) {
(Response::Error { mut message, .. }, Some(input)) => {
message += match input.delivery {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the suffix is appended unconditionally. Many daemon messages already end with punctuation, e.g. the FocusChanged one (…no further keys or Return were sent.) becomes …were sent.. Input was sent. Inspect the screen before retrying. Some WDA timeout messages also already say to check the screen. Suggestion: trim trailing ./。 before appending, and skip the hint when the message already contains equivalent guidance.

@Derrors

Derrors commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks for the quick turnaround. I checked b9cdfe6 against the nine review comments, and all of them are addressed:

  1. verify_typed no longer repairs a suffix that contains control characters or whitespace, so Return can't be sent twice (covered by the new test and regression case chore(deps): bump rsa from 0.9.10 to 0.10.0 #164).
  2. "Allow Paste" is tapped again while the prompt is still visible.
  3. A paste whose surrounding whitespace was trimmed is reported as unverified instead of failing (Pasted::Trimmed).
  4. WdaError::Write is limited to requests where acts(method, path) is true, so read-only requests fall back as before.
  5. missing_suffix strips display spaces for all-digit text, so formatted phone fields are repaired again.
  6. The bridge reports not_sent for connect failures and 401/403/404, and unknown for other failures.
  7. Scroll-search failures keep their own delivery classification and say how many swipes completed.
  8. iphone_scroll_collect returns its partial rows with interrupted.
  9. The delivery hint no longer doubles punctuation or repeats existing screen guidance.

One thing remains: the branch now conflicts with main, but only in CHANGELOG.md and CHANGELOG.zh-CN.md, because 0.2.11 (#173) was released after this PR was opened and dated the previous Unreleased section. Could you rebase onto main and move this PR's changelog entries under the new [Unreleased] heading? No code conflicts are expected.

Derrors and others added 2 commits November 23, 2026 23:47
Release 0.2.11 dated the changelogs' Unreleased section; the Derrors#170 entries
stay under Unreleased, above 0.2.11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…licates

Found by running this branch on an iPhone 15 Pro Max (iOS 27.2.1, native)
and an iPad mini 5 (iPadOS 26.7.3, WDA, landscape) against main:

- Natively, iphone_type_text "北京\n" failed with "the field didn't show
  the text" although Spotlight showed 北京: a single-line field turns a
  pasted newline into a space (it reads «北京 »), which the trimmed
  comparison didn't accept. A field that differs only in whitespace is now
  Trimmed (readback unverified), as intended; main had accepted it.
  «北京\n上海» (reads «北京 上海») too.
- Through WDA, checking the field after typing read the focused element
  four requests at a time, twice, 0.3 s apart, and typing over a selected
  search (Spotlight keeps its last one) can never match: typing 设置 took
  4.39 s against main's 2.55 s. A reread now asks only which element has
  focus and its value (WdaClient::active_element), and a first read that
  settles the case (a selection replaced) answers at once.
- iphone_scroll_collect collected rows twice. Settings' large title
  collapses into the navigation bar, so the next viewport didn't start
  with the end of the previous one: a few elements may now lie between
  the overlap and the ends. Through WDA on an iPad split view no two
  viewports overlapped at all, and the 150-row limit came after two or
  three swipes: a detail row's Cell, label and chevron have middles a
  point apart, in an order that turned round as the list moved; the
  sidebar's navigation bar and search field stay put while its rows pass
  under them, between the rows in travel order; and the column that
  didn't scroll interleaves with the one that did. Elements are now
  ordered row by row (left to right within a row); when the tree has
  scroll areas only their content is matched, and the rest (bars, the
  list's own container) is new only when the previous viewport had
  nothing like it; the column that stayed is left out. A tree read
  natively has no scroll areas and is matched whole, as before. `x` picks
  where to swipe, so an iPad sidebar can be scanned.
- The bridge's "no matching JSON-RPC reply" message comes in both
  languages, and in Chinese it joins its hint with 。 (it read
  «…回复. 未收到远端工具结果…»); the Chinese changelog's parentheses;
  D10 counts 18 tools.

Regression cases 165-167.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit bd10e21 into Derrors:main Nov 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants