Skip to content

test: remove timing races from recovery, emulator and vnc tests - #158

Merged
ElbertePlinio merged 2 commits into
mainfrom
fix/144-recovery-test-determinism
Sep 10, 2026
Merged

ElbertePlinio merged 2 commits into
mainfrom
fix/144-recovery-test-determinism

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Three subprocess-timing tests failed on separate CI attempts of unrelated changes (#144). Root causes and changes:

  • Recovery serialization (packages/core/test/evidence-recovery.test.ts): a recovery process inspects the manifest before taking the journal lock, so a peer that wins the lock and replaces manifest.json atomically leaves the loser with an unlinked inode (nlink 0), which the singleton-file check rejects as invalid evidence manifest. That is a legal interleaving, so the test now asserts the state every process must agree on (same recovered run, one session index, three artifacts, any skip only for that transient reason) instead of byte-identical stdout. The window is documented above the test.
  • Emulator early exit (packages/android/test/emulator.test.ts): the shared fake adb answered booted on the first probe, so under load the boot probe could win against the fake emulator's exit. A never-booting adb fake makes the early exit the only way out; the CI symptom was reproduced with an injected delay before the change and is gone after.
  • x11vnc supervision (packages/desktop-linux/test/integration.test.ts): the fake x11vnc bound ports inside the kernel ephemeral range and died silently on a failed bind. Ports moved below that range and the fake logs and retries a failed bind, so a lost port shows up as a named startup timeout instead of a supervision failure. The CI symptom could not be reproduced locally (145 rounds), so this is hardening against the failure the symptom names.

Production lock and supervision code is unchanged. Validation on this branch: the three files (loops of 5 under load by the worker: recovery 1/5 failing before, 0/10 after), oxlint, complexity-gate, typecheck; lead re-ran the three files once more.

Author: Opus worker. Reviewer: separate Astra review.

Closes #144

Three subprocess-timing tests each assumed an ordering that a loaded runner
does not guarantee.

Evidence recovery: a recovering process classifies a run's manifest before it
takes that run's journal lock. A peer that wins the lock replaces manifest.json
by rename, so the loser's already open descriptor points at an unlinked inode,
the nlink check fails and the run is reported as "invalid evidence manifest".
The test assumed all four processes print identical results. It now asserts the
state they must agree on instead: every process that recovered the run recovered
exactly the same run, any other process skipped it only for that transient
reason, and the run ends up recovered once with one session index and three
manifest artifacts. Reproduced 3 times in 60 four-process rounds under load.

Android emulator: waitForBoot checks the emulator process and probes adb getprop
in the same loop, and the fake adb reported a finished boot immediately, so the
test assumed the fake emulator died before the first probe returned. Under load
the probe wins and startEmulator resolves instead of rejecting. The failing test
now uses an adb that never reports a boot, which leaves the early exit as the
only way out of the loop. Confirmed by delaying the fake emulator's exit by
300ms: that reproduces the CI failure before the change and passes after it.

x11vnc supervision: the fake server bound a port inside the kernel's local port
range and had no error handler, so a lost bind killed it and startVnc reported
"x11vnc exited during startup". The ports moved below that range and the fake
now logs a failed bind and retries it, so a bind it cannot win surfaces as a
startup timeout with the reason in the log rather than as a supervision failure.

Production lock and supervision code is unchanged. The transient "invalid
evidence manifest" skip is a misleading but non-destructive report from a real
concurrent recovery, worth a follow-up rather than a change here.

Refs #144
Review follow-up on the concurrent recovery test. Tolerating an "invalid
evidence manifest" skip did not establish that the skip was transient: a run
left persistently invalid could have passed as long as its JSON still held
three artifacts. The concurrent round is now followed by a single further
recovery that must report the run as recovered with no skips, and the report
and session index bytes it leaves must equal the bytes the concurrent round
settled on. The final manifest is checked for the recovered state as well, so
a differing rendering fails and not only a differing index path or skip
message. Verified against 2 real races in 60 four-process rounds.

The comment now describes the window as a tolerated product race, filed as
#159, rather than as a legal serialization, since recovering this fixture
sequentially never produces that error.

The x11vnc supervision test now uses a fake that only binds after a delay and
asserts the port accepts a connection once startVnc returns, which proves the
wait instead of only checking the returned port and liveness. The fake x11vnc
setup moved into one helper shared by the immediate and delayed variants, and
its comment no longer claims what a lost bind surfaces as, since an unrelated
listener could satisfy readiness while the fake is still retrying.

Refs #144
@ElbertePlinio
ElbertePlinio merged commit 121d6b0 into main Sep 10, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/144-recovery-test-determinism branch September 10, 2026 14:34
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.

test: concurrent evidence recovery test is timing-sensitive in CI

1 participant