Skip to content

fix(android): prevent startup crash when recording sync cancels immediately - #20437

Merged
Git-on-my-level merged 4 commits into
mainfrom
lane/android-fgs-startup-hotfix
Oct 3, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
lane/android-fgs-startup-hotfix

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Fixes an Android 16 startup crash when a recording-sync pass finishes before its foreground service receives its first command. Cancellation now enters the service's command queue, each delivered command promotes before processing, and stops use their own start ID so newer transfers retain ownership. A retained cancellation flag also covers a rejected background STOP command: the pending START promotes and stops without acquiring a transfer wake lock.

Reproduced the production ForegroundServiceDidNotStartInTimeException using the actual native service at main SHA 147f77d86a2d: a single start immediately followed by stop killed the process. The fixed service survives that case, a 100-cycle cancellation burst, and immediate restart. The isolated regression probe also checks service, notification, and wake-lock cleanup without credentials or backend access.

Why isn't this a shared primitive instead? The fix uses Android's existing ordered service-command queue and start-ID ownership primitive. The probe exercises the production shell and Robolectric tests protect command delivery and cleanup in the existing JVM CI job.

Validation: Android 16 emulator: 25 fresh-process launches across five scenarios, including 500 start/stop pairs, retained foreground service and wake lock after restart, and no service/notification/wake-lock leaks after cancellation. Android JVM: 116 tests passed, including three new Robolectric tests executing the production service. TZ=UTC bash app/test.sh: 4,104 tests and protected contracts passed. make preflight and PR metadata preflight passed. The background case waits for Activity.onStop; every transfer start asserts OS acceptance, and every scenario requires the native log emitted only after startForeground returns successfully. Immediate cancellation still happens before service callbacks, preserving the triggering race. No physical Android device was connected.

Release-gate repair: the existing Siri reconciliation cooldown test failed under CI with real 20 ms/80 ms timers. Cooldown calculations now use the existing clock package (the default remains the system clock), and that test advances the clock and timers deterministically with fake_async. The native Android fix is unchanged. The 28-test Siri suite and focused analyzer pass; TZ=UTC bash app/test.sh also passed again: 4,104 tests plus protected contracts.

Failure-Class: new

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 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-03T11:34:27.761312Z 603fe85 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.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 13 files

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

Re-trigger cubic

Comment thread app/scripts/android_fgs_probe.py Resolved
Comment thread app/scripts/android_fgs_probe.py Resolved
@Git-on-my-level
Git-on-my-level merged commit bf48ed0 into main Oct 3, 2026
47 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/android-fgs-startup-hotfix branch October 3, 2026 11:48
Git-on-my-level added a commit that referenced this pull request Oct 3, 2026
Collect 46 authored mobile changelog fragments for Android 1.0.554, including the recording-sync startup crash fix in #20437. Existing release lines remain verbatim and consumed fragments are removed.

Validation: changelog validation passed; Android store notes derive to 452 characters within the 500-character limit. The release file retains all 43 authored user-facing lines.

Failure-Class: none
mdmohsin7 added a commit that referenced this pull request Oct 3, 2026
… runs out (#20488)

## Summary

Android users get "Omi keeps stopping" when a long background recording
sync hits Android's foreground-service time limit.

- Android 15+ caps a `dataSync` foreground service at about 6 hours a
day.
- Android 14+ caps `shortService` at about 3 minutes.
- When a cap is reached, the system calls `Service.onTimeout`. If the
service is still running a few seconds later, Android kills the process
with `ForegroundServiceDidNotStopInTimeException`.
- `SyncTransferForegroundService` never overrode `onTimeout`.

Crashlytics, last 14 days:
- 31 users, all on 1.0.553+1320, Android 15–17.
- Every crash happened with the app in the background.
- The message is "A foreground service of type dataSync did not stop
within its timeout:
ComponentInfo{com.friend.ios/com.friend.ios.sync.SyncTransferForegroundService}".

## Change

- Both `onTimeout` overloads now release the wake lock, drop the
notification and call `stopSelf()`:
  - `onTimeout(startId)`, Android 14+, for `shortService`;
  - `onTimeout(startId, fgsType)`, Android 15+, for `dataSync`.
- The service uses `shortService` as its cold-start type, so that limit
needs handling too.
- The Dart transfer continues without the keep-alive, as it already does
when Android refuses the start.

## Not in this PR

- **The larger crash in the same service:**
`ForegroundServiceDidNotStartInTimeException`, about 750 users on
1.0.553. It's addressed by #20437, which is in 1.0.554+1338.
- **Whether the service is needed at all:** #14296 added it for #5221
("sync stops when the screen turns off") without a device test. The
later VERIFY on #5221 traced the stall to the coordinator stopping all
wakes on pause, and a connected pendant already runs
`OmiBleForegroundService` (`connectedDevice`). Removing the service
needs a screen-off sync test on a real Android device, so that is a
follow-up.

## Product invariants affected

none

## Failure class

Failure-Class: none

The existing foreground-service classes
(`FC-foreground-service-promotion-after-startup-work` and
`FC-foreground-start-cancelled-before-delivery`) cover promotion at
start. This bug is a missing timeout stop.

## Verification

- `./gradlew :app:testDevDebugUnitTest --tests
com.friend.ios.sync.SyncTransferForegroundServiceTest` (JDK 21): 5 tests
pass, including the two new ones:
  - a `dataSync` timeout stops the service and releases the wake lock;
  - a `shortService` timeout stops the service.
- Both new tests fail without the fix.
- `scripts/pr-preflight --pr-body-file <this body>`: passes.
- Not run on a device or emulator. Reaching the real 6-hour limit needs
`adb shell cmd activity` FGS timeout overrides on an Android 15+ device.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/20488?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
Git-on-my-level added a commit that referenced this pull request Oct 3, 2026
…20485)

## What changed and why

The Android startup cancellation race fixed in #20437 passed host tests
and reproduced only in Android's real foreground-service command queue.
Add Android 16 emulator acceptance to the existing Mobile App Checks
workflow: 25 native lifecycle stress cases using production service
sources and three offline cold launches of a minified AOT fixture APK
that must render Get Started and retain the same healthy process.

Android full-release and production Shorebird-patch tag builds now
require a successful non-skipped emulator job on the exact main source
SHA, alongside the existing release proofs. Manual execution of the
existing workflow supplies that proof when ordinary path-based checks
were skipped. Broaden Android PR selection to startup, capture, WAL and
acceptance-runner inputs, and retain logs, screenshots, UI hierarchies
and artifact hashes.

## Product invariants affected

- INV-AUTH-1
- INV-DATA-1
- INV-BETA-1

The Codemagic edit only selects stricter Android source admission.
Production authority, auth/session ownership and desktop Beta identity
remain covered by their existing contracts.

## How it was verified

- Android 16/API 36 local emulator: all 25 native service cases passed
without process crashes, service, notification or wake-lock leaks.
- Three additional offline cold launches passed on a universal APK
reconstructed from released build 1338. It is debug re-signed for the
local emulator, so this does not claim original-signature or Play
split-install acceptance.
- Offline unit fixtures exercise failed startup, ANR/process restart,
missing rendered UI, account-state refusal, network restoration and
exact-source admission rejection.
- Actionlint, CI budget validation and repository preflight.
- The packaged startup check uses local Firebase fixtures and debug
signing, with network connectivity disabled before installation. This
does not prove physical BLE/OEM behavior, authenticated upgrades, or the
signed Play split-install artifact. Linux/KVM CI validates the x86_64
lane; local acceptance uses arm64.

## Tests

Behavioral tests run the actual aggregate shell with
failed/cancelled/skipped outcomes and refuse Android release admission
without a successful real canonical job. A behavioral test executes the
actual Shorebird publishing script and proves failed admission cannot
reach publication. Collector fixtures cover push/manual acceptance,
stale SHA, wrong branch/workflow/event, reruns and skipped jobs. Startup
fixtures cover successful execution and failure receipts/cleanup.

## Failure class (fixes)

Failure-Class: FC-foreground-start-cancelled-before-delivery

## New guards

Real instance: #20437. Reuse the production-source native probe and a
shared bounded ADB/offline boundary; Android's asynchronous
foreground-service delivery requires emulator execution rather than a
host-only assertion. The deterministic contract fixtures are registered
for local and CI lanes.

The Linux daily budget cap increases from 11,900 to 12,100 minutes to
cover the new selected emulator lane and broader startup/WAL selection;
other caps are unchanged. The Codemagic whole-document hashes are
refreshed for the shared Android admission boundary on full-release and
OTA-patch paths only; desktop workflow/publication contracts are
unchanged.
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