Repository navigation
fix(app): flush pendant custody writes before tests delete storage (#20500) - #20638
Conversation
…asedHardware#20500) Ring-custody checkpoint writes are serialized on a save/IO queue, and mismatch invalidation and ring reincarnation persist them fire-and-forget. Nothing let a caller wait for queued writes, so tests that delete their custody directory after a fixed 50ms settle raced them: the queued `.json.tmp` -> rename ran after teardown and failed the suite with PathNotFoundException "after it has completed" (main and unrelated PRs). - PendantRingCustody.flush() / PendantCustodyStore.flush(): complete once every write queued so far has landed, re-checking for writes queued while waiting. - The three flaky suites end the custody session (disconnect) and flush before deleting storage; ring_custody_download_test flushes every custody it creates before removing the path_provider mock, and pendant_custody_main_red_test flushes the shared custody. - pendant_ring_custody_flush_test.dart gates the store's directory so a fire-and-forget write is provably pending and pins flush() semantics.
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
Thanks @sanjayJ369 — clean, well-scoped fix for #20500. I verified the code at the PR head; per-file notes:
One non-blocking observation: flush() is currently test-facing only. If the app ever tears down or swaps custody storage at runtime (e.g. account switch), the same write-outlives-teardown hazard exists there — worth keeping in mind, not a change request for this PR. The stress runs in the description weren't independently reproduced by this review, but CI's reviewer check passes and the mechanism is convincing. Looks ready for maintainer merge consideration. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
A checkpoint queued while flush() waited on the store reached the I/O queue only after its predecessor's save, so flush() could return with it still pending. flush() now waits on the store inside the checkpoint-queue loop. The teardown regression test asserted on uncaught errors, but noteInfo already logs and swallows a failed write, so it passed without flush(). It now checks what reached disk before the directory is deleted, and a new test pins the store-wait race.
flush() only waited on the checkpoint queue, but an open session's live marks enqueue their persists lazily on its mark chain, so a test could flush, delete storage, and have a later mark write recreate it. flush() now also waits on every open session's mark chain until both are stable. Every custody test that deletes storage now flushes each custody it built first: pendant_ring_custody_test and local_wal_live_custody_test leaked recreated temp dirs on every run. The two wrap tests that queue thousands of marks end their session so the queued persists are dropped, and the disconnect test flushes in finally. The flush tests read the checkpoint from disk synchronously so an early return cannot hide behind the store queue, and a new test pins the store-level loop.
The u16 wrap test queues about 3300 mark persists; it now ends its session through addTearDown right after beginConnection, so a failing expectation does not leave teardown's flush writing them one by one past the timeout. The two-mark wrap test no longer needs that. A comment now says why flush() re-checks the mark chains as well as the save queue.
|
Ready for full review. Could a maintainer please add the Generated by Claude Code |
|
ci:full is now on, so the full CI suite should pick up the latest commit (you may need to re-run the jobs as you mentioned). My earlier review on this head stands; nothing new to add since. Thanks for the careful red-first guard test with the gated directory — the write-queued-while-flush-waits coverage is exactly the corner this class of bug hides in. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
…asedHardware#20500) The CAP_APP_ACK_RECLAIM download test sampled the card's advances after a fixed 300 ms sleep. Under CI load the first chunk's checkpoint persist and proof validation had not finished by then, so the incremental advance landed after the snapshot and the test failed with 0 advances (PR BasedHardware#20497 run 37150132070, attempt 1). This was a timing flake, not a custody write outliving teardown. The fake card now completes a future on its first advance, and the test waits for it, bounded at 10 s, before sending the last records and DONE. A missing incremental advance still fails the existing expectation.
…rdware#20500) The 10s custody-window test fired the drain timer's callback by hand, dropped the Future it returned, and read the WAL index after a fixed 300 ms sleep. Under CI load the index save had not landed by then, so the test failed with no disk WAL (main at 4e93805). Because that skipped sync.stop(), teardown then deleted tempDir under the still running save, which failed again "after test completion" renaming wals.json.tmp. That is a WAL index write, so the custody flush in tearDown could not cover it. The test now drives the timers with the existing ManualScheduler: it elapses the 10s window and awaits waitForCallbackIo(), which completes once the drain, its audio write and the index save have finished. The body runs in try/finally with sync.stop(), which queues behind any drain still running, so no index write outlives tempDir even when an expectation fails. The changelog exemption reason now covers both timing fixes.
|
Reviewed the full diff against #20500 — the approach (an awaitable Per-file notes:
Checks are green (Dart Analyze & Tests, Android JVM Unit Tests, Android Emulator Acceptance, Backend Hermetic Merge Gate). Already human-approved; from the automation side this is in good shape for merge — no blocking concerns. Thanks for the careful diagnosis of the two distinct flake causes and for the sleep-free guard tests. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
fix(app): flush pendant custody writes before test teardown — fixes #20500 (flaky CI, filed by mdmohsin7), stated root cause, CI green, tests added. 4/5 confidence (diff slightly over 300-line guideline but scoped to the fix).
What changed and why
Fixes #20500. The issue cites four CI failures. The CI logs show two different causes, and this PR fixes both.
1. Custody writes outlive test teardown (main at
0c00747665, and PR #20497 run 37147694253). Ring-custody checkpoint writes are serialized onPendantRingCustody._saveQueueandPendantCustodyStore._ioQueue. Live marks persist lazily on each open session's mark chain. Mismatch invalidation, ring reincarnation and live marks persist without awaiting, and nothing let a caller wait for those writes. Tests deleted their custody directory after a fixed 50 ms_settle(). Under CI load a queued.json.tmp→renamethen ran after teardown and failed the suite withPathNotFoundException"after test completion".PendantCustodyStore.flush()completes once the I/O queue is idle, re-checking for work queued while it waited.PendantRingCustody.flush()waits on the checkpoint queue, every open session's mark chain and the store. It repeats until neither the checkpoint queue nor any mark chain changed while it waited.2. Fixed sleeps in two tests (PR #20497 run 37150132070 attempt 1, and main at
4e938058d9, run 37145070911). Neither failure was a custody write, soflush()alone could not fix them.ring_custody_download_test.dart, "CAP_APP_ACK_RECLAIM: incremental advance fires on each durable chunk…", failed withExpected: >= 1, Actual: <0>. It counted advances after a fixed 300 ms sleep. Under load the first chunk was written about 235 ms after the read started. The advance that chunk triggers comes only after the checkpoint persist and proof validation, and it had not reached the card when the sleep ended. The fake card now completes a future on its first advance. The test waits for it (bounded at 10 s) before it sends the last records and DONE, so the advance it counts is still mid-transfer.pendant_custody_main_red_test.dart, "pendant BLE frames drain to disk within the 10s custody window", failed withExpected: non-empty, Actual: []. It fired the drain timer's callback, dropped the returned Future, and read the WAL index after a fixed 300 ms sleep. The failed expectation skippedsync.stop(), so teardown deletedtempDirunder the still-runningWalFileManager._saveWals. That caused a second failure "after test completion" onwals.json.tmp. The test now drives its timers with the existingManualScheduler: it elapses the 10 s window and awaitswaitForCallbackIo(), which completes once the drain, its audio write and the index save have finished. The body runs intry/finallywithawait sync.stop().stop()queues behind any drain still running onLocalWalSyncImpl._bufferQueue, so no index write outlivestempDireven when an expectation fails.Changed suites:
pendant_ring_custody_flush_test.dart(new)flush()(below).omi_ring_custody_test.dartdisconnect(), flush every custody they built, then delete. The disconnect test flushes infinally.ring_custody_download_test.dartpath_providermock. The CAP_APP_ACK_RECLAIM test waits for the first advance instead of sleeping.pendant_custody_main_red_test.dartPendantRingCustody.shared. The 10 s window test awaits the drain throughManualSchedulerand stops the sync infinally.pendant_ring_custody_test.dartaddTearDown, which drops its ~3300 queued mark persists.local_wal_live_custody_test.dartmanager()handed out.Product invariants affected
none
How it was verified
Unless noted otherwise, every run below used head
ac9a46070bwith Flutter 3.44.5 (Dart 3.12.2), the version CI uses. The machine has 8 cores and was under a load average of about 11 to 14 from other work. Earlier revisions of this description reported results fromd15a282c. That was beforeflush()gained the store re-check and mark-chain wait, before two more suites changed, and before the timing fixes. The results below replace them.ring_custody_download_test.dartandpendant_custody_main_red_test.dart(9 tests), run 5 times in each CI time-zone lane (UTC,Pacific/Kiritimati,Pacific/Pago_Pago). 15/15 runs passed (+9: All tests passed!). No log containsPathNotFoundExceptionor a failure "after test completion".pendant_ring_custody.dart,local_wal_sync.dart,ring_storage_sync.dart,omi_connection.dartorwal_file_manager.dart, run once per lane. This includes all six changed suites and the new flush test. Each lane:+341 ~9: All tests passed!, with noPathNotFoundExceptionand no failure "after test completion". The only custody "persist failed" line is the existingreincarnation persist failed for omi-1: Binding has not yet been initialized.from the untouchedomi_ring_custody_test.dart"a lost ENABLE ack keeps ring-id custody" test, which also appears on main and in PR fix(app): load the app catalog on Integrations when apps came from the cache #20497's CI log.5b448a974bthen failed with the same assertions as CI,Actual: <0>andActual: WhereIterable<Wal>:[]. The follow-on "after test completion" error did not reproduce locally. Both tests on this head passed, and so did the whole 10 s window file (+3).ring_storage_sync.dart, the CAP_APP_ACK_RECLAIM test fails at the 10 s bound withExpected: >= 1, Actual: <0>._drainPendantTailskipping its_flush, the 10 s window test fails with "pendant frames must reach the disk index…".flutter analyzeon the 7 touched Dart files:No issues found!.dart format --line-length 120 --set-exit-if-changed: 0 changed.PendantCustodyStore.saveJson→_File.rename, fromPendantRingCustody._persist←beginConnection._File.renameofwals.json.tmpfromWalFileManager._saveWals←LocalWalSyncImpl._flush←_drainPendantTail.LocalWalSyncImpl.stop()waits for an in-flight drain. Each queued operation chains on the previous one, and_flushawaits the audio write and the index save.git diff --checkis clean.check-mobile-changelog.py --base origin/main --head HEADandmobile-changelog.py validatepass, andscripts/pr-preflight --pr-body-filewith this body passes.Tests
app/test/unit/pendant_ring_custody_flush_test.dartholds the store's directory behind a gate, so a fire-and-forget write is provably pending without sleeps. Its 8 tests:flush()waits for a pending reincarnation write, and for a pending mismatch-invalidation write.flush()waits for a write queued while it was already waiting, and for a checkpoint queued while it waited on the store.flush()waits for live-mark writes still queued on an open session. Deleting the directory afterflush()does not recreate it.PendantCustodyStore.flush()waits for I/O queued while it was already waiting..tmpfile before the directory is deleted.The two timing fixes are covered by their own tests, which now wait on a completion instead of a fixed sleep. Each still fails if the behavior is missing. With no incremental advance, the count stays 0 after the 10 s bound. With no drain inside the 10 s window, either no timer fires or the index has no disk WAL.
Failure class (fixes)
Failure-Class: new
Failure-class transition narrative (only when needed)
new: the nearest existing classes have other owners.FC-continuation-resumed-after-unmountis a widgetStatecontinuation.FC-run-loop-timer-outlives-owneris a desktop run-loop timer.FC-dropped-derived-future-rethrows-handled-errorre-emits an already-handled error. None covers queued storage writes outliving storage teardown.flush()on the queue owner, awaited before storage teardown. The pinning test isapp/test/unit/pendant_ring_custody_flush_test.dart, and the class file is.github/failure-classes/FC-queued-write-outlives-storage-teardown.json.omi_ring_custody_test.dart"persisted durable frontier replays before READ through 0x15 only", on main at0c00747665(Pacific/Kiritimati lane) and in PR fix(app): load the app catalog on Integrations when apps came from the cache #20497 run 37147694253.mark persist/advance failed … PathNotFoundExceptionfive times inpendant_ring_custody_test.dart, andmismatch-invalidation persist failed … PathNotFoundExceptiononce inring_custody_download_test.dart.4e938058d9) were fixed-sleep timing failures, described above.FC-virtual-idle-before-durable-io: a test fired a timer callback, dropped its Future, and then read durable state. The fix reuses that class's existing guard,ManualScheduler.waitForCallbackIo(). This PR does not change that class's definition.wals.json.tmperror has this class's shape: a queued WAL index write outlived teardown. It ran late only because the failed assertion skippedsync.stop(), and thefinallynow covers that.