Skip to content

fix(android): wait for killed processes to exit before the close fence - #4027

Merged
thymikee merged 2 commits into
callstack:mainfrom
okwasniewski:oskar/android-close-killed-pids
Oct 28, 2026
Merged

thymikee merged 2 commits into
callstack:mainfrom
okwasniewski:oskar/android-close-killed-pids

Conversation

@okwasniewski

@okwasniewski okwasniewski commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Android close and open --relaunch failed with android-app-close-timeout (phase process) on loaded CI emulators while the force-stopped app was still exiting. Logcat from 15 CI runs of the e2e mobile benchmark shows every Killing <pid> followed by Zygote: Process <pid> exited due to signal 9 with no restart in between after up to ~700 ms (7 ms on an idle Mac). The 2 s fence counted that exit time, so a busier runner failed it (2 of ~20 runs today).

  • close reads the package's pids before am force-stop, then waits up to 10 s for those pids to exit (new phase exit; the bound only catches a wedged device). The 2 s process fence then still refuses a new process.
  • A pidof that errors, prints no pid list, or times out (bounded by the fence) fails with android-process-probe-unavailable, as killApp does.
  • 7 files. Help text, docs and changeset updated.

Known gap: a process started between the pidof read and force-stop is not in the killed set, so a slow exit of that one still hits the 2 s fence.

Validation

  • pnpm check:affected --run --head 42e84d915: all runnable checks passed.
  • New test "waits past the process fence for a killed process that exits slowly" fails on 3537dc5 with process remained running after close and passes on 42e84d9.
  • Live at 42e84d9, Pixel Tablet API 37 emulator: open --relaunch 3x gave a fresh pid each time, close left no process. At fc6d637, Pixel 9 API 37: e2e mobile benchmark on this build: Android deterministic flows-lists + login-form 10/10, agentic Login Form / Infinite Scroll / Modal Flow 2/2.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 15:31
@vercel

vercel Bot commented Oct 28, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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

All reported issues were addressed across 7 files

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Re-trigger cubic

Comment thread src/commands/management/app.ts Outdated
Comment thread .changeset/android-close-killed-exit.md Outdated
Comment thread website/docs/docs/commands.md Outdated
Comment thread packages/platform-android/src/app-lifecycle.ts Outdated
Comment thread packages/platform-android/src/app-lifecycle.ts
Comment thread packages/platform-android/src/app-lifecycle.ts Outdated
@okwasniewski
okwasniewski force-pushed the oskar/android-close-killed-pids branch from fc6d637 to 42e84d9 Compare October 28, 2026 15:53
Copilot AI balanced review requested due to automatic review settings October 28, 2026 15:53

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@thymikee

Copy link
Copy Markdown
Member

The code looks good at 42e84d9, and I found no blocking problems. Smoke Tests is still running, and the Vercel failure is the fork-deploy authorization prompt, which is unrelated to this diff. There are no conflicts. The next step is to wait for Smoke Tests to go green. The live runs are reported without logs, and I did not see a run at this head where the exit phase takes longer than 2 s, which is the case this fix targets.

Not blocking, and fine to take or leave: (1) in the process phase, waitForAndroidPackageProcessGone counts an unreadable pidof as gone, so a pid list with stderr noise lets close succeed while the process still runs, and the code never raises android-process-probe-unavailable as the help and docs promise; routing it through readAndroidPackagePids and throwing androidPidofUnavailableError on undefined, plus a close test for that case, would fix it. (2) readAndroidPackagePids is the fifth pidof parser in platform-android, so one typed pid read in the adb module could replace the others in a later PR. (3) An adb client that dies from a signal resolves with empty streams and reads as an empty set, which the retirement module already guards against with a device-shell marker. (4) In the wait loop, deadline.remainingMs() can be 0 after the isExpired() check, and normalizeTimeoutMs(0) then runs pidof without a bound, so Math.max(1, deadline.remainingMs()) would close that gap.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Oct 28, 2026
@thymikee
thymikee merged commit aa82d74 into callstack:main Oct 28, 2026
14 of 15 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.

3 participants