Skip to content

fix(android): accept a dispatched am start timeout once the app is foreground - #4143

Merged
thymikee merged 2 commits into
callstack:mainfrom
zerone0x:fix/android-open-am-start-timeout
Nov 4, 2026
Merged

thymikee merged 2 commits into
callstack:mainfrom
zerone0x:fix/android-open-am-start-timeout

Conversation

@zerone0x

@zerone0x zerone0x commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

am start -W stops waiting after about 10 s and prints Status: timeout. The launch keeps going, so a slow cold start failed open even though the app came up. Now tryAndroidHelperLaunch treats Status: timeout plus an Activity: line for the requested package as dispatched. It then polls the foreground until that package is up, within a 30 s deadline that starts at dispatch and matches the helper's app action budget. If the package never comes up, the open fails with reason: android-launch-not-foreground. A timeout with no Activity: line, or one that names another package, still fails right away. Nothing is resent.

2 files touched. No scope expansion. Fixes #4095.

Validation

Tested SHA 44bbf31 (base d4bcd42).

  • pnpm check:quick: passed.
  • automation-helper-app.test.ts: 8/8 passed. On base, the two new timeout+Activity tests fail.
  • pnpm check:affected --run --head 44bbf31 (exactCommit=true): format, lint, typecheck, layering, fallow and build passed. vitest-related failed: 38 provider-integration tests hit zip not found in PATH, and base fails the same 38. This host has no zip/unzip. A local pnpm test:unit failed only zip-dependent tests, and base fails those too.
  • CI at 44bbf31: Integration Tests and Coverage passed. Android Smoke failed at live-form-scenario.ts:62: the email field read ada@example instead of ada@example.test. That is the fill path, not open. It may be flaky; this is not proven.
  • Not verified on a device: I had no Android device or emulator.

…reground

`am start -W` stops waiting after about 10 s and prints `Status: timeout`
while the launch continues, so a slow cold start failed `open` even though
the app came up. Treat `Status: timeout` with an `Activity:` line for the
requested package as dispatched, then require that package to reach the
foreground within the helper open's deadline before returning.

Fixes callstack#4095
@vercel

vercel Bot commented Nov 1, 2026

Copy link
Copy Markdown

@zerone0x is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@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.

No issues found across 2 files

View guided diff | Re-trigger cubic

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member

The change looks correct in code at 44bbf31, but it has no live Android run yet.

The new branch in app-lifecycle.ts changes how open behaves on the helper launch route, and the PR says it was not run on a device or emulator. The unit tests mock runAndroidAutomationHelper and hostShell. They do not show that the real helper returns Status: timeout with an Activity: line, or that the window and activity state resolve to the package while a cold start is still running. The CI Android smoke uses a fast fixture app, so it never reaches the timeout branch. Please run open on an Android emulator against an app whose cold start takes more than 10 s. Show the helper output with Status: timeout and an Activity: <pkg>/... line, show open succeeding once the package is foreground, and show a launch that never comes up failing with android-launch-not-foreground. Attach the command output with the commit sha.

Not blocking, take or leave: waitForAndroidPackageForeground mirrors waitForAndroidPackageNotForeground (the same deadline loop, differing only in predicate and poll interval), so one shared helper could serve both.

CI shows one failure, in the Smoke Tests smoke:form-input step: the email field holds ada@example instead of ada@example.test. That is the fill route after the app is already open, and the diff does not touch it, so it looks unrelated. The log has no Status: timeout or android-launch-not-foreground lines. Repo Guards & Compatibility and Coverage were still running when I checked. There are no conflicts. The next step before merge is the emulator run above, at this commit or its successor.

@zerone0x

zerone0x commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

New head: fd815cb.

Emulator run: still to do. I tried to run it on this host and could not. /dev/kvm is present, but the user can't open it (open('/dev/kvm') returns EACCES, the user is not in the kvm group, and there is no root access). The Android emulator will not boot an x86_64 image without hardware acceleration. I have not posted any device output, and I won't post any until it comes from a real run. The run you asked for is still open: Status: timeout + Activity: <pkg>/... from the helper, open succeeding once the package is foreground, and android-launch-not-foreground for a launch that never comes up. I'll post it from a machine with an emulator, at this commit or a later one.

Shared deadline loop: done in fd815cb. waitForAndroidPackageForeground and waitForAndroidPackageNotForeground now both call waitForAndroidForegroundPackage(device, deadline, pollMs, matches). Each wrapper keeps its own deadline, poll interval and predicate (open: 30 s from dispatch, 250 ms; close: 2 s, 50 ms), so behaviour does not change.

Checked at fd815cb:

  • automation-helper-app.test.ts, lifecycle.test.ts, __tests__/app-lifecycle-close.test.ts, __tests__/app-lifecycle-kill.test.ts: 61/61 passed.
  • vitest run packages/platform-android: 1320 passed, 11 failed. The 11 failures are in manifest.test.ts and install-artifact.test.ts. They need zip, which this host doesn't have, and the same 11 fail without this change.
  • pnpm check:quick (lint + typecheck), oxfmt --check and pnpm check:fallow passed.

On smoke:form-input: I agree it's the fill path and this diff doesn't touch it.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member

Thanks for the update. At fd815cb the two foreground waits now share one helper, waitForAndroidForegroundPackage, so that earlier note is fixed. The code change itself looks right, but the live Android evidence asked for in the earlier review is still missing.

The changed device path is tryAndroidHelperLaunch, the helper open route. The unit tests mock the helper and dumpsys window windows, so the real Status: timeout plus Activity: output, the foreground package parsing mid-launch, and the error the user sees are unproven. Please run open <pkg> on an Android emulator against an app whose cold start takes more than 10 s. Show the helper output with Status: timeout and Activity: <pkg>/..., and open succeeding once the package is foreground. Then show a launch that never reaches the foreground (for example an activity that blocks or finishes immediately) failing with details.reason android-launch-not-foreground. Attach the command output with SHA fd815cb or its successor. If you have no device, a maintainer can run it.

I did not run the tests or a device here. The failing Vercel check is the fork deployment authorization, not a build or test, and this diff touches only packages/platform-android, so I treat it as unrelated. The earlier Android Smoke failure was in the fill path, not the helper-open timeout branch. The live run above must pass before merge.

The open inline thread from the earlier review about the live run still stands.

@zerone0x

zerone0x commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I still have no Android emulator I can use: this host has no KVM access, and I would rather not post device output that does not come from a real run. If one of the maintainers can do the run at fd815cb, I will be glad to look into anything it shows. If not, I will post the three cases (Status: timeout + Activity:, open succeeding once foreground, android-launch-not-foreground) once I have a device.

@thymikee

thymikee commented Nov 4, 2026

Copy link
Copy Markdown
Member

We ran this on an Android 15 emulator (ReactNative_API_35B) at fd815cb, so the live check no longer waits on you.

  • Slow cold start: a test app that sleeps 14 s in onCreate. Through this PR's CLI and daemon, open com.example.slow4143 succeeded in 14.4 s (startup.durationMs: 14391). The same launch through an installed 0.21.31 daemon without the fix failed at 10.35 s with COMMAND_FAILED "Android helper could not launch the application". That is the bug from Android open fails with "helper could not launch the application" when am start -W reports "Status: timeout" on slow cold starts #4095.
  • A launch that never shows real content: apps that sleep 14 s or 60 s in onCreate and then finish also returned success, at 14.8 s and 49 s. Android shows the app's starting window right away, so the package counts as foreground. We could not produce android-launch-not-foreground on a real device, and we accept that the unit tests cover that branch.

The code looks good, and we are accepting this.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 4, 2026
@thymikee
thymikee merged commit f8e9c8f into callstack:main Nov 4, 2026
11 of 12 checks passed
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.

Android open fails with "helper could not launch the application" when am start -W reports "Status: timeout" on slow cold starts

2 participants