dmitchelljackson commited on
Commit
a34aa88
·
verified ·
1 Parent(s): 06e32bc

Add white paper source

Browse files
Files changed (1) hide show
  1. ESPRESSOGYM_WHITEPAPER.md +369 -0
ESPRESSOGYM_WHITEPAPER.md ADDED
@@ -0,0 +1,369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # EspressoGym
2
+
3
+ ## Turning open-source UI tests into reinforcement-learning environments
4
+
5
+ Status: Concept and validation white paper
6
+ Last updated: 2026-10-15
7
+
8
+ Despite the name, EspressoGym is not limited to tests written with Android's
9
+ Espresso framework. The name communicates the core operation: take existing
10
+ Android UI tests and mint them into executable reinforcement-learning
11
+ environments. Espresso, Compose UI tests, UI Automator, and other supported test
12
+ frameworks are source material for the same environment-production pipeline.
13
+
14
+ ## Why this matters
15
+
16
+ Training better mobile-control agents does not primarily require another action
17
+ grammar or another emulator wrapper. It requires many more environments in which
18
+ an agent can act, make mistakes, recover, and receive trustworthy feedback.
19
+
20
+ Today, those environments are expensive to create by hand. Meanwhile,
21
+ open-source Android projects already contain thousands of UI tests whose authors
22
+ have implemented realistic setup, exercised useful workflows, and written
23
+ executable definitions of success. EspressoGym is an attempt to turn that
24
+ distributed work into reusable training infrastructure.
25
+
26
+ ## 1. Goal
27
+
28
+ Build the largest practical collection of **reproducible, executable Android
29
+ training environments with source-backed success signals**.
30
+
31
+ Each environment should provide:
32
+
33
+ - a natural-language goal;
34
+ - a real Android app in a known initial state;
35
+ - freedom for an external agent to interact using any control scheme;
36
+ - executable checkpoints derived from the app's existing assertions;
37
+ - clean reset and teardown behavior;
38
+ - a known-good trajectory for qualification and health checks;
39
+ - pinned source, artifacts, licenses, and build provenance.
40
+
41
+ EspressoGym is not intended to define the model loop, observation format, action
42
+ grammar, optimizer, or reward function. It supplies the environment and raw
43
+ evidence. A training system decides how to act, score, and stop.
44
+
45
+ The desired result is not merely a larger benchmark. It is a corpus that can
46
+ produce new rollouts for reinforcement learning, including off-path behavior and
47
+ recovery, instead of only replaying prerecorded demonstrations.
48
+
49
+ ## 2. Problem
50
+
51
+ ### 2.1 Interactive environments are the scarce resource
52
+
53
+ An emulator and a tap API are generic. A useful task is not. Every task also
54
+ needs a valid starting state, a meaningful goal, reliable success conditions,
55
+ cleanup, and a way to distinguish ordinary failure from a broken environment.
56
+
57
+ That task-specific work is why executable mobile benchmarks remain much smaller
58
+ than offline trajectory datasets.
59
+
60
+ Offline demonstrations are valuable for imitation learning, but they cannot tell
61
+ an agent what happens after a novel action. They do not naturally support
62
+ exploration, recovery, or repeated checkpoint evaluation. Hand-authored online
63
+ tasks solve those problems, but they are costly to scale.
64
+
65
+ ### 2.2 Existing projects solve adjacent problems
66
+
67
+ The relevant prior art spans three different products: general Android-control
68
+ infrastructure, offline training data, and manually authored online benchmarks.
69
+ Each establishes an important part of the solution, but none provides a scalable
70
+ environment-production pipeline from existing application tests.
71
+
72
+ | Project | What it establishes | Why it does not close this gap |
73
+ | --- | --- | --- |
74
+ | [AndroidEnv](https://github.com/google-deepmind/android_env) | A reusable RL interface, simulator integration, observations, actions, and task/reward APIs. | It makes Android tasks runnable but does not manufacture them. Goals, initial state, event/reward definitions, and task-specific cleanup still have to be authored. |
75
+ | [AndroidControl](https://github.com/google-research/google-research/tree/master/android_control) | More than 15,000 human demonstrations across 833 apps: strong evidence that broad mobile-control data improves training and transfer. | It is an offline trajectory dataset. A learner cannot take a novel action, observe its consequence, recover, or query a live success condition. |
76
+ | [AndroidWorld](https://github.com/google-research/android_world) | A reproducible emulator environment with durable programmatic rewards for 116 task templates across 20 apps. | The task implementations are hand-authored. Randomized names, dates, and values create useful instances, but not new semantic workflows; the reusable semantic task count remains 116. |
77
+ | [MobileAgentBench](https://arxiv.org/abs/2406.08184) | Automated evaluation of 100 tasks across 10 open-source apps with several difficulty levels and agent integrations. | It is a carefully curated benchmark, not a system for converting the much larger body of existing app tests into environments. |
78
+ | [SPA-Bench](https://github.com/ai-agents-2030/SPA-Bench) | 340 bilingual tasks across 66 system and third-party apps, including cross-app tasks, agent integrations, automated metrics, and Android snapshots. | It broadens evaluation substantially, but tasks and validators remain curated benchmark assets. Third-party production dependencies are not source-backed, and it does not provide an ecosystem-scale environment-generation path. |
79
+ | [MobileBench-OL](https://aclanthology.org/2026.findings-acl.668/) | 1,080 manually created tasks across 80 Chinese apps, executed on physical devices with trajectory rules, golden paths, noise injection, and automated reset workflows. | The apps are predominantly proprietary and use their live production backends. The authors used three phones with real verified accounts; success is inferred from UI/action traces, and reset is another UI task rather than restoration of app and server state. This is impressive live evaluation coverage, but not a hermetic high-volume RL corpus. |
80
+ | [MobileWorld](https://tongyi-mai.github.io/MobileWorld/) | The closest architectural prior art: 201 tasks across 20 apps in a containerized Android environment with open-source applications, self-hosted backends, snapshots, database inspection, local-state checks, and deterministic evaluation. | Its environments and integrations are deliberately engineered app by app and its tasks are still authored for the benchmark. It demonstrates that hermetic backend-aware mobile environments work; it does not solve how to manufacture thousands of them from work already present in open-source repositories. |
81
+
82
+ MobileBench-OL deserves particular clarification because its headline scale sounds
83
+ similar to EspressoGym's goal. It does not provide 1,080 self-contained backends. Its
84
+ apps talk to their normal production services under real network conditions.
85
+ Annotators wrote tasks and golden trajectories from scratch; experts then created
86
+ XPath-like success rules over UI elements and critical actions. After evaluation,
87
+ an agent follows manually written inverse instructions such as disabling a setting
88
+ or clearing search history. Some tasks are explicitly considered infeasible to
89
+ reset and receive alternative success handling. The released APKs pin client
90
+ versions, but they do not make the proprietary applications or their backends open
91
+ source, immutable, or locally reproducible.
92
+
93
+ MobileWorld, conversely, proves that the stronger environment model is possible:
94
+ containerized Android, controlled open-source services, inspectable databases, and
95
+ snapshot restoration. Its limitation is economic rather than conceptual—twenty
96
+ apps and 201 tasks required purpose-built environment engineering.
97
+
98
+ The remaining gap is therefore a **manufacturing problem**. We need a repeatable
99
+ way to discover, transform, validate, package, and maintain source-verifiable
100
+ interactive environments without manually implementing every task and backend.
101
+ EspressoGym's claim is that open-source UI tests contain enough of that missing
102
+ work to make the process scalable.
103
+
104
+ ### 2.3 UI tests are promising, but not environments yet
105
+
106
+ An existing UI test usually runs setup, performs a fixed action sequence, checks
107
+ assertions, and exits. An RL agent instead needs the test to pause after setup,
108
+ remain alive while an external controller acts, evaluate relevant assertions
109
+ after steps, and cleanly end only when the caller chooses.
110
+
111
+ Real repositories add further complications:
112
+
113
+ - old commits and dependencies may no longer build;
114
+ - setup, actions, assertions, and cleanup may be interleaved;
115
+ - assertions may depend on local variables, fakes, rules, or custom runners;
116
+ - some tests use tiny mocks that do not represent a useful app workflow;
117
+ - tests may accidentally depend on execution order or shared state;
118
+ - leaving the scripted path may crash, dead-end, or corrupt later episodes;
119
+ - several tests may represent the same semantic task with different values.
120
+
121
+ The problem is therefore not extracting text from test files. It is producing a
122
+ qualified, resettable environment without changing what the original test means.
123
+
124
+ ## 3. Solution
125
+
126
+ ### 3.1 Core bet
127
+
128
+ The project rests on six claims:
129
+
130
+ 1. Open-source maintainers have already paid much of the semantic authoring cost
131
+ in their ordinary UI tests.
132
+ 2. A capable model can identify task intent, the agent-control boundary, and
133
+ meaningful checkpoint boundaries.
134
+ 3. Once those labels exist, deterministic code generation can transform the test;
135
+ an LLM does not need to synthesize or repair evaluator code.
136
+ 4. The original test, known-good replay, negative controls, mutations, and reset
137
+ checks can mechanically reject unsafe conversions.
138
+ 5. Apps and generated test harnesses can be compiled once and distributed as
139
+ versioned bundles rather than rebuilt during training.
140
+ 6. Labels describe semantic boundaries, not a particular model or controller, so
141
+ runtime improvements require regeneration rather than relabeling.
142
+
143
+ If these claims hold, the marginal cost of a new environment becomes repository
144
+ qualification, limited labeling inference, compilation, and deterministic
145
+ validation—not a human writing another environment and reward function by hand.
146
+
147
+ ### 3.2 Authoring model
148
+
149
+ The original UI test remains a normal test. Existing setup, actions, and
150
+ assertions are not replaced with an EspressoGym DSL. Labeling adds only a case
151
+ annotation and semantic markers:
152
+
153
+ ```kotlin
154
+ @TrainerCase("contacts.create-contact")
155
+ @Test
156
+ fun createContact() {
157
+ val contacts = FakeContacts()
158
+ launchContacts(contacts)
159
+
160
+ Trainer.start()
161
+
162
+ onView(withId(R.id.add)).perform(click())
163
+ onView(withId(R.id.name)).perform(typeText("Ada"))
164
+ onView(withId(R.id.save)).perform(click())
165
+
166
+ Trainer.checkpoint("contact-created")
167
+ onView(withText("Ada")).check(matches(isDisplayed()))
168
+ assertThat(contacts.savedNames).contains("Ada")
169
+ }
170
+ ```
171
+
172
+ In normal CI, `Trainer.start()` and `Trainer.checkpoint()` are no-ops and the test
173
+ runs as originally written. For dataset production, a deterministic generator
174
+ uses the markers to create a persistent episode implementation. The last
175
+ checkpoint is the terminal goal checkpoint; earlier checkpoints may provide
176
+ useful progress evidence.
177
+
178
+ This keeps assertions in ordinary test code, retains IDE navigation, and makes
179
+ the source auditable by Android developers who know nothing about the training
180
+ harness.
181
+
182
+ ### 3.3 Runtime contract
183
+
184
+ The training harness controls the emulator directly and calls a small environment
185
+ SDK around its own action loop:
186
+
187
+ ```python
188
+ env = RLEnvironment(config_path=case_path, serial=serial)
189
+
190
+ goal = env.goal
191
+ env.start()
192
+
193
+ while harness.should_continue:
194
+ harness.observe_and_act(serial, goal)
195
+ result = env.step_ended()
196
+ harness.record_and_score(result)
197
+
198
+ env.end(reason="caller_finished")
199
+ ```
200
+
201
+ `start()` resets device state and runs the original test fixture and setup.
202
+ `step_ended()` synchronously runs whichever checkpoints are due and returns raw
203
+ observations. `end()` performs final checks and unwinds the original cleanup
204
+ lifecycle.
205
+
206
+ The environment never assumes how the caller produced an action. It can be used
207
+ with ADB, accessibility, UI Automator, coordinates, a learned action grammar, or
208
+ a human. Likewise, a terminal checkpoint passing does not force the episode to
209
+ end. The caller owns reward and stopping policy.
210
+
211
+ ### 3.4 Checkpoints and partial credit
212
+
213
+ Each checkpoint has a stable ID, description, suggested score, and execution
214
+ policy. Policies can evaluate a checkpoint after every step, every N steps, on
215
+ demand, or only when the episode ends. Passed checks may latch to avoid repeated
216
+ cost.
217
+
218
+ The runtime reports raw states such as `PASSED`, `FAILED`, `NOT_OBSERVABLE`, and
219
+ `ERROR`. A failed assertion is normal evidence that the agent has not yet reached
220
+ that state. An assertion infrastructure error, app crash, test-process death, or
221
+ transport failure is environment health data—not task failure disguised as a
222
+ zero reward.
223
+
224
+ This separation lets researchers experiment with sparse terminal reward, shaped
225
+ reward, regression penalties, or custom scoring without rebuilding the APKs.
226
+
227
+ ### 3.5 Deterministic production pipeline
228
+
229
+ The intended dataset workflow is:
230
+
231
+ ```text
232
+ cataloged repository and pinned revision
233
+ -> build qualification and permitted build-system repair
234
+ -> model proposes goal, start marker, checkpoints, and config
235
+ -> validators ensure existing app/test logic was not changed
236
+ -> deterministic episode and golden-trace generation
237
+ -> app APK and EspressoGym test APK compilation
238
+ -> original-test, replay, reset, negative, and mutation qualification
239
+ -> content-addressed project bundle
240
+ -> balanced dataset shard and release catalog
241
+ ```
242
+
243
+ The labeling agent may make several attempts to get a repository building and to
244
+ produce valid labels. It may update build configuration and dependencies, but it
245
+ must not rewrite application behavior or existing test actions and assertions.
246
+ Accepted changes are committed automatically only after mechanical guards and
247
+ build checks pass. Cases that cannot be converted safely are recorded with a
248
+ reason rather than silently repaired.
249
+
250
+ The released bundle contains precompiled APKs, the case configuration, generated
251
+ episode mapping, checkpoint metadata, golden trace, qualification receipts,
252
+ licenses, hashes, and provenance. Bundles are grouped into balanced shards so one
253
+ emulator can run an installed app while another shard or app is downloaded and
254
+ prepared.
255
+
256
+ ### 3.6 Generated qualification, not model review
257
+
258
+ Each labeled case produces a small deterministic validation suite:
259
+
260
+ - replay the original actions as the golden trajectory and require success;
261
+ - run no actions and require that terminal success is absent;
262
+ - truncate or mutate the trajectory and ensure ordinary mistakes do not break the
263
+ harness;
264
+ - inject a recoverable detour and return to the golden path;
265
+ - reset and replay the golden trajectory again to prove state isolation;
266
+ - run cases alone, repeatedly, and in shuffled order to detect dependencies.
267
+
268
+ This suite tests both the environment and its prerecorded trajectory. It does not
269
+ prove that a model can recover—that requires training—but it can prove that common
270
+ wrong actions remain bounded and do not poison the next rollout.
271
+
272
+ ### 3.7 Probe evidence and potential scale
273
+
274
+ The current static census found:
275
+
276
+ | Funnel stage | Cases | Projects |
277
+ | --- | ---: | ---: |
278
+ | Recognized UI interaction | 6,620 | 424 |
279
+ | Device-capable after excluding Robolectric-only tests | 5,910 | 391 |
280
+ | Strict action-plus-assertion candidates | 5,002 | 346 |
281
+
282
+ The 710 Robolectric-only or local-shadow cases removed at the device-capable stage
283
+ are not part of the headline pool or yield forecast. They do not expose a real
284
+ device UI for a mobile-control agent. Projects that also contain genuine
285
+ instrumentation or device tests remain eligible through those tests.
286
+
287
+ These are candidates, not finished environments. Static analysis establishes that
288
+ tests perform UI actions and contain assertions; it does not prove that the pinned
289
+ commit builds, the task is meaningful, or the environment tolerates off-path
290
+ behavior.
291
+
292
+ The candidate pool is also unevenly distributed. The median UI project contributes
293
+ five cases, the top 10% contributes 60.3%, and inverse-HHI gives an effective
294
+ project count of 59.8. Final releases must report raw cases, each project's
295
+ contribution, and semantic clusters rather than inflate diversity with repeated
296
+ values. EspressoGym publishes qualified environments without imposing a per-app
297
+ cap; downstream users control sampling and balancing.
298
+
299
+ An initial 50-project execution probe selected 22 tests that ran, of which 15
300
+ passed. The sample was small and non-random. More importantly, the failure audit
301
+ found that 22 of the 28 projects without a test result were blocked by first-pass
302
+ runner defects or missing host tooling; only six required project-specific repair.
303
+ A separate source-feasibility sample classified 37 of 43 device cases as directly
304
+ pollable or segmentable, with six harder continuation cases. A selected labeler
305
+ pilot converted 10 of 11 attempted cases into fully emulator-green environments.
306
+ None of these is a production-yield measurement, but together they make 20% too
307
+ pessimistic as the base expectation.
308
+
309
+ The realistic planning range is **50–70% raw technical conversion**, or roughly
310
+ **2,500–3,500 published qualified environments** from the 5,002 strict,
311
+ device-capable candidates. This applies neither a per-app cap nor an assumed
312
+ semantic-deduplication loss. Twenty percent remains a downside scenario. A fixed
313
+ prospective pilot must replace this planning range before substantial inference
314
+ or cloud-build spending.
315
+
316
+ Scale comparisons should remain explicit:
317
+
318
+ - 5,002 strict candidates are about **43x** AndroidWorld's 116 semantic templates;
319
+ - the raw qualified planning range would be about **22–30x** AndroidWorld;
320
+ - MobileBench-OL currently reports 1,080 online tasks, so the qualified-environment
321
+ planning range would be about **2.3–3.2x** its task count;
322
+ - AndroidControl remains much larger as an offline demonstration collection.
323
+
324
+ The defensible ambition is not “more rows than every dataset.” It is a uniquely
325
+ large collection of semantically distinct, executable, source-verifiable training
326
+ environments. Final claims must use published, qualified bundles—not the census.
327
+
328
+ ### 3.8 What must be proven before scaling
329
+
330
+ The next fixed pilot should cover 10 projects and 30–50 selected candidates. It
331
+ must measure, without changing the denominator:
332
+
333
+ - project build yield and case packaging yield;
334
+ - semantic acceptance and duplicate rate;
335
+ - original-test preservation;
336
+ - golden, negative, recovery, and post-reset behavior;
337
+ - checkpoint latency and per-episode reset/setup time;
338
+ - app, assertion, transport, and emulator failure rates;
339
+ - model tokens, retries, wall time, and cost per accepted environment;
340
+ - cases rejected for mocks, lifecycle coupling, state leakage, or weak terminal
341
+ assertions.
342
+
343
+ The approach should be reconsidered if build maintenance dominates total cost,
344
+ source tests cannot be transformed while preserving lifecycle semantics, useful
345
+ checkpoints are too slow to evaluate during training, wrong-path actions commonly
346
+ corrupt future episodes, or semantic deduplication collapses the candidate pool.
347
+
348
+ ## 4. Where collaborators can help
349
+
350
+ This project crosses several specialties, and the highest-leverage work is not
351
+ limited to model inference:
352
+
353
+ - Android/JUnit engineers: lifecycle preservation, instrumentation, rules,
354
+ runners, Compose/Espresso compatibility, and fast reset.
355
+ - Compiler/tooling engineers: reliable Java/Kotlin analysis and deterministic
356
+ episode generation.
357
+ - ML systems researchers: checkpoint scheduling, scoring policies, environment
358
+ APIs, rollout health, and training experiments.
359
+ - Build/infrastructure engineers: reproducible Android toolchains, distributed
360
+ workers, resumable artifact publication, and balanced shards.
361
+ - Dataset researchers: semantic clustering, contamination analysis, diversity
362
+ measurement, and statistically sound yield estimates.
363
+ - App maintainers: identifying which tests represent meaningful end-user tasks
364
+ and which depend on unrealistic fakes.
365
+
366
+ The detailed runtime contract is in
367
+ [`ESPRESSOGYM_PRD.md`](ESPRESSOGYM_PRD.md). Dataset qualification and
368
+ packaging requirements are in [`DATASET_PRD.md`](DATASET_PRD.md), and the concrete
369
+ implementation sequence is in [`IMPLEMENTATION_HANDOFF.md`](IMPLEMENTATION_HANDOFF.md).