Skip to content

Android CI: harden retry against PackageManager indexing race + reduce decode flake#4858

Closed
shai-almog wants to merge 1 commit intomasterfrom
harden-android-retry-flake
Closed

Android CI: harden retry against PackageManager indexing race + reduce decode flake#4858
shai-almog wants to merge 1 commit intomasterfrom
harden-android-retry-flake

Conversation

@shai-almog
Copy link
Copy Markdown
Collaborator

Summary

Two complementary mitigations for the Android instrumentation test flake observed on PR #4856 (and several recent master runs):

  1. Logcat ring buffer bumped to 16 MiB at startup (adb logcat -G 16M). The default 256K-1M is too small for our 90+ test suite where each screenshot emits ~70 chunk lines — the buffer wraps mid-suite, dropping a chunk and making Cn1ssChunkTools fail reassembly with a gap error. This is the root cause of the decode flake the existing retry block tries to recover from.

  2. Retry's am start step now waits for PackageManager indexing. After adb install -r reports Success, the launcher Intent isn't immediately resolvable — pm needs a moment to register every activity in the manifest. The previous version raced and got "Activity not started, unable to resolve Intent" on the first call, then skipped the 10-minute retry wait. New flow:

    • Poll cmd package resolve-activity --brief -a MAIN -c LAUNCHER <pkg> for up to 30s until pm reports the component.
    • Retry am start up to 3× with a 2s backoff if the first call still races.
    • Fall back to monkey -p <pkg> -c LAUNCHER 1 (different code path inside pm) if all am start retries fail.
    • pidof remains the source of truth for whether the app actually launched.

Why two separate fixes

The first reduces the probability of needing the retry (smaller chance of a chunk drop in the first place). The second makes sure the retry actually works when the drop still slips through. Together they should turn the flake from "fails outright" into "occasionally takes longer to pass."

Observed failure that prompted this

PR #4856 build https://github.com/codenameone/CodenameOne/actions/runs/25282838085/job/74122673963FlipTransitionTest emitted identical bytes (png_bytes=25546, chunks=69, total_b64_len=34064) as the most recent successful master run, but the original decode failed (chunk drop), and the retry's am start returned Error: Activity not started, unable to resolve Intent.

Test plan

  • Push and watch the Android instrumentation job: it should pass cleanly.
  • If a decode flake still occurs, the retry should now reach the wait/decode step instead of bailing immediately. Check the STAGE:RETRY -> ... am start exit=0 ... PackageManager resolved launcher lines in the log.
  • If we still see am start failures after the resolve-activity wait, the monkey fallback should fire and bring the app up.
  • Compare retry log artifact (connectedAndroidTest-retry.log) for retry-emitted CN1SS chunks.

🤖 Generated with Claude Code

The instrumentation test runner already retries decode-only failures
(logcat occasionally drops a chunk line, breaking PNG reassembly) by
restarting the app and re-emitting from the on-device suite. The retry
itself was failing in two ways:

1. After `adb install -r`, `am start -W -a MAIN -c LAUNCHER -p <pkg>`
   returned "Activity not started, unable to resolve Intent" because
   PackageManager hadn't finished indexing the freshly-installed APK.
   The script gave up immediately and skipped the 10-minute retry wait,
   so the failed test never got a second chance.

2. The original logcat capture used the device's default ring buffer
   (256K-1M), which can wrap mid-suite when 90+ tests each emit ~70
   chunk lines. That's the root cause of the decode flakes the retry
   was supposed to recover from.

Changes:

- Bump the device-side logcat ring buffer to 16M with `adb logcat -G`
  before clearing it. Mitigates buffer wrap during long suites.
- After `adb install`, poll `cmd package resolve-activity --brief`
  (max 30s) until pm reports the launcher activity is registered.
- Retry `am start` up to 3 times with a 2s backoff to absorb residual
  indexing race.
- Fall back to `monkey -p <pkg> -c LAUNCHER 1` if `am start` still
  refuses to resolve the Intent. `pidof` after launch remains the
  source of truth for whether the app actually came up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shai-almog
Copy link
Copy Markdown
Collaborator Author

Folding into #4856 per request.

@shai-almog shai-almog closed this May 3, 2026
@shai-almog shai-almog deleted the harden-android-retry-flake branch May 3, 2026 16:02
@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 3, 2026

Compared 86 screenshots: 86 matched.

Native Android coverage

  • 📊 Line coverage: 9.89% (5375/54372 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 7.76% (26350/339651), branch 3.60% (1174/32602), complexity 4.55% (1420/31210), method 7.97% (1162/14574), class 13.02% (254/1951)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 9.89% (5375/54372 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 7.76% (26350/339651), branch 3.60% (1174/32602), complexity 4.55% (1420/31210), method 7.97% (1162/14574), class 13.02% (254/1951)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

Benchmark Results

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 894.000 ms
Base64 CN1 encode 202.000 ms
Base64 encode ratio (CN1/native) 0.226x (77.4% faster)
Base64 native decode 596.000 ms
Base64 CN1 decode 257.000 ms
Base64 decode ratio (CN1/native) 0.431x (56.9% faster)
Image encode benchmark status skipped (SIMD unsupported)

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