Skip to content

Recover Android launch after Activity destruction - #399

Queued
n0rpan wants to merge 10 commits into
mainfrom
mobile/android-activity-lifetime
Queued

n0rpan wants to merge 10 commits into
mainfrom
mobile/android-activity-lifetime

Conversation

@n0rpan

@n0rpan n0rpan commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #95. Built on the merged #361, which gives both launch and alert intents one Android Activity in the Firebase build.

On Android 16, changing the app language destroyed the Activity while the original process stayed cached. A launch in that process reused the first GPUI platform and panicked before it could draw. After the native event loop has ended, exit the spent process so Android can start a fresh renderer. Use a direct exit because running process exit handlers reproduced a native renderer mutex abort in the emulator. Handle language and layout direction changes in place and flush the current draft when the window deactivates.

Verified on an isolated API 36 emulator with 16 KiB pages and a fixture-signed ARM64 Firebase bundle. Home and resume kept the same PID. Changing the app language kept the app visible and the PID stable. Back destroyed the Activity, and both the launcher and a synthetic alert intent cold-started a fresh process with an empty crash buffer. The Firebase packaging check and rustfmt passed. Real Firebase delivery and physical-device testing remain open.

The Android CI smoke now exercises ordinary Back at the unpaired root and a second launcher start. It waits for a visible, drawn Activity on both launches, checks for a new process and the Activity-loop exit marker, and checks the Android crash buffer. The same API 35 x86_64 image passed locally with the fix and the previous APK failed because the first process stayed alive.

The first hosted run built the APK, then stopped in the Firebase package preflight because it still searched the workflow for its old inline PID command. Commit 61adeb3 updates the preflight to verify the new relaunch helper and its shell syntax. The preflight passes locally. First hosted run

The replacement hosted API 35 job passed the Firebase preflight and the new emulator check. Ordinary Back ended PID 1886, and the second visible Activity opened as PID 2174 with an empty crash buffer. Passing Android job

Checked against main at 545fc97. The mobile and workflow paths match the integrated #361 tree at 8eec5eb. An unsigned API 35 emulator rehearsal combined this change with the merged Reduce Motion handling (#409) and the Play packaging tests from #389 at adfb450. All 22 Play tests passed. Changing motion while backgrounded preserved the unsent draft and PID. Back and a launcher restart changed PID from 2015 to 2237 with an empty crash buffer. Combined Android job

The Stock clients (latest) job failed at tests/fixtures/stock_opencode.py:193: upstream OpenCode printed its help text and exited 1 for models ox. This PR leaves that fixture and CLI invocation unchanged. The latest-client lane is advisory on PRs. Admission waits for the required OX merge check.

Read a future FCM session alert from the launcher activity's intent: a
session_ref with a known kind and its exact pairing_hint, mutually exclusive
with approval_ref. Java checks extra presence before reading either value, so
a valid session reference plus a wrongly typed approval_ref is still refused;
an approval reference may carry only an approval or question kind, or omit
kind. Java then validates the action, types, canonical reference, known
session kind and required hint, and keeps the envelope in the bounded dedupe
store. Rust parses it into a typed SessionAlert event that shares the existing
bounded inbox, dedupe and newest-tap rules, and routes only that valid
explicit launch through the shared signed follow_tap session branch. Received
data and background messages are untouched; approval taps keep their legacy
and routed behaviour.

The existing activity, launcher and no-FCM build are unchanged. The relay's
NEW_TASK | CLEAR_TOP click action can recreate the standard-mode activity for
a background-warm tap, which uses the same capture path and is to be verified
on a device; a foreground onNewIntent is not covered by this slice. The relay
does not send a session reference yet and no Android session alert opt-in
control is added.

Checks: cargo fmt --check; host android_fcm_events tests (26); host clippy
-D warnings; Android cargo check with and without android-fcm; the pilot
static check; javac against android-36; and a Java fixture for the reference,
hint and kind validators.
…warm-launch

Restack the Android warm notification-tap change onto origin/main
9276853. Preserve main's #352 FCM bundle builds, #353 session-link
routing and #372 typed notification capture; the resulting diff against
main is limited to the reviewed #361 warm-tap feature paths.
The GPUI Android platform belongs to the original Activity's native thread.
After that event loop returns, end the spent process so a later launcher
or notification intent cannot inherit its platform. A direct process exit
avoids running native exit handlers while renderer threads are still alive.

Handle language and layout direction changes in place in both app variants
and flush pending draft saves when the Android window deactivates.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T22:12:00.015105Z 17ddd2e Draft marked ready
🔒 Security Review ✅ Completed 2026-12-03T22:08:55.596465Z 17ddd2e Draft marked ready
ℹ️ 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.

The emulator smoke only checked the first pidof after am start. Extend it
to launch OX Mobile, press ordinary Back at the unpaired root, require the
first process to end with a bounded observation and no force-stop, then
relaunch and require a different, resumed and drawn process with no crash
or relevant failure.

The helper also checks the Activity-loop exit marker. Against the pre-fix
debug APK, Back brings the launcher forward but leaves the old process
alive, so the new check fails at the intended assertion.

Verified on the Android 35 default x86_64 image with the exact 5f473a6
debug APK. The GitHub-hosted workflow path itself was not run here.

n0rpan commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Two Android overlaps to preserve when rebasing: #409 changes the same window-activation callback. Keep its motion refresh on activation and this PR’s draft flush on deactivation. #389 adds Play tests beside the emulator step in mobile.yml; keep those as well as this PR’s relaunch smoke and log artifact. On the combined Android build, background and resume an unsent draft while changing the system motion setting, then verify Back/relaunch still starts a healthy Activity.

@n0rpan

n0rpan commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

I checked the failed Fast Linux job on 61adeb3. At 17:15 UTC, Ubuntu Snapshot returned HTTP 500/502 during apt-get update, before the build. #386 has since landed on main with the signed archive fallback. The Android job on this same attempt passed the Back/relaunch smoke. I’m keeping this PR stacked on #361 while checking the integration with #409 and #389. Failed Fast Linux job · Passing Android job

@n0rpan

n0rpan commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

The combined Android API 35 rehearsal passed on #399 61adeb3a, #361 d6b9a4ad, #409 22486acd, #389 352400bf, and main 20f8288d. The activation callback kept the motion refresh and the Android deactivation callback kept the draft flush. In mobile.yml, I preserved the Play checks before the emulator, the relaunch helper, its log artifact, and the subsequent Android version step.

The disposable APK seeded an unsent draft into the app’s real conversation store. The emulator pressed Home, disabled Android animations, and resumed the same PID. The app saw the draft in memory and in private storage and picked up reduced motion. Ordinary Back then ended PID 2076, and the launcher opened a visible Activity in PID 2244 with an empty crash buffer. The Firebase preflight and 20 Play tests also passed. The signing and upload jobs were skipped. Emulator job and logs

This rehearsal used temporary instrumentation. The PR is still stacked on #361. Its eventual integration should retain both callback paths and both sets of workflow checks.

Base automatically changed from mobile/android-alert-warm-launch to main December 3, 2026 21:20
@n0rpan

n0rpan commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

/queue f2da29d

@n0rpan

n0rpan commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

In line to merge. Commit 17ddd2e is reviewed with nothing blocking; it has entered the merge queue.

@n0rpan

n0rpan commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

@codex security review

Asked for by the maintainer’s queue request, for commit f2da29d.

@n0rpan
n0rpan marked this pull request as draft December 3, 2026 21:23
@n0rpan
n0rpan marked this pull request as ready for review December 3, 2026 21:23
@n0rpan

n0rpan commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

I rehearsed the notification stack together with the exact Play delivery head from #389 (adfb4507) on local integration 5306d28. The merged workflow keeps the Play preflight, Back/relaunch smoke test and its diagnostics.

The ARM64 APK generated from the fixture-signed bundle installed on the Android 16 emulator with 16 KiB pages. It drew from a cold synthetic notification intent and received the warm intent in the same process. The first Back test hit an input ANR. Its trace showed the native main thread running in Android’s ARM translation optimizer while NativeActivity paused. Four subsequent ARM64 Back/relaunch runs and three native x86-64 Firebase release runs passed, including the exit marker and a new process. This emulator result does not establish how Back behaves on physical ARM64 hardware.

@n0rpan
n0rpan added this pull request to the merge queue Dec 3, 2026
Any commits made after this event will not be merged.
@n0rpan
n0rpan removed this pull request from the merge queue due to a manual request Dec 3, 2026
@n0rpan

n0rpan commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

/queue 17ddd2e

@n0rpan

n0rpan commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

@codex security review

Asked for by the maintainer’s queue request, for commit 17ddd2e.

@n0rpan
n0rpan marked this pull request as draft December 3, 2026 22:04
@n0rpan
n0rpan marked this pull request as ready for review December 3, 2026 22:04
@n0rpan

n0rpan commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

The Android job on 17ddd2e passed the headless launch, Back, and relaunch smoke and uploaded its diagnostics: https://github.com/oxstack/ox/actions/runs/47213436514/job/144636673557. The latest-client advisory failed in the stock OpenCode fixture because OpenCode v2.4.4 rejects models ox. I reproduced that error locally with the same upstream version and an earlier packaged OX binary. The baseline stock-client protocol check passed.

@n0rpan
n0rpan added this pull request to the merge queue Dec 3, 2026
Any commits made after this event will not be merged.

This branch was previously deployed

1 inactive deployment
auto-queue — 17ddd2e3 Deployed Dec 3, 2026 by n0rpan via Queue when green and reviewed #8284
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