Repository navigation
fix(app): make the Android FGS probe's ACTIVE check a handshake, not a wall-clock race - #23153
Conversation
…a wall-clock race Mobile App Checks run 39680972837 (#23133, backend-only head 8d062ad) failed round 0 of the burst case with "A queued stop terminated the later active transfer." The service was fine. The probe activity scheduled ACTIVE at +1.5 s and its own stop() at +4.0 s on the main thread, but the 201 queued burst commands are delivered on that thread first: the failing emulator ran ~26 ms per command (the previous, passing run ran 3-13 ms and already slipped ACTIVE to +3.2 s in one round), so ACTIVE fired after the stop was due, both ran back-to-back, and the runner's dumpsys observed the intended teardown. The runner then raised before writing the case logcat, so the artifact could not show this. Reproduced on an API 36 emulator under guest CPU load: the unmodified probe fails with the same message (ACTIVE, stop and SURVIVED within 72 ms; 202 promotions before ACTIVE and one after). With this change the same load passes 25/25 cases (burst batches 4.0-9.1 s, verify latency 0.7-1.8 s) and idle passes 10/10. - ProbeActivity: in burst/restart, register an exported receiver, log ACTIVE, and stop only on the runner's com.omi.fgsprobe.VERIFIED broadcast (30 s fallback logs VERIFY_TIMEOUT). SURVIVED follows the ack-driven stop by 2 s. Other modes are unchanged. - android_fgs_probe.py: per-case flow in run_case(); on ACTIVE verify dumpsys, write <round>-<mode>-active-*.log, then broadcast; fail with a message that names the evidence; VERIFIED is required and VERIFY_TIMEOUT is fatal for those modes. - android_fgs_probe_test.py (checks-manifest android-fgs-probe-runner-contract): ack only after verification, verification latency cannot race the stop, an inactive service saves evidence and fails without an ack, the fallback marker fails the case, other modes neither verify nor ack. - SyncTransferForegroundServiceTest: 100 queued start/stop pairs plus a final start deliver in order with no stopSelfResult, foreground with the wake lock held; only the later stop ends the service.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9b395baf22
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| companion object { | ||
| /** The runner broadcasts this once it has verified the ACTIVE service state. */ | ||
| const val ACTION_VERIFIED = "com.omi.fgsprobe.VERIFIED" | ||
| private const val VERIFY_TIMEOUT_MS = 30_000L |
There was a problem hiding this comment.
Budget the fallback for the runner's snapshots
On a sufficiently slow emulator, this 30-second fallback can still stop the service while the runner is verifying it: after observing ACTIVE, snapshot() performs two sequential ADB calls, each allowed to run for up to 20 seconds, before broadcasting VERIFIED. If their combined latency exceeds 30 seconds, the fallback releases the wake lock before the second snapshot and a healthy run is again reported as the queued-stop regression. Keep the service alive for at least the runner's full verification budget, or make the timeout begin only after an acknowledgement protocol that cannot race these snapshots.
Useful? React with 👍 / 👎.
Luna r1 on #23153: the hermetic fake labels the post-broadcast stop with VERIFY_TIMEOUT when `fallback=True`; it does not model the activity's 30 s timer, so the test proves the runner rejects the marker, not that the activity emits it. Say so in the name and the fake's docstring.
|
Luna review round 1: SHIP, no P0/P1. One minor finding — the hermetic fallback test only proves the runner rejects the |
Summary
Mobile App Checks run 39680972837 (#23133, a backend-only head) failed the Android Emulator Acceptance probe in round 0 of the
burstcase with "A queued stop terminated the later active transfer." This is a harness timing flake, not a service bug; the productionSyncTransferForegroundServicebehaved correctly in every log, and no stale queued stop ever terminated a transfer.Cause
ProbeActivityscheduledACTIVEat +1.5 s and its ownstop()at +4.0 s on the main thread. Inburst, the 201 queued start commands are delivered on that same thread beforeACTIVE, soACTIVEslips bybatch − 1.5 sand the window before the intended stop shrinks to4.0 s − batch:emptycase)Local reproduction (unmodified
origin/main,omi_android_gate_api36):ACTIVE09.053,SURVIVED09.125, the activity's own stop delivered 09.204 — 202 promotions beforeACTIVE, one after. The runner's dumpsys landed after that intended teardown. The runner also raised before writing the case logcat, so the CI artifact holds only0-empty*and could not show this.Service correctness
stop()sets a volatile flag then queuesACTION_STOP;start()queues a start then clears the flag;onStartCommanddecides from the flag at delivery. All of these run on the main thread, so every queued burst command delivers with the flag false. The existing Robolectric testa stale queued stop does not terminate a later accepted startcovers stop-N-then-start-N+1 and was green on the failing run. Production ordering through Dart's refcountedSyncTransferKeepAliveis strictly alternating start/stop. No user impact.Change
burst/restart, register an exported receiver, logACTIVE, and stop only on the runner'scom.omi.fgsprobe.VERIFIEDbroadcast (30 s fallback logsVERIFY_TIMEOUT).SURVIVEDfollows the ack-driven stop by 2 s. Other modes unchanged.run_case(); onACTIVE, verify dumpsys, write<round>-<mode>-active-*.log, then broadcast; fail with a message that names the evidence;VERIFIEDrequired andVERIFY_TIMEOUTfatal for those modes.android-fgs-probe-runner-contract): ack only after verification; verification latency cannot race the stop; an inactive service saves evidence and fails without an ack; the fallback marker fails the case; other modes neither verify nor ack.stopSelfResult, foreground with the wake lock held; only the later stop ends the service.{"kind": "none"}changelog fragment (harness only).Product invariants affected
none
Failure class (fixes)
Failure-Class: FC-wall-budget-equals-paced-work-duration
The activity's fixed +4.0 s wall-clock stop was the budget; the 201 paced command deliveries plus the runner's verification were the work. At the failing emulator's ~26 ms per command the work exceeded the budget and a healthy, keeping-up service was rejected as a failure. The handshake removes the wall budget from the verification step instead of margin-sizing it.
Verification
Repository
BasedHardware/omi, this branch at the PR head; local emulatoromi_android_gate_api36(API 36, arm64, headless).python3 app/scripts/android_fgs_probe_test.py— 5 tests OK (hermetic, host layer)../gradlew :app:testDevDebugUnitTest --tests com.friend.ios.sync.SyncTransferForegroundServiceTest(JDK 21, SDK 36) — 12 tests, 0 failures, including the new 100-pair burst test (JVM/Robolectric layer).python3 app/scripts/android_fgs_probe.py --rounds 5under 96 guest busy loops (emulator layer, the condition that reproduces CI) — 25/25 cases pass; burst batches 4.0–9.1 s,ACTIVE→VERIFIED0.7–1.8 s. Same command, unmodifiedorigin/main, same load — fails with the CI message.--rounds 2at idle — 10/10 pass;ACTIVE→VERIFIED113–613 ms.scripts/pr-preflight --lane local— passes.CI's Android Emulator Acceptance job runs the fixed probe on this PR.
Evidence detail (workspace):
data/run-2026-10-13-two-lane-nemotron/swarm/state/refs/p48-android-stop-race-evidence.md. Closes theswarm/known-red.mdrow for this failure.