Skip to content

fix(android): end close once the pre-close processes are gone - #4902

Merged
thymikee merged 3 commits into
mainfrom
fix/4901-android-close-fence
Nov 21, 2026
Merged

thymikee merged 3 commits into
mainfrom
fix/4901-android-close-fence

Conversation

@thymikee

@thymikee thymikee commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Since #4881 a plain close fails the Android smoke replay with process remained running after close. The fence refused any new Settings process that ran 2 s after the stop, by pid presence. Android restarts Settings for a background client, so that process is not the app the close ended.

Close now succeeds once the pids that ran before the stop have exited and the package is not foreground (re-read after the exit fence, so a relaunch that is on screen still fails). The process phase and the relaunch special case that accepted it are removed. A survivor of the stop still fails with exit. Help and docs match.

5 files. Fixes #4901.

Before / after

AVD API 37, worktree CLI, isolated state dir. A watcher starts Settings again (provider query) once the pre-close process is gone, as Android does for a client. open settings then close, three runs each:

Base 721adbc Head
close exit 1, process remained running after close, 2.6–2.9 s Closed, exit 0, 0.8 s

01-settings.ad replay: 9/9 pass on head.

Validation

New unit test (a new pid persists while the killed one exits) fails on base and passes on head. packages/platform-android, src and repo-guard suites pass locally. CI owns full validation. CI runs API 36 and logs no pids, so its failure is inferred from the same fence path.

🤖 Generated with Claude Code

The Android close fence refused any new process that ran for 2s after the stop, by pid presence alone. Android restarts Settings at once for a background client, so a plain close failed with android-app-close-timeout phase process. Close now succeeds once the pids that ran before the stop have exited and the package is not foreground. Drop the process phase and the relaunch special case that accepted it.

Fixes #4901

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.48 MB 6.48 MB -419 B
Package (unpacked) 6.48 MB 6.48 MB -419 B
Package (download) 1.98 MB 1.97 MB -156 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 21.0 ms 20.9 ms -0.1 ms
CLI --help 47.7 ms 45.7 ms -1.9 ms

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 1 new finding on adbd2a5. The verdict and the full list are in the summary comment.

Run the exit fence first and the foreground fence last, so a relaunch that is on screen after the killed processes exit still fails close, while a new background process does not.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 1 new finding on 5b74501. The verdict and the full list are in the summary comment.

A surviving visible app fails close in 2s with phase foreground again, and a relaunch that is on screen after the killed processes exit still fails.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of b0969c7

Since the review of 5b74501: 0 new · 0 still open · 1 no longer raised

No open findings.

1 new finding away from what changed since 5b74501 not shown. Comment @apex-sentinel-staging review for a full review.

Reviewed with this repository's own Sentinel configuration (721adbc6985f).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

The PR is ready at b0969c7, and the code looks correct. The two earlier inline threads on the restarted-package and visible-app cases are fixed at this head (#4902 (comment) and #4902 (comment)), so the author can resolve them.

CI is green: the only check not passing is Body rules run 44917865607, which was cancelled one second after start and superseded by run 44917865965 of the same workflow, which succeeded. There are no conflicts, and nothing else stands in the way of merge.

Not blocking, and fine to take or leave: the comment in killAndroidPackage at https://github.com/callstack/agent-device/blob/b0969c7/packages/platform-android/src/app-lifecycle.ts#L677 says both fences run as on close, but close no longer runs the process-gone fence; the help text at https://github.com/callstack/agent-device/blob/b0969c7/packages/command-surface/src/management/app.ts#L98 and commands.md:265 reads as if any new process is ignored, though a new foreground process fails with phase foreground, so "new background process" would be accurate; and the Validation section could name the tested SHA. Not verified here: the unit tests and a device run were not executed, and the live table could not be reproduced, so the passing CI Android smoke lane is the head-level evidence, which is weak while that lane fails intermittently (#4901).

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 21, 2026
@thymikee
thymikee merged commit ffef4b7 into main Nov 21, 2026
21 of 22 checks passed
@thymikee
thymikee deleted the fix/4901-android-close-fence branch November 21, 2026 16:29
thymikee added a commit that referenced this pull request Nov 21, 2026
* fix(android): end close once the pre-close processes are gone

The Android close fence refused any new process that ran for 2s after the stop, by pid presence alone. Android restarts Settings at once for a background client, so a plain close failed with android-app-close-timeout phase process. Close now succeeds once the pids that ran before the stop have exited and the package is not foreground. Drop the process phase and the relaunch special case that accepted it.

Fixes #4901

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* fix(android): check the foreground last when close confirms the stop

Run the exit fence first and the foreground fence last, so a relaunch that is on screen after the killed processes exit still fails close, while a new background process does not.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* fix(android): keep the foreground fence first and re-read it last

A surviving visible app fails close in 2s with phase foreground again, and a relaunch that is on screen after the killed processes exit still fails.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit ffef4b7)
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 smoke: plain close fails with 'com.android.settings process remained running after close' since #4881

1 participant