Skip to content

fix(app): make the Android FGS probe's ACTIVE check a handshake, not a wall-clock race - #23153

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/android-stop-race
Oct 21, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/android-stop-race

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Mobile App Checks run 39680972837 (#23133, a backend-only head) failed the Android Emulator Acceptance probe in round 0 of the burst case with "A queued stop terminated the later active transfer." This is a harness timing flake, not a service bug; the production SyncTransferForegroundService behaved correctly in every log, and no stale queued stop ever terminated a transfer.

Cause

ProbeActivity scheduled ACTIVE at +1.5 s and its own stop() at +4.0 s on the main thread. In burst, the 201 queued start commands are delivered on that same thread before ACTIVE, so ACTIVE slips by batch − 1.5 s and the window before the intended stop shrinks to 4.0 s − batch:

source per-command cost burst batch ACTIVE slip window before stop
CI pass 39676205471, rounds 0–4 3.0–13.0 ms 0.6–2.6 s 64–1635 ms 2.5 s → 1.36 s (round 1)
CI fail 39680972837, round 0 ~26 ms (from its empty case) ≈ 5.2 s > 3.7 s ≈ 0
local idle, API 36 1.4 ms 0.27 s 6 ms 2.5 s
local, 96 guest busy loops ~30 ms 6.0 s 4.6 s 0 → identical failure

Local reproduction (unmodified origin/main, omi_android_gate_api36): ACTIVE 09.053, SURVIVED 09.125, the activity's own stop delivered 09.204 — 202 promotions before ACTIVE, 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 only 0-empty* and could not show this.

Service correctness

stop() sets a volatile flag then queues ACTION_STOP; start() queues a start then clears the flag; onStartCommand decides 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 test a stale queued stop does not terminate a later accepted start covers stop-N-then-start-N+1 and was green on the failing run. Production ordering through Dart's refcounted SyncTransferKeepAlive is strictly alternating start/stop. No user impact.

Change

  • 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 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 required and VERIFY_TIMEOUT fatal for those modes.
  • android_fgs_probe_test.py (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.
  • README documents the handshake; {"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 emulator omi_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 5 under 96 guest busy loops (emulator layer, the condition that reproduces CI) — 25/25 cases pass; burst batches 4.0–9.1 s, ACTIVE→VERIFIED 0.7–1.8 s. Same command, unmodified origin/main, same load — fails with the CI message.
  • --rounds 2 at idle — 10/10 pass; ACTIVE→VERIFIED 113–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 the swarm/known-red.md row for this failure.

View guided diff Turn on auto-fix

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T23:10:49.819405Z f55c9d1 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Luna review round 1: SHIP, no P0/P1. One minor finding — the hermetic fallback test only proves the runner rejects the VERIFY_TIMEOUT marker, not that the activity emits it (its 30 s timer runs on-device). Addressed in f55c9d1 by naming the test and the fake's docstring for exactly that claim. Review output: review-23153-r1.md (two-lane lead scratch).

@Git-on-my-level
Git-on-my-level merged commit ef581d4 into main Oct 21, 2026
45 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/android-stop-race branch October 21, 2026 23:37
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.

1 participant