Repository navigation
fix(android): diagnose emulator starts distinctly and prove a real Flutter APK - #101
Merged
Merged
Conversation
…utter APK The live Android integration test failed in two seconds with "exited before finishing boot" and then deleted the emulator log it named. Root cause: avdmanager honours XDG_CONFIG_HOME and wrote the freshly created AVD to ~/.config/.android/avd, while the emulator only searches $ANDROID_AVD_HOME, $ANDROID_SDK_HOME/avd and $HOME/.android/avd. Pickforge now resolves one AVD directory, passes it as ANDROID_AVD_HOME to avdmanager, -list-avds and the emulator, verifies the ini landed there, and fails before spawning when the AVD is not where the emulator will look. Start failures carry one distinct kind (avd-missing, avd-in-use, port-collision, snapshot, kvm, process-exit, boot-timeout with the adb device state, aborted), the log path and its last lines, and the failed session record keeps the same diagnosis under meta.androidStartFailure. Console ports are probed with a loopback bind before launch on top of adb and the per-home registry; a collision the emulator still reports is retried on a fresh pair. New --cold-boot and --read-only options (CLI and MCP); sessions report bootMode and readOnly; a writable instance is reported as avd-in-use for any further start because the emulator shares an AVD only among read-only instances. Graceful stop waits 30 s for the snapshot save. android launch-app resolves the launcher activity, starts it with am start -W and confirms the process, returning component, pid and launch state; the real APK pass showed the old monkey launch reporting success while the launcher stayed on screen. The live test preserves diagnostics on failure, copies them to PICKFORGE_LIVE_ANDROID_ARTIFACTS, boots PICKFORGE_LIVE_ANDROID_AVD or a throwaway AVD under its temp root, optionally installs and launches a real APK, and proves a cold-boot read-only session with a concurrent read-only session from a second home. Closes #93 Refs #89
…ts, harden the boot probe Review residuals on #101: - The refusal to start any session while a writable emulator holds the AVD is Pickforge's own fail-closed policy (AVD_SHARING_POLICY), stated as such in the pre-flight error, the log-classification hint, the release notes and the live test, instead of being presented as emulator behaviour. - The avd-missing hint and the avdHomeDir doc comment named $ANDROID_SDK_HOME/avd while the code (and the emulator) resolve $ANDROID_SDK_HOME/.android/avd; both now list the real search order. - A sys.boot_completed probe that cannot run (adb missing or not executable mid-boot) no longer escapes waitForBoot as a bare spawn error: the wait keeps polling and ends in the typed boot-timeout EmulatorStartError with the adb state, the log path, the redacted tail and the probe's own error. Tests fail on the previous head for each of the three points.
…mory counters The #93 first-launch deaths were reproduced on a disposable clone of the lab AVD: a fresh sideload on the 2 GB Play image, right after a quickboot restore, trips lowmemorykiller into a storm that kills every oom_score_adj 0 process including the app just launched, while MemAvailable stays around 1 GB and load and io pressure look the same on restores whose first launch survives. The live test now waits (bounded, every probe logged) until lowmemorykiller has been quiet for 30 s before each launch attempt instead of reading MemAvailable and load1.
3 tasks done
This was referenced Sep 5, 2026
ElbertePlinio
added a commit
that referenced
this pull request
Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Release-grade Android proof for #93: root-causes the "intermittent" live-test start failure, makes emulator start failures distinct and durable, verifies app launches, and proves a real Flutter APK end to end through the Pickforge Android lab with independent visual review.
Full report and raw evidence:
~/Projects/Boards/pickforge/0.4-release/android/report.md. Round 3 (2c341c8, fully isolated, disposable AVD clone; the current headb2c8066merges currentorigin/mainthrough #100; production Android, CLI Android, and core lifecycle sources are byte-identical to the round-3 device-pass head, so the pass was not redone):raw-isolated/,raw-isolated-concurrency/,real-trees-diff.txt,investigation-first-launch/,vision-verdict-round3.md,run-isolated-pass.sh. Rounds 1-2 are preserved underraw/,raw-concurrency/,raw-attempt*/,live-test/.Root cause of the baseline failure
avdmanagerhonoursXDG_CONFIG_HOMEand wrote the test's freshly createdpickforge-avdto~/.config/.android/avd; the emulator resolves$ANDROID_AVD_HOME, then$ANDROID_USER_HOME/avd,$ANDROID_EMULATOR_HOME/avd,$ANDROID_PREFS_ROOT/.android/avd,$ANDROID_SDK_HOME/.android/avdand$HOME/.android/avd, so it exited in 2 s withUnknown AVD name, and the test'safterAlldeleted the log named by the error. Reproduced deterministically in an isolated HOME. Not intermittent: it depends on whether the AVD had to be created on an XDG host. (The stray~/.config/.android/avd/pickforge-avd.*from the 2026-09-04 baseline is still on the machine; not deleted by this work.)Changes
ANDROID_AVD_HOME→ANDROID_USER_HOME/avd→ANDROID_EMULATOR_HOME/avd→ANDROID_PREFS_ROOT/.android/avd→ANDROID_SDK_HOME/.android/avd→~/.android/avd) and passed asANDROID_AVD_HOMEtoavdmanager,emulator -list-avdsand the emulator;createAvdverifies the ini landed there. Theavd-missinghint and the doc comment name the same directories the code resolves.avd-in-use; explicit port bound on loopback →port-collision.AVD_SHARING_POLICY): Pickforge shares an AVD only among read-only sessions and refuses to start any session, writable or read-only, while a writable emulator holds the AVD's lock, because a writable instance keeps rewriting the disk overlays and quickboot snapshot a read-only one maps. What the emulator itself admits is recorded as evidence (raw-isolated/41-*,42-*) and not relied on.EmulatorStartErrorwith kindsavd-missing | avd-in-use | port-collision | snapshot | kvm | process-exit | boot-timeout | aborted, the log path, the redacted last 25 log lines, and the adb device state on timeout (missing/offline/unauthorized/device) with a hint each. Asys.boot_completedprobe that cannot run at all (adb missing or not executable mid-boot) no longer escapes as a bare spawn error: the wait ends in the typedboot-timeoutdiagnosis with the probe's own error. The failed session record keeps the diagnosis inmeta.androidStartFailure.--cold-boot/--read-onlyonsession createandandroid start,coldBoot/readOnlyon the MCP tools; sessions reportbootModeandreadOnly. Graceful stop waits up to 30 s afteradb emu killbefore signalling.launchAppresolves the launcher activity (cmd package resolve-activity), starts it witham start -W, and confirms the process withpidof, returning component, pid and launch state. The real pass showed the oldmonkeylaunch returning success while the launcher stayed on screen.PICKFORGE_LIVE_ANDROID_AVD) or creates a throwaway one under its temp root, optional real APK (PICKFORGE_LIVE_ANDROID_APK/_PACKAGE), preserves its temp root on failure, copies logs and records toPICKFORGE_LIVE_ANDROID_ARTIFACTS, adds a cold-boot read-only + concurrent read-only second-home case, and gates each launch attempt on lowmemorykiller having been quiet for 30 s (bounded, every probe logged) instead of onMemAvailable/load, which the investigation showed do not predict the first-launch kill.registerSessionToolssplit per tool (complexity gate on the touched function).avdHomeDir, the policy wording, and the probe-cannot-run path (old-head-replay-bc3302b.txt: exactly these 5 fail on the reviewed head, 27 pass).Evidence, round 3 (this head; real SDK, KVM, Flutter 3.41.6 release APK)
Isolation:
HOME,XDG_CONFIG_HOME,ANDROID_USER_HOME,ANDROID_EMULATOR_HOME,PICKFORGE_HOME(three homes),PICKLAB_HOME, the adb server (ANDROID_ADB_SERVER_PORT=5137with its own copy of the adb key; the stray default-port server was stopped first) andANDROID_AVD_HOME, which points at a btrfs reflink clone ofpicklab-avdunder/var/tmp, all set by the harness (run-isolated-pass.sh), not by the product. Nothing under the real~/.androidor~/.configwas opened for writing;snapshot-real-trees.shhashed every file under~/.android(20 GB, all AVDs and quickboot snapshots) and~/.config/.androidbefore and after: paths and sha256 identical for~/.android(152 files) and~/.config/.android, sentinels identical, and the only~/.configchanges are Codex/Slack/zen browser state written by those applications (real-trees-diff.txt).COLD); UI treecontent-desc0 → 2 after two taps with screenshots; home + relaunch keeps 2 (launchState: HOT, same pid); 26 s screen recording; logcat;pickforge evidence record→ outcome passed with the planted secret redacted; run artifact recorded; destroy leaves no process, adb device, record or port lock.--read-onlystart from another home refused before spawning withavd-in-useand the policy text, its failed session record keeping the diagnosis; a rawemulator -read-onlynext to A refused by the emulator itself (Another emulator instance is running…, exit 1). A untouched afterwards.devicein oneadb devices), the same APK installed and launched in both, tapped to 1 and 3, cross-home targeting fails closed, B destroyed, C tapped to 4, both gone, no lock left by the read-only instances.claude -p --model claude-opus-5, Read only, different model from the driver): PASS,A: 0, 1, 2, 2, 2,B: 0, 1,C: 0, 3, 4; its remaining notes are what pixels cannot show (byte-identical kept-state frames, disclosed; serial/port identity and B's teardown, which the adb listings and session records carry).investigation-first-launch/): a fresh sideload on the 2 GB Play image right after a quickboot restore can trip lowmemorykiller into a storm that kills everyoom_score_adj 0process including the app just launched, whileMemAvailablestays around 1 GB; a reinstall or a read-only boot did not trip it; the storm is sometimes transient (a launch after 30 s of lmkd quiet survives) and sometimes an eight-minute thrash no bounded wait survives. The product keeps failing loudly; the harness and the live test wait for lmkd quiet; the product-side fix (opt-in bounded readiness, AVD provisioning with more RAM) is filed as Android: first launch of a fresh sideload after a quickboot restore is killed by lowmemorykiller on the 2 GB Play-image AVD #105.Rounds 1-2 (previous head
bc3302b, run against the realpicklab-avdwith the real AVD home): warm boot, install, verified launch, counter 0 → 1 → 2, home + relaunch keeps 2, video, logcat, evidence record with the planted secret redacted, clean destroy; two read-only sessions from two homes tapped to 1 and 3 / 4; vision round 1 FAIL on mid-restore frames, round 2 PASS. Those runs rewrote the real AVD'ssnapshot.pb, which is why round 3 was redone on a clone.Findings for follow-up (not fixed here)
pickforge initrefuses a project whose state directory already holds lab runs ("non-empty but has no Pickforge project receipt"); the TypeScript lab and the Rust CLI shareprojects/<id>/. The pass runsinitfirst.packages/cli/distandtarget/release/pickforge. Add release-grade real Android and Flutter APK proof #93 is therefore not closed by this PR.ANDROID_ADB_SERVER_PORT; two Pickforge homes on one machine share the default server and rely on distinct console ports (which the bind probe enforces across homes).Gates
bun run typecheck,bun run lint,complexity-gate check --changed,bun run test,bun run test:coverage(thresholds unchanged),bun run build,cargo fmt --check,cargo clippy --workspace --all-targets --locked -- -D warnings,cargo test --workspace --locked,cargo build --release -p pickforge-cli. Local results at2c341c8(the round-3 head;f82e45cadds release-notes text only): typecheck and lint pass;complexity-gate check --changedreports 0 violations;bun run test106 files, 1353 passed, 4 skipped;bun run test:coverageall files statements 84.77 %, branches 86.92 %, functions 91.05 %, lines 84.77 % (thresholds 73/86/79/82 unchanged);bun run buildok;cargo fmt --check,cargo clippy -D warnings,cargo test --workspace --locked(all suites ok) and the release build ok. CI forf82e45c: run 33938643555, all jobs pass.Head
88fb607mergesorigin/maina2ecc44(#103, Xvfb display allocation and teardown): no file in common with this branch, clean merge, and the Android package, the CLI/MCP Android paths andsession-lifecycle.tsdo not use the display helpers #103 changed, so production Android behaviour is unchanged and the device pass was not repeated. Local results at88fb607: typecheck and lint pass;complexity-gate check --changedreports 0 violations;bun run test107 files, 1358 passed, 4 skipped;bun run test:coverageall files statements 84.79 %, branches 86.79 %, functions 91.15 %, lines 84.79 % (thresholds unchanged);bun run buildok;cargo fmt --check,cargo clippy -D warnings,cargo test --workspace --locked(all suites ok) and the release build ok. CI for88fb607: run 33940311985 on the exact head, all jobs pass.Refs #93
Refs #89
Exact combined-head CI: https://github.com/pickforge/pickforge/actions/runs/33944473917 (attempt 1, all green). Candidate smokes: https://github.com/pickforge/pickforge/actions/runs/33944473928 (attempt 1, all green). Independent closure review: CLEAN.