# R-A07 Record Row Flake Investigation

## Status

Active flaky-test investigation. Do not apply or merge the suspected fix until a
diagnostic run captures the failure and confirms its cause.

The suspected fix is currently stored in:

```text
stash@{0}: On master: wip-rA07-record-row-wait
```

The working tree contains diagnostic-only changes in
`AttachmentRealOsRegressionTest.kt`. The original immediate record-row click
behavior remains active.

## Failure Summary

The scheduled regression run failed in:

```text
AttachmentRealOsRegressionTest
  rA07_cancelledCameraCaptureShowsErrorLeavesNoPartialAndRetrySucceeds
```

Failed GitHub Actions run:

```text
https://github.com/yorvana/android/actions/runs/27553797634
commit: 3443923e1a2a6ace919b44af3a3f749e317e6bac
```

The failure occurred in `openRecord` when the test immediately clicked the
newly saved record:

```kotlin
composeRule.onNodeWithTag(TestTags.recordItem(record.id)).performClick()
```

Compose reported that no node with the expected `RecordItem_<record-id>` tag
existed. The failure was at `AttachmentRealOsRegressionTest.kt:345` in the
original CI source.

The CI result also contained a suppressed retry failure:

```text
IllegalStateException: Only a single call to runTest can be performed during one test
```

That indicates `RetryRule` cannot safely retry this Compose test, but it does
not explain why the record row was initially absent.

## Current Hypotheses

The missing record-row node may be caused by:

1. A Compose/UI rendering race after save and navigation.
2. Save navigation not completing before `openRecord`.
3. Record persistence or repository visibility lag.
4. State interference from another test in the full suite.

The proposed stashed fix waits for the target record-row tag before clicking.
That may be correct, but applying it before capturing the failure would hide
other possible causes.

## Diagnostics

Diagnostic logging is implemented in:

```text
app/src/androidTest/java/com/yorvana/regression/attachments/AttachmentRealOsRegressionTest.kt
```

Logcat tag:

```text
AttachmentRegression
```

The instrumentation logs:

- Before and after the save click.
- After `composeRule.waitForIdle()`.
- Persisted record IDs.
- Whether the repository can read the record.
- Immediately before and after the original record-row click.
- On click failure only: target-node count and visible navigation markers.

Semantics queries are intentionally performed only after click failure.
Querying semantics before the click added enough delay to risk masking the
timing race.

## Reproduction Commands

Run managed-device tests sequentially. ANGLE works locally and is slower than
host rendering, making it the preferred reproduction renderer.

Targeted forced run:

```bash
./gradlew :app:pixel2api33DebugAndroidTest --rerun-tasks \
  -Pandroid.testoptions.manageddevices.emulator.gpu=angle \
  '-Pandroid.testInstrumentationRunnerArguments.class=com.yorvana.regression.attachments.AttachmentRealOsRegressionTest#rA07_cancelledCameraCaptureShowsErrorLeavesNoPartialAndRetrySucceeds' \
  -Pandroid.testInstrumentationRunnerArguments.annotation=com.yorvana.testsupport.tiers.RegressionFull
```

Full extended suite:

```bash
./gradlew regressionFullExtendedCheck --rerun-tasks \
  -Pandroid.testoptions.manageddevices.emulator.gpu=angle
```

Do not count an `UP-TO-DATE` invocation as a reproduction attempt.

## Log Locations

R-A07 device log:

```text
app/build/outputs/androidTest-results/managedDevice/debug/pixel2api33/logcat-com.yorvana.regression.attachments.AttachmentRealOsRegressionTest-rA07_cancelledCameraCaptureShowsErrorLeavesNoPartialAndRetrySucceeds.txt
```

JUnit XML:

```text
app/build/outputs/androidTest-results/managedDevice/debug/pixel2api33/TEST-pixel2api33-_app-.xml
```

Extract the diagnostic timeline:

```bash
rg -n "AttachmentRegression" \
  app/build/outputs/androidTest-results/managedDevice/debug/pixel2api33/logcat-com.yorvana.regression.attachments.AttachmentRealOsRegressionTest-rA07_cancelledCameraCaptureShowsErrorLeavesNoPartialAndRetrySucceeds.txt
```

Search for captured failures:

```bash
rg -n "click failed|AssertionError|No node|Only a single call" \
  app/build/outputs/androidTest-results/managedDevice/debug/pixel2api33/
```

## Evidence To Capture

When the failure reproduces, preserve the complete managed-device result
directory before another run overwrites it:

```bash
cp -a app/build/outputs/androidTest-results/managedDevice/debug/pixel2api33 \
  /tmp/ra07-failure-pixel2api33
```

The decisive diagnostic line should resemble:

```text
openRecord click failed recordId=<id> targetNodes=<count>
saveNodes=<count> addRecordNodes=<count> detailNodes=<count>
```

Interpretation:

| Evidence | Likely cause |
| --- | --- |
| Persisted ID exists, repository record is present, `addRecordNodes=1`, `targetNodes=0` | UI record-list rendering race; waiting for the row is justified. |
| Persisted ID exists and repository record is present, but `saveNodes=1` | Save/navigation did not complete; wait for vehicle-detail navigation instead. |
| Persisted ID absent | Persistence/save failure; investigate record save flow. |
| Repository record absent but persisted ID exists | Repository visibility/cache problem. |
| `detailNodes=1` before click | Test is already on an unexpected detail screen. |

Also preserve the surrounding logcat lines, especially frame-skipping,
Choreographer, OpenGLRenderer, and lifecycle events.

## Successful Diagnostic Baseline

Two full extended ANGLE suites passed after adding diagnostics:

```text
18 executed, 3 skipped, 0 failed
```

The latest successful R-A07 timeline was:

```text
rA07 after save click
rA07 after waitForIdle                         +622 ms
rA07 persisted record ids=[<record-id>]       +35 ms
rA07 repository record present=true           +2 ms
openRecord before click                        +1 ms
openRecord after click                         +17 ms
openRecord detail visible                      +329 ms
```

Earlier local attempts also passed:

- Three original-code targeted runs using host GPU rendering.
- One original-code full extended suite using host GPU rendering.
- Three original-code targeted runs using ANGLE.

The issue has not reproduced locally yet.

## Next-Agent Checklist

1. Confirm `stash@{0}` still contains `wip-rA07-record-row-wait`.
2. Confirm the diagnostic-only changes remain active.
3. Run the full extended ANGLE suite sequentially with `--rerun-tasks`.
4. On failure, immediately copy the result directory to `/tmp`.
5. Compare persistence, repository visibility, navigation markers, and target
   node count using the table above.
6. Apply the stashed wait-for-row fix only if the captured evidence shows a
   healthy persisted record on vehicle detail with `targetNodes=0`.

