Skip to content

fix(android): require acknowledgements for test IME typing - #4722

Merged
thymikee merged 10 commits into
mainfrom
t3/ime-ack-review-fixes
Nov 20, 2026
Merged

thymikee merged 10 commits into
mainfrom
t3/ime-ack-review-fixes

Conversation

@thymikee

@thymikee thymikee commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Require an ordered acknowledgement from the Android test IME and split large text on code-point boundaries. The acknowledgement reports attempted UTF-16 length and the editor API result. Fill still verifies the resulting field value through its existing readback.

The v2 receiver returns codes and lengths only. A helper without v2 acknowledgement support refuses typing with a reinstall hint. Bundled helpers upgrade with the CLI. With no focused editor, the helper returns no-input-connection instead of a false success. Refs #4520.

Validation

Base 6e18ea3349685f3cf6cec4c2e6d1104980ab2738; tested head f265d1f9a09f7128379d89f24d6e1e031d8d7b2a.

  • pnpm check:affected --run --head f265d1f9a0 passed: 42 checks, 25 hosted or parked skips, exactCommit=true. Its first run failed only on vitest-related: two unrelated provider-integration scenarios could not attach to a live daemon, cause unproven. Both pass solo, and one rerun passed. Earlier head f4ad9a57749 had the same receipt.
  • Live run at f4ad9a5774 on emulator Pixel_7_CI (Android 16), CLI and helper built from it: fix(android): require acknowledgements for test IME typing #4722 (comment). Later heads change host retry routing and its tests only, so this run still covers the helper.
    • ASCII and mixed Unicode type returned ok with commitText code=1.
    • 50,001 UTF-8 bytes gave two code=1 acks. type and fill read back the full text exactly in a multiline field.
    • fill read back exactly, also when the field already held the value.
    • A pre-v2 helper was refused with android_ime_helper_no_ack and the reinstall hint. The field did not change.
    • With no focused editor (tab switch, or a window with no editor), type reports no-input-connection.
    • Logcat had 0 matches for the typed text.
  • Live run at f265d1f9a0 on the same emulator: a test-IME fill whose clear was acked and whose first text chunk got no-input-connection made one rebind and one recovery attempt, then read back exactly (19 of 19 forced attempts): fix(android): require acknowledgements for test IME typing #4722 (comment)
  • CI: Coverage fails on main's stale recording-overlay source (fix in fix(recording): regenerate the embedded recording overlay source #4737), not on this change.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.44 MB 6.44 MB +2.1 kB
Package (unpacked) 6.44 MB 6.44 MB +2.1 kB
Package (download) 1.96 MB 1.96 MB +2.0 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 21.9 ms 18.2 ms -3.7 ms
CLI --help 46.0 ms 39.8 ms -6.2 ms

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 4 new findings on d7045ea. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The code at 3ecac96 looks right to me, but the live Android evidence does not cover it yet. The recorded device run was made at d7045ea, where the receiver ran handleAction on a worker thread. Head 3ecac96 changed the native path after that run: the receiver now commits on the main thread with a synchronous finish, it adds the plain-text byte bound at lines 165-170, and the fill clear/retry routing changed. Nothing shows a run of the helper and CLI built from this head, so the ordered ack, the chunked commits and the fill read-back are unproven for the code that will merge. Could you rebuild the helper and CLI at 3ecac96 and run them on an Android device, then record the SHA, device, commands and output? The run should show: (a) type of ASCII and of mixed Unicode with surrogate-pair emoji returns ok, and AgentDeviceTestIME logcat shows commitText code=1 length=<n>; (b) type of more than 48,000 UTF-8 bytes gives two code=1 acks, and a snapshot or read-back shows the full text; (c) fill with an exact read-back, including a field that already holds the value; (d) a helper that does not answer (a v1 APK or an unregistered receiver) is refused with android_ime_helper_no_ack and the field is unchanged; (e) if you can reproduce it, type with no focused editor reports no-input-connection; (f) a logcat grep shows no user text.

The next three points are smaller but affect behavior. First, a failed commit never reaches the retry: only a no-input-connection rejection with dispatchedSteps===0 goes to the refocus/rebind retry, while a commit-returned-false from a text chunk, or from a clear whose read-back mismatches, throws straight out of fillAndroidImeHelper. On API 31+ the IME-side commitText returns false mainly when the binder call fails, which is the stale-session case that only a rebind fixes, and before this PR it fell through to verification and then rebind and retry. The rule should be: a dispatch the helper proves did not land never ends the fill before the one rebind retry. Second, partial dispatch uses a new ad-hoc details.dispatchedChunks, set by mutating error.details (text-input.ts:309). The existing evidence key is dispatchedSteps, which the daemon ledger reads. If chunk 2 of a single long line fails after chunk 1 committed, the error carries no dispatchedSteps, so the ledger misses the partial dispatch. Planning each byte-bounded piece as a plan step would make discloseDispatchAfterSteps cover it and remove dispatchedChunks. Third, the surrogate-pair test uses 12,000 four-byte emoji, which is exactly 48,000 bytes, so the split falls between whole code points and a naive byte or UTF-16 slice would also pass. Starting the string with 'a' makes the boundary land mid-pair. Also, the README sentence that says a malformed broadcast can never crash the IME process no longer holds, because the catch is now RuntimeException and an Error escapes onReceive. Please restore catch (Throwable) or reword it. Last, type through the test IME now fails with typed reasons where it used to report success, and the issue lists the docs semantics as a completion item, but no user doc changed. One sentence in the test-IME section of known-limitations would cover it: type fails when no editor is focused or the helper predates the acknowledgement protocol, and reinstalling or reopening fixes the latter.

Could the capability probe go? The v2 ordered ack and the code-point chunking look right, but isProtocolAcceptable already drops any broadcast whose protocol extra does not match, so every pre-v2 helper answers result=0 on its first text or clear dispatch with nothing committed, and assertCommittedOutcome already refuses no-ack. Deleting ACTION_PROBE end to end (the Java handler and Bundle, the host constant and its transport special case, the probe-ok variant, imeHelperAckSupport, the probe and assert functions, the ensure-time cache invalidation, the ForTests hook and the probe tests) would remove roughly 100 lines and the process-global cache, and leave one transport classifier. The reinstall hint can move onto the no-ack error. With the dispatchedSteps change above and details.reason in place of failureReason, matching the sibling Android text reasons, the design gets smaller without losing the refusal.

Not blocking: you can take or leave dropping the six new names re-exported from the public ./mechanics entry, since nothing imports them through it and one is a ForTests hook, and adding one provider-scenario type case whose fake answers result=3 or result=0 to check the typed failure on the RPC response.

The four inline threads from the earlier review round no longer apply at 3ecac96, so they can be resolved: worker thread in the receiver (r4622453697), no-input-connection retry (r4622453724), plain-text byte bound (r4622453728), and already-matching clear read-back (r4622453738); each is fixed at this head.

All 17 checks pass at 3ecac96. The unit and provider-scenario suites cover the host route through fakes, but CI does not build or run the native helper on a device. Before merge, we need the head-built Android run above, and a decision on the capability probe.

@thymikee

Copy link
Copy Markdown
Member Author

Review follow-up. Head: 697f7b988a. Commits: f5cfb72 and 697f7b988a.

1. A failed dispatch now gets the rebind retry. A commit-returned-false from a text chunk or from a clear now goes to the one refocus/rebind retry (text-input.ts, attemptFillWithRetry). A clear that returns false and whose read-back does not match also retries. no-input-connection still retries only when no step was dispatched. Tests: fillAndroid rebinds after a dropped commit (code 2) and fillAndroid requires a matching readback after clear refusal (match=false). The second test shows two clears.

2. dispatchedChunks is gone. The code no longer changes error.details. planAndroidTextSteps now takes a line chunker. Each piece of up to 48,000 bytes is one plan step, so discloseDispatchAfterSteps reports dispatchedSteps. Fill also counts each piece. Test: typeAndroid reports a partial dispatch truthfully when a later chunk is rejected expects dispatchedSteps: 1.

3. Surrogate-pair test. The string now starts with 'a'. The first chunk is 47,997 bytes, and the boundary is inside a pair.

4. README and receiver. onReceive uses catch (Throwable) again. The README says that the handler catches every Throwable and reports it as a rejected broadcast.

5. User doc. known-limitations.md, test-IME section: "With the test IME, type fails if no editor is focused or the helper does not acknowledge the command. For an older helper, reinstall a current version and reopen the session."

6. The capability probe is removed. I removed ACTION_PROBE in all places: the Java handler and Bundle, the host constant and its transport special case, probe-ok, imeHelperAckSupport, the probe and assert functions, the cache delete at ensure time, the ForTests hook, and the probe tests. A pre-v2 helper answers result=0 on its first dispatch, and the host refuses it as android_ime_helper_no_ack. The reinstall hint is now on that no-ack error. Errors use details.reason, not failureReason.

7. Optional items. I removed the six new re-exports from mechanics.ts, because nothing imports them. I added one provider scenario: Provider-backed Android test-IME type returns the typed helper failure on the RPC response. The fake answers result=3, and the RPC error has reason: android_ime_helper_dispatch_rejected and dispatchKind: no-input-connection. The fake then answers result=0, and the RPC error has reason: android_ime_helper_no_ack and the reinstall hint.

8. Inline threads. r4622453697, r4622453724, r4622453728 and r4622453738 are resolved.

Live run: pending. Reason: shared emulator busy. Another session owns emulator-5554. A separate run on a head-built helper and CLI follows on a different emulator. That run will record (a) to (f) at this head. Results from f5cfb72 are not evidence for this head, because this head changes the receiver catch.

Checks. Focused unit tests pass (text-input-test-ime, ime-helper-ack, ime-rebind). The new provider scenario is in test/integration/provider-scenarios/android-ime-type.test.ts and passes. pnpm check:affected --run: passed (exactCommit=true).

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on 697f7b9. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

Live Android run at 697f7b9

This run covers head 697f7b988ad60339abbae36339a8420843baa5a7. I built the CLI and the IME helper from this head. I did not change source code.

  • Device: emulator emulator-5554 (Pixel_7_CI, Android 16).
  • Build: pnpm install --frozen-lockfile && pnpm build && pnpm build:android, then pnpm clean:daemon.
  • Helper: agent-device-android-ime-helper-0.21.40-dev.apk, sha256 b1f27be5…1002ed. I installed it with adb install -r. snapshot -i --json shows backend: android-helper, helperVersion: 0.21.40-dev.
  • CLI: node bin/agent-device.mjs --session live-4722 --platform android --serial emulator-5554 …. The app is com.callstack.agentdevicelab, opened with open com.callstack.agentdevicelab agent-device-test-app:///form.
  • fill with delay 0 uses the accessibility helper. To test the test-IME fill path, I added --delay-ms 1.
Case Result
(a) ASCII and Unicode type Pass
(b) More than 48,000 UTF-8 bytes Pass for the chunks and acks. I could not show a full read-back. See below.
(c) fill with read-back Pass
(d) Helper that does not answer Pass
(e) No focused editor Not reproduced. type reports success. See below.
(f) No user text in logcat Pass

(a)

$ agent-device type "LiveAscii4722 ok"        -> Typed 16 chars ; get text -> LiveAscii4722 ok
$ agent-device type "Zażółć 東京 😀👍🏽 a😀b"   -> Typed 17 chars ; get text -> Zażółć 東京 😀👍🏽 a😀b
I AgentDeviceTestIME: commitText code=1 length=16
I AgentDeviceTestIME: commitText code=1 length=21

(b)

The input is "a" + "😀"×12500. That is 50,001 UTF-8 bytes and 25,001 UTF-16 units. The leading a puts a byte split inside an emoji pair. The helper split the text on a code point.

$ agent-device type "$LONG" --json   -> success, "Typed 12501 chars"
I AgentDeviceTestIME: commitText code=1 length=23999
I AgentDeviceTestIME: commitText code=1 length=1002
$ agent-device fill id=field-name "$LONG" --delay-ms 1 --json
  -> success, "Filled 12501 chars", "verification": "unconfirmed", after = 4999 UTF-16 units
I AgentDeviceTestIME: clearText code=1
I AgentDeviceTestIME: commitText code=1 length=23999
I AgentDeviceTestIME: commitText code=1 length=1002

23,999 + 1,002 = 25,001. The read-back shows an exact prefix, but only 5,000 units. On this image, the lab app field keeps at most 5,000 UTF-16 units. The cap is in the field, not in the helper. Control test: I typed 6,000 ASCII characters after S (ack commitText code=1 length=6000). Then I sent 3,000 backspaces. The field kept 2,000 characters, not 3,001. Thus the field held 5,000 characters after the commit. fill reports unconfirmed for this case, which is correct. To show a full read-back, use an editor with no length cap.

(c)

$ agent-device fill id=field-email "FillCase4722 Łódź 😀x" --delay-ms 1 --json -> success, "Filled 20 chars" (no unconfirmed flag)
$ agent-device fill id=field-email "FillCase4722 Łódź 😀x" --delay-ms 1 --json -> success (field already held the value)
$ agent-device get text id=field-email -> FillCase4722 Łódź 😀x
I AgentDeviceTestIME: clearText code=1
I AgentDeviceTestIME: commitText code=1 length=21     (once for each fill)

(d)

I built the helper from 204c6271cf^ (before #4520, no setResult). I packaged it as 0.21.99, so the CLI keeps this install. Before the test, the field held KeepMe4722.

$ agent-device type "ShouldNotLand4722" --json
  -> COMMAND_FAILED, reason android_ime_helper_no_ack, dispatchKind no-ack, requestedUtf16 17, dispatched unknown
$ agent-device fill id=field-email "ShouldNotLand4722b" --delay-ms 1 --json
  -> COMMAND_FAILED, reason android_ime_helper_no_ack, requestedUtf16 0 (clear step), dispatchedSteps 1
$ adb shell am broadcast -p com.callstack.agentdevice.imehelper -a …ACTION_INPUT_TEXT_B64 --es protocol android-ime-helper-v2 --es text <b64>
Broadcast completed: result=0
$ agent-device get text id=field-email -> KeepMe4722   (after each step)

Then I removed the old helper and installed the head-built helper again.

The same refusal also occurred without a planned test. During the run, a process outside this session set the default IME back to Gboard 3 times (device time 11:46:12, 11:51:58 and 11:56:25). After each reset, the helper service was not bound. type returned android_ime_helper_no_ack, and the field did not change. When I reopened the session, the helper became the IME again. I did not find the process that made the change.

(e)

I opened the Home tab, which has no text field (mServedView=null). Android 16 then gives the IME a fallback BaseInputConnection, and commitText returns true on it.

$ agent-device type "NoEditor4722" --json -> success, "Typed 12 chars"
I AgentDeviceTestIME: commitText code=1 length=12
$ adb shell am broadcast … --es text <b64 "RawNoEditor4722">
Broadcast completed: result=1, data="utf16=15"

No text appeared on the screen. Thus, on this device, type with no focused editor reports success. It does not report no-input-connection or no_ack. I recorded the result as it occurred.

(f)

I ran adb logcat -d -b all after the final run (18,832 lines). Each of these strings has 0 matches: LiveAscii4722, Zażółć, 東京, 😀, 👍, FillCase4722, Łódź, and base64 prefixes of the payloads. The AgentDeviceTestIME lines contain only codes and lengths.

Cleanup: I closed the session, and the default IME is Gboard again. I did not add an adb forward or reverse. The emulator is still running. The raw logs are in the worktree under .tmp/live-4722/ and are not committed.

@thymikee

Copy link
Copy Markdown
Member Author

Thanks for the update. At 697f7b9, the earlier findings from the 3ecac96 review look fixed in the code: the receiver no longer needs a worker thread, the retry covers the no-input-connection and commit-returned-false cases, the plain input branch rejects text over the size bound, and a mismatching read-back after a clear now retries.

One thing remains. This head changes the native receiver (catch Throwable, probe removal) in TestInputMethodService.java:71 and the host retry routing in text-input.ts:338. No run with a helper and CLI built from this head has been posted, and the PR says it is pending. CI does not build the native helper or type through the test IME on a device, so the ordered ack, the chunking over the 48,000-byte bound, the v1 refusal and the fill read-back are unproven for the code that will merge. Please post one run from a helper and CLI built at 697f7b9 or later, with the SHA, device/API, commands and output. It should show: (a) type of ASCII and mixed Unicode with a surrogate-pair emoji returns ok, and AgentDeviceTestIME logcat shows commitText code=1 length=<n>; (b) type of more than 48,000 UTF-8 bytes gives two code=1 acks and a read-back shows the full text; (c) fill with exact read-back, including a field that already holds the value; (d) a v1 APK or unregistered receiver is refused with reason android_ime_helper_no_ack plus the reinstall hint, and the field is unchanged; (e) if you can reproduce it, type with no focused editor reports no-input-connection; (f) a logcat grep shows no user text.

Not blocking: known-limitations.md:41 names only type, but fill now also fails with a v1 helper, so you could say "type and fill fail if the helper does not acknowledge the command; type also fails if no editor is focused." Take it or leave it.

On the open inline threads: the thread on clear/retry routing and thread on the receiver thread look fixed at this head, as do the threads on the size bound and the clear read-back, so you can resolve them. The thread on failure reason codes in CLI help does not apply: versioned help does not list reason codes for type or fill, and the behavior is in the user docs and typed constants.

On CI, the Smoke Tests failure looks unrelated. It fails at live-automation-scenario.ts:252 in a snapshot, back, diff check where Back did not leave the automation screen. That route does not reach the text input code. The Coverage job log is cut off before any failure line, so its cause is unclear. It has been re-run, since this PR changes platform-android unit tests.

Before merge, please post the head-built Android run above and make sure Coverage passes.

@thymikee

Copy link
Copy Markdown
Member Author

Live Android run at f4ad9a5 (new head)

This run covers the new head f4ad9a5774937067f71be1433f01175551d9881a. I built the CLI and the IME helper from this head.

  • Device: emulator emulator-5554 (Pixel_7_CI, Android 16, API 36).
  • Build: pnpm install --frozen-lockfile && pnpm build && pnpm build:android (AGENT_DEVICE_ANDROID_BUILD_TOOLS=36.0.0), then pnpm clean:daemon.
  • Helper: agent-device-android-ime-helper-0.21.40-dev.apk, sha256 7f82c5175f0b…65505c718a. snapshot -i --json shows androidSnapshot.backend: android-helper, helperVersion: 0.21.40-dev.
  • CLI: node bin/agent-device.mjs --session live-4722b --platform android --serial emulator-5554 ….

The fix for (e)

On 697f7b9, type with no focused editor returned ok. The cause: commitText returns true even if no view gets the text. I found two cases on API 36:

  1. A window gains focus with no editor (for example, Settings opens). The IME then has the client binding's placeholder connection.
  2. An editor loses focus in the same window (for example, a tab switch in the lab app). The old connection stays started, but the client deactivated it. dumpsys input_method shows mServedView=null and mInputStarted=true.

The helper now finds the focused editor before each commit or clear. It returns code 3 (no-input-connection) if the connection is the binding's placeholder, or if getTextBeforeCursor(0, 0) returns null. A deactivated connection returns null. A real editor returns an empty string. A zero length reads no user text. The host already maps code 3 to dispatchKind: no-input-connection. A new host test covers the type result.

Case Result
(a) ASCII and Unicode type Pass
(b) More than 48,000 UTF-8 bytes, full read-back Pass
(c) fill with exact read-back Pass
(d) v1 helper refused, field unchanged Pass
(e) No focused editor reports no-input-connection Pass
(f) No user text in logcat Pass

(a)

$ agent-device type "LiveAscii4722b ok" --json      -> success, "Typed 17 chars"
$ agent-device get text id=field-email              -> LiveAscii4722b ok
$ agent-device type "Zażółć 東京 😀👍🏽 a😀b" --json  -> success, "Typed 17 chars"
$ agent-device get text id=field-email              -> Zażółć 東京 😀👍🏽 a😀b
I AgentDeviceTestIME: commitText code=1 length=17
I AgentDeviceTestIME: commitText code=1 length=21

(b)

The input is "a" + "😀"×12500: 50,001 UTF-8 bytes, 25,001 UTF-16 units. I used the multiline field field-notes. It has no length limit (control: 6,000 characters read back as 6,000).

$ agent-device type "$LONG" --json                             -> success, "Typed 12501 chars"
I AgentDeviceTestIME: commitText code=1 length=23999
I AgentDeviceTestIME: commitText code=1 length=1002
$ agent-device get text id=field-notes --json                  -> utf8 bytes 50001, utf16 units 25001, exact match True
$ agent-device fill id=field-notes "$LONG" --delay-ms 1 --json -> success, "Filled 12501 chars", no unconfirmed flag
I AgentDeviceTestIME: clearText code=1
I AgentDeviceTestIME: commitText code=1 length=23999
I AgentDeviceTestIME: commitText code=1 length=1002
$ agent-device get text id=field-notes --json                  -> utf8 bytes 50001, utf16 units 25001, exact match True

"exact match True" compares the full read-back with the input.

(c)

$ agent-device fill id=field-email "FillCase4722b Łódź 😀x" --delay-ms 1 --json -> success, "Filled 21 chars"
$ agent-device fill id=field-email "FillCase4722b Łódź 😀x" --delay-ms 1 --json -> success (field already held the value)
$ agent-device get text id=field-email -> FillCase4722b Łódź 😀x
I AgentDeviceTestIME: clearText code=1
I AgentDeviceTestIME: commitText code=1 length=22   (once for each fill)

(d)

I built the helper from 204c6271cf^ and packaged it as 0.21.99 (versionName=0.21.99), so the CLI kept it. The lab app had gone back to the dev-client launcher, so I used the Settings search field. First, I set KeepMe4722b with the accessibility fill path.

$ agent-device type "ShouldNotLand4722b" --json
  -> COMMAND_FAILED, reason android_ime_helper_no_ack, dispatchKind no-ack, requestedUtf16 18, dispatched unknown
     hint: "Reinstall a current bundled or provider IME helper and reopen the session."
$ agent-device fill 'role=edittext' "ShouldNotLand4722c" --delay-ms 1 --json
  -> COMMAND_FAILED, reason android_ime_helper_no_ack, requestedUtf16 0 (clear step), dispatchedSteps 1, same hint
$ adb shell am broadcast -p com.callstack.agentdevice.imehelper -a …ACTION_INPUT_TEXT_B64 --es protocol android-ime-helper-v2 --es text <b64>
Broadcast completed: result=0
W AgentDeviceTestIME: handleAction: rejected …ACTION_INPUT_TEXT_B64, protocol mismatch
$ agent-device get text 'role=edittext' -> KeepMe4722b   (after each step)

Then I closed the session, uninstalled the old helper, and installed the head-built helper again. A check type "Restored 😀" returned ok (commitText code=1 length=11).

(e)

Lab app, Home tab after a focused field (mServedView=null):

$ agent-device type "NoEditor4722b" --json
  -> COMMAND_FAILED, reason android_ime_helper_dispatch_rejected, dispatchKind no-input-connection, requestedUtf16 13
W AgentDeviceTestIME: handleAction: no current input connection for …ACTION_INPUT_TEXT_B64
$ adb shell am broadcast … --es text <b64 "RawNoEditor4722b">
Broadcast completed: result=3, data="no-input-connection"

Settings home, opened with no editor:

$ agent-device type "NoEditorSettings4722b" --json
  -> COMMAND_FAILED, reason android_ime_helper_dispatch_rejected, dispatchKind no-input-connection

Control with a real editor (Settings search): type "Wiß 😀" -> success, commitText code=1 length=6. In the failure cases, no text appeared.

Note: for no-input-connection, the error says dispatched: "unknown". The helper did not commit, so "no" is also true. I did not change this.

(f)

I ran adb logcat -d -b all after the run (11,532 lines). Each of these strings has 0 matches: LiveAscii4722b, Zażółć, 東京, 😀, 👍, FillCase4722b, Łódź, NoEditor4722b, RawNoEditor4722b, NoEditorSettings4722b, KeepMe4722b, ShouldNotLand4722, RawV1_4722b, Restored, Wiß, and base64 prefixes of the payloads. The AgentDeviceTestIME lines contain only codes, lengths, and action names.

Limitation: I cleared the main log buffer once, before (b). Thus the dump does not hold the first (a) run. I ran (a) again after (b). The dump holds that run and all later steps.

Other notes

  • The default IME did not reset to Gboard during this run. Each check showed the helper as the IME while the session was open.
  • Validation: pnpm check:affected --run --head f4ad9a5774 passed with 42 checks and 25 hosted or parked skips, exactCommit=true.
  • Cleanup: I closed the session. The default IME is Gboard again. I added no adb forward or reverse. The emulator is still running. The raw logs are under .tmp/live-4722b/ in the worktree and are not committed.

@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready at f4ad9a5. The focus check in the native helper fixes what the earlier review at 697f7b9 left open (#4722 (comment)), and the live evidence now covers the routes that matter.

Not blocking: the new host test in text-input-test-ime.test.ts fakes result=3 and asserts a mapping that already existed at 697f7b9, and the provider scenario in android-ime-type.test.ts already covers the same reason, so only the one-broadcast, no-retry count is new. You can fold that count into an existing type test or leave it as is.

The focus check ran live only on an API 36 emulator, against a React Native EditText and the Settings search field. WebView, Compose, Flutter and API 23-35 were not exercised. If the app's UI thread stays busy for about 2 s, getTextBeforeCursor can time out. The helper then reports no-input-connection where it used to queue the commit, so type fails with a new but accurate error and fill retries once. That case is not measured.

All five earlier inline threads can be resolved. The receiver thread (#4722 (comment)), the retry conditions (#4722 (comment)), the size bound (#4722 (comment)) and the clear read-back (#4722 (comment)) are fixed at this head. The thread on reason codes in help (#4722 (comment)) does not apply: the behavior is in known-limitations.md, and the reasons ship as typed constants.

Smoke Tests (Android, iOS, macOS) are still running. None has failed. The delta touches only the native helper, one host test and one doc line, so iOS and macOS smoke do not reach it. No conflicts. Merge once those checks finish green, or fail on a route outside Android text input.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 19, 2026
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding and 1 moved to a new line on f4ad9a5. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@thymikee thymikee removed the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 19, 2026
@thymikee

Copy link
Copy Markdown
Member Author

The retry-gate fix in f265d1f looks right in code. The no-input-connection retry now counts only acknowledged text chunks, so a clear followed by code 3 reaches the rebind, and the new unit cases cover that path. The earlier review at f4ad9a5 (#4722 (comment)) found nothing, and the remaining gap is evidence for the new branch.

The branch at text-input.ts:349 retries a device-facing fill after an acknowledged clear and a no-input-connection answer. The PR validation and the linked emulator run cover f4ad9a5, which predates this branch, so no live result covers the changed route. Please run the current head on an Android emulator through the test IME fill route where an acknowledged clear is followed by no-input-connection. Record the source SHA, device, commands, the single recovery attempt, and the final field value in the PR evidence. If the race cannot be triggered on demand, please say so and show the closest route you reached.

Of the two open inline threads, the retry-gate one (#4722 (comment)) is fixed at this head and can be resolved. The reason-code one (#4722 (comment)) does not apply: versioned help does not list per-command reason codes, and the behavior is in known-limitations.md and the typed constants in input-validation.ts. It can also be resolved.

All 17 test checks pass at this head. There are no conflicts. Before merge, please post the live evidence above. The ready-for-human label is removed until then, because this head changes a device-facing route after the last live run.

@thymikee

Copy link
Copy Markdown
Member Author

Live Android run at f265d1f: clear acked, then code 3, then one recovery

This run covers the head f265d1f9a09f7128379d89f24d6e1e031d8d7b2a. The exact branch at text-input.ts L349 was hit live: 19 of 19 attempts with a focus loss in the race window.

  • Device: emulator emulator-5554 (Pixel_7_CI, Android 16, API 36).
  • Build: pnpm install --frozen-lockfile && pnpm build && pnpm build:android (AGENT_DEVICE_ANDROID_BUILD_TOOLS=36.0.0), then pnpm clean:daemon.
  • Helper: dumpsys package shows versionName=0.21.40-dev, versionCode=21040. snapshot -i --json shows backend: android-helper, helperVersion: 0.21.40-dev.
  • CLI: node bin/agent-device.mjs --session live-4722c --platform android --serial emulator-5554 ….
  • Field: the exp:// text field of the lab app's dev-client launcher (Compose). The lab form screen did not load, and I did not start Metro. A KEYCODE_TAB in this field moves focus to the Connect button. Then a raw clear broadcast returns result=3, data="no-input-connection".

How I triggered the race

The text is "R4722c" + "😀"×12500: 50,006 UTF-8 bytes, 25,006 UTF-16 units, two chunks. For each attempt, an on-device watcher follows logcat -s AgentDeviceTestIME. When it sees the first clearText code=1, it runs cmd input keyevent 61 (TAB). Then:

$ agent-device fill 'role=edittext' "$TEXT" --delay-ms 1 --json
$ agent-device get text 'role=edittext' --json

The window between the clear ack and the first text chunk is about 60-150 ms. The TAB landed in that window in every attempt.

Result (attempt 20, raw lines, codes and lengths only)

14:20:11.667 I AgentDeviceTestIME: clearText code=1
14:20:11.814 W AgentDeviceTestIME: handleAction: no current input connection for …ACTION_INPUT_TEXT_B64
14:20:12.397 I AgentDeviceTestIME: onCreate: permission-gated receiver registered   <- rebind (ime disable/enable/set)
14:20:13.556 I AgentDeviceTestIME: clearText code=1                                  <- recovery attempt
14:20:13.781 I AgentDeviceTestIME: commitText code=1 length=24002
14:20:13.957 I AgentDeviceTestIME: commitText code=1 length=1004
CLI:       success=true, "Filled 12506 chars", delayMs 1, no unconfirmed flag
read-back: utf8 bytes 50006, utf16 units 25006, exact match True

The CLI JSON has no retry field. The logcat shows the retry.

Attempts Sequence Result
2-20 (19) clear code=1, text code=3, one rebind, clear code=1, 2 commits code=1 fill ok, exact read-back
1 no TAB (my first trigger used sendevent, and SELinux denied it) clear, 2 commits, fill ok

Every hit had exactly one rebind and exactly two clears. Thus the fill made one recovery attempt, and no second one.

Other notes

  • One extra attempt failed and is not counted above. About 4 s after attempt 12 passed, default_input_method changed to Gboard. No command of this run was active then. The next fill failed with typed android_ime_helper_no_ack (requestedUtf16 0, dispatchedSteps 1) and the reinstall hint. I did not find the cause. A pnpm check:affected run was active in the same worktree at that time. I stopped my daemon, reopened the session, and ran attempts 13-20 again. All 8 hit the branch.
  • Logcat: I cleared the buffer before each attempt. Each per-attempt AgentDeviceTestIME log and the final logcat -d -b all (9,022 lines, attempt 20 and the read-back) have 0 matches for R4722c, Probe4722c, 😀, and base64 prefixes of the payload.
  • Cleanup: I closed the session. The default IME is Gboard again. I added no adb forward or reverse. The emulator is still running. The raw logs are under .tmp/live-4722c/ in the worktree and are not committed.
  • Review threads r4628405336 and r4628405358 are resolved.

@thymikee

Copy link
Copy Markdown
Member Author

Head f265d1f9a09f7128379d89f24d6e1e031d8d7b2a.

Two minor Sentinel findings were handled. One is fixed. One needed no code change.

The fill rebind retry no longer counts the clear step. A clear that committed and a text chunk that then answers no-input-connection reach the one rebind and retry. Text the helper already acked ends the fill instead of committing twice.

Only host retry routing changed. There is no native change. The live run at f4ad9a5 still covers the helper.

The help-text finding stands as answered. Versioned help lists no per-command reason codes for type or fill. The behavior is in known-limitations.md and the typed constants. See #4722 (comment).

Three unit tests cover the routing. Two of them fail at f4ad9a5. Both review threads are resolved.

@thymikee

Copy link
Copy Markdown
Member Author

This now conflicts with main. Please rebase. The earlier review at f265d1f still stands for the code.

thymikee and others added 8 commits November 20, 2026 08:57
…knowledgement (#4520)

The test IME helper previously dropped null-InputConnection input, silently
truncated text at 32_000 UTF-16 units and ignored commitText's boolean, while
the host checked only the broadcast process exit code — so type could report
success over a dropped or truncated payload (reproduced on Pixel_7_CI: CLI
"Typed 33000 chars" with the receiver committing 32_000).

Helper (android-ime-helper-v2): every known action now answers with an ordered
result (goAsync + setResult) that `am broadcast` prints as
"Broadcast completed: result=<code>, data=...". Finite non-zero code set
(committed / commit-returned-false / no-input-connection / rejected-payload /
protocol-mismatch / probe-ok); result data and logs carry codes and lengths
only, never user text. The 32_000-unit silent truncation is removed; payloads
above the declared 64_000-base64-char (48_000-byte) bound are rejected with a
code. Measured on-device (Pixel 7, API 36): delivery+commit verified up to the
bound, the adb-shell channel itself breaks between 65_000 and 66_000 chars,
and result=0 is exactly what a no-receiver or pre-ack helper prints.

Host: probe the running receiver's ack capability per device (artifact metadata
cannot prove it — version policy treats a newer-installed helper as current);
result=0/unparseable refuses with android_ime_helper_no_ack, never optimistic
success and no fallback. Type/fill dispatch text in code-point-safe chunks
within the declared byte bound; every chunk must ack committed with a matching
attempted UTF-16 length or the command fails truthfully with
android_ime_helper_dispatch_rejected plus dispatched-chunk evidence. An ack is
attempted dispatch only — fill keeps its single read-back owner.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
commitText returns true even when no view receives the text. The helper
now treats the client binding's placeholder connection and a deactivated
started connection (getTextBeforeCursor returns null) as no focused
editor, so type reports no-input-connection instead of false success.
The rebind retry was gated on dispatchedSteps, which also counts the clear.
A text chunk that answers no-input-connection after that clear committed left
the field cleared and unfilled. Gate the retry on the attempt's own acked text
chunks instead: no acked text means the helper proves nothing of this attempt
landed, so the rebind and one retry still apply. Text the helper already
acknowledged ends the fill instead of committing twice, and a rejection from
the retried attempt still propagates.
The new fill-retry cases pushed text-input-test-ime.test.ts past the 1000-line
lint cap. The acknowledgement-driven rebind-and-retry cases move to
text-input-test-ime-retry.test.ts, and the broadcast ack, the field it writes,
and the packaged helper artifact they share move to a fixtures file beside both
files. No production change.
@thymikee
thymikee force-pushed the t3/ime-ack-review-fixes branch from f265d1f to 2f90a08 Compare November 20, 2026 08:18
@thymikee

Copy link
Copy Markdown
Member Author

Rebased onto main at 854bba6. The new head is 2f90a08d3b.

  • Conflict: one import block in packages/platform-android/src/text-input.ts. fix(android): authenticate and bound persistent snapshot helper sessions #4729 and this PR both changed the test-IME fill path.
  • Behavior change against main: fix(android): authenticate and bound persistent snapshot helper sessions #4729 added a guard that refuses a test-IME fill over 32,000 UTF-16 units, because one broadcast could not carry it. This PR sends a long fill as ordered chunks under the helper's 64,000-character Base64 bound, so the guard would refuse text that this PR can deliver. Commit 2f90a08d3b removes the guard and canAndroidImeHelperCommitText.
  • Tests: the two fix(android): authenticate and bound persistent snapshot helper sessions #4729 tests for that guard are replaced. One checks the helper's declared bound in TestInputMethodService.java. The other fills text just over one broadcast (48,001 ASCII bytes, and 21,334 three-byte characters) and expects the whole text in two chunks, each at most 48,000 bytes.
  • Validation: pnpm check:affected --run passed with an exact-head receipt after the rebase. The platform-android suite passes (1,496 tests).
  • Live evidence: the device runs at f4ad9a5 and f265d1f used the same helper and host chunking code. The rebase changes no native code.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on 2f90a08. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready at de20ed2. The earlier conflict is gone, no conflicts remain, and the Android no-ack case now reports whether no receiver answered or the ack was unreadable, with the reinstall hint only for the first. The new test covers it.

Not blocking: in packages/platform-android/src/ime-helper.ts:70, result=0 also appears when the helper is installed and current but is not the active IME, so the comment and the reinstall hint could say "no receiver answered (pre-ack helper, or helper IME not active)" and optionally suggest reopening the session first. Take or leave it.

The open inline thread on the no-ack cause is fixed at this head, so it can be resolved: #4722 (comment)

Checks are still running at de20ed2 (Smoke Tests, Smoke Tests iOS and macOS, Analyze, Coverage), and none has failed. The Android smoke route covers the test-IME type and fill path this PR changes. The live device evidence comes from the PR. Before merge, the checks must go green at this head.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of de20ed2

Since the review of 2f90a08: 0 new · 0 still open · 1 no longer raised (1 marked fixed)

No open findings.

2 findings below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (854bba6c5a18).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee
thymikee merged commit ef1198e into main Nov 20, 2026
23 of 24 checks passed
@thymikee
thymikee deleted the t3/ime-ack-review-fixes branch November 20, 2026 11:39
thymikee added a commit to pcbeingused333/agent-device that referenced this pull request Nov 20, 2026
* origin/main: (70 commits)
  refactor(apple-runner): one RUNNER_ERROR_CODES row per runner error code with parity/docs gates (callstack#4774)
  fix(android): require acknowledgements for test IME typing (callstack#4722)
  feat(scroll): add scroll refresh for pull-to-refresh (callstack#4770)
  refactor(host-kit): add request Scope and use it for the wait capture deadline (callstack#4794)
  fix(android): let permission all change nothing on an app that declares no permissions (callstack#4796)
  fix(cli): replace the CLI session and generated remote config instead of rewriting them in place (callstack#4797)
  fix(host-kit): accept a group-writable script directory the user owns (callstack#4799)
  fix(cli): escape control characters at the CLI's stdout and stderr writes (callstack#4778)
  fix(audit): do not report rows under a persistent bar that scrolling reveals (callstack#4775)
  fix(daemon): refuse an unsafe state directory before first use (callstack#4783)
  refactor: settle remaining single-deadline races through settleWithin (callstack#4788)
  refactor(host-kit): settle deadline races via settleWithin with R87 race ratchet (callstack#4766)
  fix(android): authenticate and bound persistent snapshot helper sessions (callstack#4729)
  fix(daemon): bound upload ingress and finalization (callstack#4721)
  chore(gates): ratchet wire-published reason literals by value (R89) (callstack#4779)
  feat(audit): evaluate role-less clickable views on Android (callstack#4780)
  fix(mutation): keep umask-setting tests out of Stryker's thread pool (callstack#4785)
  feat(audit): report controls that share one accessible name (callstack#4771)
  fix(contracts): pair open runtime hints with their apply operation (callstack#4754)
  refactor(daemon): report startup progress over the launch channel instead of marker files (callstack#4777)
  ...
thymikee added a commit that referenced this pull request Nov 20, 2026
* origin/main:
  feat(gesture): hold before the move with gesture pan --hold-ms (#4767)
  docs: clarify device verification and security proposals (#4805)
  fix(daemon-client): say that a hung daemon is stopped before ensureDaemon starts a new one (#4803)
  test: remove five timing races from CI (#4800)
  refactor(remote): save a remote script from memory with the local publisher (#4802)
  refactor(apple-runner): one RUNNER_ERROR_CODES row per runner error code with parity/docs gates (#4774)
  fix(android): require acknowledgements for test IME typing (#4722)
  feat(scroll): add scroll refresh for pull-to-refresh (#4770)
  refactor(host-kit): add request Scope and use it for the wait capture deadline (#4794)
  fix(android): let permission all change nothing on an app that declares no permissions (#4796)
  fix(cli): replace the CLI session and generated remote config instead of rewriting them in place (#4797)
  fix(host-kit): accept a group-writable script directory the user owns (#4799)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant