Skip to content

perf(android): share one helper generation across an app-less fill - #5213

Merged
thymikee merged 3 commits into
mainfrom
perf/android-fill-helper-generation
Nov 29, 2026
Merged

thymikee merged 3 commits into
mainfrom
perf/android-fill-helper-generation

Conversation

@thymikee

@thymikee thymikee commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

An app-less fill uses command scope. Before this change, each hierarchy read in the fill (the pre-read and every verification sample) started the snapshot helper and then stopped it. A point fill with two settled samples paid 3 helper start/stop cycles.

Now fillAndroid holds the helper generation its reads start (holdAndroidSnapshotHelperSessionForOperation in the lifecycle owner) and stops it in finally.

  • Each read is still a fresh capture.
  • Other commands on the device piggyback on the held helper as on any live session. They start no competing instrumentation.
  • The fill's own input stays off the held helper. Outside a daemon session it skips helper input and sends the focus tap with channel: 'adb-shell'. Provider-native precedence and the no-replay rule are unchanged.
  • Overlapping fills share one hold. A generation another owner started keeps running.

Before / after

App-less point fill with two settled samples: 3 helper starts and stops before, 1 after. The field result and the input channel do not change.

Validation

text-input-fill-helper-lifecycle.test.ts covers one start and one stop, 3 fresh captures, the shell channel kept for focus and text, a concurrent read and tap reusing the held helper, daemon-session helper input, provider-native precedence, no replay, cleanup on error and on cancellation, and another owner's generation. These tests fail if the global hiding comes back or if the fill's input gate is removed. snapshot.test.ts and text-input-fill.test.ts pass locally. CI pending. No live device run.

🤖 Generated with Claude Code

An app-less (command-scoped) fill stopped the snapshot helper after every
hierarchy read, so its pre-read and settled verification samples each paid
a fresh helper start and stop. The fill now holds the generation its reads
start and stops it when the fill returns or throws. Each read stays a fresh
capture, piggyback input sees no session during the hold so the input
backend is unchanged, and a generation another owner started keeps running.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.70 MB 6.70 MB +791 B
Package (unpacked) 6.69 MB 6.70 MB +791 B
Package (download) 2.04 MB 2.04 MB +315 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 17.5 ms 17.4 ms -0.1 ms
CLI --help 37.6 ms 37.6 ms +0.0 ms

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

…device

Concurrent app-less fills on one device were taken for nested holds, so the
first to return stopped the helper the second still used. Count holders per
device; the last holder to leave stops the generation the holders started.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 c644e15. The verdict and the full list are in the summary comment.

Other commands on the device now see the held helper and piggyback on it
instead of starting a competing instrumentation that stopped it under the
fill. The fill keeps its input off the held helper explicitly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 2f596a6

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

No open findings.

🔧 1 finding marked fixed in their threads
Finding Fixed by Where
Operation hold hides the session from unrelated commands, forcing am instrument thymikee 2f596a6 · reply

1 new finding away from what changed since c644e15 not shown. Comment @apex-sentinel-staging review for a full review.

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

💬 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

Copy link
Copy Markdown
Member Author

At 2f596a6, live Android evidence is still missing for this change. Without it, an app-less fill could fail or leave the helper running on a real device.

The helper instrumentation now stays live while shell input tap and input text and the test IME broadcasts run. A change to device capture and interaction lifecycle must be proven on a device, and the PR body says there was no live device run. Fake-provider tests cannot show that a live UiAutomation helper works alongside shell input and IME rebinding. Can you run pnpm build && pnpm build:android, then pnpm clean:daemon, and on an Android emulator run a point fill, fill <x> <y> <text>, on a text field with no app in the session (or with no session), followed by snapshot -i --json? The output should show that the fill succeeds and reports the field text, that the backend is androidSnapshot.backend: android-helper with a helperVersion matching package.json, and that daemon diagnostics or logs have one helper session start and one stop for the whole fill, with no android_snapshot_helper_session_fallback. After the command, adb shell ps | grep <helper package> should print nothing. This is required before merge.

Not blocking: you can take or leave a short note that command-scope fills now always use the shell channel, even if another owner left a helper session live (no fix is needed now), and a rewrap of the long JSDoc line.

Two earlier threads no longer apply and can be resolved. In this thread, concurrent holds are now reference-counted, only the last holder stops the helper, and a test covers the overlap. In this thread, the live-session lookup is unchanged from main and does not hide the held session, so concurrent commands reuse it instead of starting a competing am instrument.

Not verified here: no device run was performed, and the new test file was not run.

The only checks that are not passing are two cancelled Body rules runs. They check the PR description, and the cancellations are likely unrelated to this change, which only touches packages/platform-android.

Before merge, the live app-less point fill run above is needed at 2f596a6.

@thymikee

Copy link
Copy Markdown
Member Author

Live evidence for the app-less point fill at 2f596a6 (packages/platform-android/src/text-input.ts:107).

Setup: a fresh Android 15 (API 35, google_apis arm64) emulator AVD created for this run. CLI = this checkout (node bin/agent-device.mjs) after pnpm build && pnpm build:android. A private AGENT_DEVICE_STATE_DIR, then pnpm clean:daemon scoped to that state dir. package.json version 0.21.45-dev.

Commands:

# A separate session moved the device to the Settings search field and was then closed
agent-device --platform android --serial <emu> --session fill5213 open            # no app
agent-device ... --session fill5213 snapshot -i --json   # EditText "Search settings", rect {126,128,954x189}, value ""
agent-device ... --session fill5213 fill 603 222 'battery saver' --debug --json
adb -s <emu> shell ps -A | grep -E 'snapshothelper|instrument'   # (no output)
agent-device ... --session fill5213 snapshot -i --json
adb -s <emu> shell ps -A | grep -E 'snapshothelper|instrument'   # (no output)

Fill result (exit 0): {"success":true,"data":{"x":603,"y":222,"text":"battery saver","message":"Filled 13 chars","targetKind":"point"}}

Request diagnostics for the fill (sessions/fill5213/requests/<id>.ndjson, trimmed):

16:19:05.275 android_snapshot_helper_session_ready   {"packageName":"com.callstack.agentdevice.snapshothelper","runner":".../.SnapshotInstrumentation"}
16:19:05.342 android_snapshot_helper_session_capture {"version":"0.21.45-dev","transport":"persistent-session","answered":true}   # pre-read
16:19:05.592 android_snapshot_helper_session_capture {... "answered":true}
16:19:06.154 android_snapshot_helper_session_capture {... "answered":true}
16:19:06.157 android_text_injection                  {"action":"fill","backend":"test-ime","textLength":13}
16:19:06.497 android_snapshot_helper_session_stop    {"capturedCount":3,"lifetimeMs":1371,"quitAcknowledged":true,"quitExitObserved":true,"release":"released","forceKilled":false}

Phase counts in the request: session_ready 1, session_stop 1, session_capture 3, session_fallback 0, session_start_failed 0. A single am instrument adb process ran for 1103 ms and covered all three reads. The test IME broadcasts ran while it was live.

Post-fill snapshot -i --json:

androidSnapshot: {"backend":"android-helper","helperVersion":"0.21.45-dev","helperTransport":"persistent-session","helperSessionReused":false}
@e3 android.widget.EditText value="battery saver" id=com.google.android.settings.intelligence:id/open_search_view_edit_text

The screen shows the Settings search results for "battery saver". ps -A showed no snapshot helper or instrumentation process after the fill or after the snapshot. Only the IME service com.callstack.agentdevice.imehelper stays resident, as the active input method.

Result: pass. The fill succeeds, the backend is android-helper at the current helperVersion, the fill has one helper start and one stop with no fallback, and no helper is left running.

@thymikee

Copy link
Copy Markdown
Member Author

The live run at 2f596a6 covers what the review asked for. An app-less point fill on an API 35 emulator succeeded and reported the field text. The request shows one helper session_ready and one session_stop around three captures, with no session_fallback. The follow-up snapshot reports android-helper at the current helperVersion, and no helper or instrumentation process remained after the fill. The required evidence is satisfied.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 29, 2026
@thymikee
thymikee merged commit ed90021 into main Nov 29, 2026
21 of 23 checks passed
@thymikee
thymikee deleted the perf/android-fill-helper-generation branch November 29, 2026 17:32
thymikee added a commit that referenced this pull request Nov 29, 2026
Resolve the fillAndroid conflict with #5213: the per-fill helper hold now
wraps the identity pre-read and the fill. Fold the target-identity cases
into #5214's capture-evidence scenario and flip its wrong-field test to
expect android_fill_target_moved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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