Skip to content

fix(app): keep offline sync moving past bad clocks and stalled pendant reads - #25331

Merged
Git-on-my-level merged 17 commits into
BasedHardware:mainfrom
Git-on-my-level:lane/q12-app-sync
Nov 15, 2026
Merged

Git-on-my-level merged 17 commits into
BasedHardware:mainfrom
Git-on-my-level:lane/q12-app-sync

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Offline Sync keeps valid audio ahead of unknown/future capture clocks, with one isolated clock-recovery batch after at most 36 valid batch attempts. The shared budget is now saved on waiting WALs in the owner-fenced index before valid uploads, so repeated iOS process restarts cannot erase the turn. A recovery batch resets the shared budget after entering the gate, allowing valid work to resume. No request mixes valid and unknown-clock files.

Only invalidCaptureTime (invalid_capture_time) retries daily during the first week, then weekly indefinitely until accepted. Other refusal reasons retain their existing expiry. The 25-refusal-per-drain cap and single-file isolation remain. A server rollout may start disabled and enable recovery later: an already expired refusal becomes eligible on its next weekly due date without user action or a new app install. Weekly probes cost at most five full-file requests per affected file per rolling 30 days after the first week (roughly 4–5 times its bytes plus request overhead), and stop on acceptance. This is a schedule bound, not a measured currency cost.

The install migration is removed. It is unnecessary with non-expiring paced recovery and introduced an eager startup index save that blocked walReady in the gated-save test and consumed the first injected save failure. The existing flush still awaits the durable audio/index before publishing live custody proof or issuing pendant ADVANCE. Strengthened regressions assert no persisted row, proof, or ADVANCE while the actual audio index write is blocked or fails, followed by proof only after a successful save. Neither stored refusal clock is reset, so there is no migration/receipt crash boundary. Deterministic refusals remain aggregated without user attention or an immediate same-pass retry; the only deliberate policy difference is the slow, persisted invalid-date schedule. Rows retain the existing “Invalid recording date” label until accepted, then follow the existing uploaded/processing states.

A settled pendant read failure gives the phone backlog its upload turn. Cancellation during a queued phone flush remains cancelled before the gate, including the new budget checkpoint. Pass serialization, the upload mutex, owner fencing, durability and acknowledgment rules remain in place.

LittleFS first parsed DATA and subsequent audio idle both have conservative 60-second deadlines. Firmware 3.0.17–3.0.19 permits 500ms queueing plus 15s for an SD read, then unbounded BLE-buffer retries without a progress heartbeat. The tests cover first DATA arriving after 20 seconds, a healthy 45-second inter-DATA gap, and ACK-only traffic still failing at 60 seconds. Incomplete transfers retain the original device record, save parsed audio durably, never skip the unread head, and report failure after cleanup. Evidence: app/docs/offline-storage-liveness.md.

The app does not rename existing files because the companion server fix accepts both ..._<timestamp>_uN.bin and ..._uN_<timestamp>.bin forms. New collision names keep the timestamp last.

Rollback defines, all compile-time and default false: OMI_WAL_CLOCK_PRIORITY_OFF, OMI_PHONE_AFTER_DEVICE_FAILURE_OFF, OMI_STORAGE_AUDIO_LIVENESS_OFF, OMI_DEVICE_COLLISION_TIMESTAMP_LAST_OFF, and OMI_INVALID_CAPTURE_TIME_RECOVERY_OFF. The last restores seven-day expiry without changing stored state. The storage define restores the original five-second any-packet first-data detection and disables audio idle; it does not restore silent incomplete-transfer success, remove cleanup, or weaken custody/delete proof. These are not remote-config switches.

Release notes for the lead: the normal store route is Codemagic with validated release tags, exact-source Release Eligibility and Mobile Release Eligibility receipts, then store approval and the documented phased/staged train. App/lib PRs need the ordinary source/review/CI gates, invariant/failure-class metadata, changelog fragment and UI evidence declaration; this service-only change declares no UI evidence. Codemagic contains Shorebird iOS/Android patch workflows and app/shorebird.yaml, so these Dart-only changes are patch candidates only for an installed binary already built with a compatible Shorebird release. Current store lanes use ordinary flutter build; updater compatibility of the owner's 1.0.592+1560 is unverified. Server-side recovery/parser work can ship separately, but cannot change this client's scheduling/timers or filename generation.

Product invariant: INV-CAP-1.

Failure-Class: FC-batch-fault-domain-head-of-line-poison

UI-Evidence: none -- Changes are confined to WAL scheduling, transfer liveness and persistence; no widgets, layouts or user-facing strings were changed.

Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 2754 -> 2789 | Preserve the existing ledger authority and cancellation fences, checkpoint the bounded clock-class turn, and conservatively observe unaccepted unknown-clock audio for the merged end marker; index durability and restart regressions cover the shared state.

Merged origin/main at 2d59f75eace67a03cc31dd07effa7ab73b8e15a5 into local head f5758dd1afa9846ca4eaf6c864388c7efcf9d6e0, preserving #25311 capture-end reporting and #25332 upload tracing. The only textual conflict was at the bulk-upload gate in local_wal_sync.dart; both clock-turn bookkeeping and trace preparation remain after the cancellation check. The marker remains an observer. Unknown-clock or refused WALs in its session, including future-clock chunks awaiting index publication, cannot produce a false zero watermark; accepted files and trusted trailing silence stay excluded. Focused regressions cover both clock classes accepted serially and failed publication. The fetched main uses a pending_wals JSON watermark and an X-Omi-Upload-Trace timing header; it contains no separate upload-watermark header.

The capture-end observer now counts retained batch journals directly from disk instead of relying on the current writer and publishing list. Failed seal flush/close, failed append/publish, cancellation and process loss cannot erase the count. Replayed journals may overlap the ledger until server acceptance; they are excluded only for acknowledged files whose current byte length matches the accepted length, with no retained torn original. Transport-only synced, terminal-refused and corrupted rows stay conservatively pending. Unreadable evidence over-counts; an unavailable directory or unknown ledger suppresses the marker. An append during the asynchronous scan invalidates that observation and retains the end for a later accepted-file wake. Reports are bound to the account and WAL generation before queuing and after the scan. No new startup save, uploader, cleanup authority or audio deletion is added. Focused real-ledger regressions cover both failed seal operations, cancellation, replay and eventual zero after actual upload acceptance; additional cases cover append failures, account changes, unreadable evidence and a growing accepted prefix. Validation on local head 46a179598fb40829d679bddea9dca040c6719ede completed 2026-11-15T00:32:09Z through bin/omi-heavy, Flutter 3.44.5 / Dart 3.12.2: full CI app/test.sh 8,837 passed, 5 skipped, zero failures across all 981 Dart files; separate dev-controls spine 138 passed; three exact CI timezone runs 39 passed each. Focused four-file regression run 98 passed. Format checked 23 Dart files, unchanged. Nine touched Dart files analyze with no issues; full analyzer ratchet passed without baseline change. Expanded directory analysis reports 11 existing infos outside changed files, zero errors/warnings. The actual pre-push hook passed, including all 29 preflight checks, generated-output validation and formatting. Backend type/unit selectors ran with no applicable backend delta, no skip overrides. Source clean; no push or release. The two failed-seal paths, account races, restart/replay, concurrent append and original CI custody/refusal regressions all passed. Full enumeration, files and logs: Q12-I-durable-pending.md, evidence/q12-i-durable-pending/. The lead owns publication, fresh CI and independent review.

Failure-Class: FC-device-timestamp-without-plausibility-window
Failure-Class: FC-batch-fault-domain-head-of-line-poison
Failure-Class: FC-device-transfer-failure-reported-as-complete
Failure-Class: FC-device-timestamp-without-plausibility-window
Failure-Class: FC-cancel-strands-pending-wait
Failure-Class: FC-sync-refusal-spends-user-attention
Failure-Class: FC-offline-drain-newest-first-starves-recovery-deadline
Failure-Class: FC-device-transfer-failure-reported-as-complete
Retry invalidCaptureTime daily for the first week and weekly indefinitely, retaining the cap, original clocks and priority. Remove the install migration and its eager startup index save; keep live custody proof and ADVANCE behind the real durable save.

Failure-Class: FC-sync-refusal-spends-user-attention
Use a 60-second first-DATA deadline as well as the audio-idle window. Real DATA delayed 20 seconds succeeds; ACK-only chatter still fails without advancing the unread record. Keep the rollback define at the original five-second first-packet behavior.

Failure-Class: FC-batch-fault-domain-head-of-line-poison
Checkpoint the shared 36-valid-batch budget on waiting WALs in their owner-fenced index before upload. Spend it only after the unknown-clock batch enters the gate, then yield back to valid audio. Exercise repeated service recreation with continuous same-session work and two unknown-clock rows.

Failure-Class: FC-batch-fault-domain-head-of-line-poison
Use the parsed invalid-capture-time exception for the day-eight server rollout regression and satisfy the analyzer brace rule without changing its baseline.

Failure-Class: FC-sync-refusal-spends-user-attention
Use the existing WAL interface export for the production refusal exception so touched-file analysis stays clean.

Failure-Class: FC-sync-refusal-spends-user-attention
Include held uploadRejected rows in the persisted class budget under their existing automatic recovery authority. Held miss and on-device-only rows remain excluded. Exercise the held refusal beside a future-clock miss and continuous valid work across service restarts.

Failure-Class: FC-batch-fault-domain-head-of-line-poison
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Independent review (GPT-6 Luna, xhigh), three rounds, final exact-head verdict.

VERDICT: SHIP
HEAD: 54a48fc

Round one (930d7fc) and round two (88ad1f7) were FIX-FIRST: a cancel could be lost before the fallback upload; future-clock refusals could become permanently ineligible; the first-DATA deadline was shorter than the firmware's read window; the fairness counter did not survive restarts; a one-time migration was not crash-idempotent. All are addressed; the migration was removed in favour of an indefinite weekly retry for invalid-date refusals.

On the custody regression CI caught at 88ad1f7 (local_wal_live_custody_test.dart: an ADVANCE observed after a failed index save): the reviewer traced it to the removed migration's unconditional startup index save consuming the test's one-shot failure, not to proof preceding a durable audio index. In the final code _flush reports live proof only after a successful index save, failed concurrent writes are retried before a waiter returns, device chunks require hasDurableWal, and ring ADVANCE validates referenced WALs. No test expectation was weakened in this delta; the custody tests gained startup-save, on-disk index, proof and ADVANCE assertions.

One NOTE, not blocking: add a combined regression where a concurrent save takes the live WAL delta, fails while _flush waits, and succeeds on retry, asserting no proof or ADVANCE before the successful write (app/test/unit/local_wal_live_custody_test.dart:332).

Checked by the reviewer: 101 focused tests across seven files. The author ran the full CI suite locally (8,794 passed, 5 skipped). Not verified by anyone: behaviour on a physical phone and pendant.

Git-on-my-level and others added 3 commits November 15, 2026 06:42
Preserve capture-end observation, upload tracing, serial seal wakes and Q12 recovery/custody fences. Keep unknown-clock and refused audio in the pending watermark until accepted, including unpublished journaled chunks, without changing sealing or upload authority.

Failure-Class: FC-batch-fault-domain-head-of-line-poison
Retain failed seal, append and replay evidence in the pending watermark by reading disk journals. Discharge retained journals only for matching server-accepted bytes; invalidate concurrent capture observations and fence account generations. No startup index save or custody release changes.

Failure-Class: FC-batch-fault-domain-head-of-line-poison
…g count

A retained batch journal that names a different owner can never be uploaded
by the signed-in account, so counting it kept that account's recording open
after an account switch that reused the recording id. Journals with unreadable
ownership still count for every account.

Failure-Class: none

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Independent review of 46a179598fb4 (GPT-6 Luna, second round) returned one finding, no blockers: the journal scan did not compare a journal's owner with the signed-in account, so after an account switch that reused a recording id the new account's capture-end count could stay non-zero forever. Fixed in 52a44d22dbeb: a journal that names another owner is skipped; a journal with unreadable ownership still counts for every account (test added in mobile_standard_batch_test.dart; the two affected test files pass, 70 tests). The reviewer's note that the scan runs on the main isolate without an entry cap is left as is: the calls are asynchronous and the scan runs once per end report and per accepted upload of that recording. Reviewer confirmed no regression to clock ordering, device-failure backlog, transfer deadlines, collision naming or invalid-time retry.

@Git-on-my-level
Git-on-my-level merged commit 7f944b6 into BasedHardware:main Nov 15, 2026
38 checks passed
@aryanorastar

aryanorastar commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Support field evidence for the invalid-clock and backlog behavior covered by this PR. On an iOS CV1 with firmware 3.0.21, a customer reported roughly 2,000 queued entries, including a large undated group and entries dated years into the future. New recordings later produced transcripts and a downstream export, while the older missing period remained absent from the customer's export. The old queue disappeared from view after a reinstall. Its disappearance does not establish upload, deletion or recovery.

A previous production metadata check independently found invalid_capture_time refusals on iOS 1.0.591. The November 18 read-only production recheck verified that a batch job stamped November 12 still carries an allowance hold and its encrypted staged input is listed. A separate group of quota-held objects was created before the reported missing period in the customer's time zone. It cannot be counted as recovery for that period. Phone queue rows, held inputs, and exported conversations measure different things. The customer later reported running 1.0.592. We have not established that their installed build contained this merge or that the same historical files were still on the phone after reinstall. Please use this as field evidence when verifying the release against a mixed valid/unknown-clock backlog. Customer-specific recovery remains with Support. The separate manual transfer percentage problem is tracked in #25653.

A broader owner-scoped reconciliation subsequently found admission records across several days missing from the finished-conversation export. Sampled encrypted inputs still exist, and the non-privacy records in that interval have quota-hold evidence. On another day with no matching capture timestamps, production logs show invalid-time upload refusals. Those logs cannot identify the original capture day of a rejected recording. Fix verification should exercise both a valid timestamp held for allowance and an invalid clock rejected before admission. Neither case should be inferred from the finished-conversation export alone.

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.

2 participants