Skip to content

fix(app): count union of audio intervals in recording blocks (#23561) - #23570

Closed
huynhnhatquandongnai-source wants to merge 2 commits into
BasedHardware:mainfrom
huynhnhatquandongnai-source:fix/offline-sync-recording-block-audio-union
Closed

huynhnhatquandongnai-source wants to merge 2 commits into
BasedHardware:mainfrom
huynhnhatquandongnai-source:fix/offline-sync-recording-block-audio-union

Conversation

@huynhnhatquandongnai-source

Copy link
Copy Markdown

Summary

Fix inflated offline sync duration by computing the union of positive audio intervals rather than span between earliest start and latest end (closes #23561).

  • In �pp/lib/pages/conversations/recording_blocks.dart: update RecordingBlock.seconds to collect positive audio intervals [timerStart, timerStart + seconds], sort by start, and merge overlapping intervals to calculate the exact total audio duration. Gaps between non-consecutive WALs (e.g. 55s gaps within the 120s grouping window) are excluded from the reported duration. Overlapping phone/device copies are counted once.
  • Add regression tests in �pp/test/pages/conversations/recording_blocks_test.dart verifying gap exclusion, overlapping copy deduplication, and non-positive length filtering.

Invariants affected

  • Counts union of positive audio intervals without reporting gap time as pending audio.
  • Overlapping phone/device copies count once.
  • Preserves recording grouping, source files, ownership, retry, and upload state.

Failure-Class: none

…rdware#23561)

## Summary
Fix inflated offline sync duration by computing the union of positive audio intervals rather than span between earliest start and latest end (closes BasedHardware#23561).

- In `app/lib/pages/conversations/recording_blocks.dart`: update `RecordingBlock.seconds` to collect positive audio intervals `[timerStart, timerStart + seconds]`, sort by start, and merge overlapping intervals to calculate the exact total audio duration. Gaps between non-consecutive WALs (e.g. 55s gaps within the 120s grouping window) are excluded from the reported duration. Overlapping phone/device copies are counted once.
- Add regression tests in `app/test/pages/conversations/recording_blocks_test.dart` verifying gap exclusion, overlapping copy deduplication, and non-positive length filtering.

## Invariants affected
- Counts union of positive audio intervals without reporting gap time as pending audio.
- Overlapping phone/device copies count once.
- Preserves recording grouping, source files, ownership, retry, and upload state.

Failure-Class: none

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: the production fix is correct and nicely scoped, but one of the three new tests cannot pass as written, so this needs a small change before merge.

What's good (app/lib/pages/conversations/recording_blocks.dart):

  • The new seconds getter is a correct interval union: it keeps only positive-length WALs, sorts [timerStart, timerStart + seconds] pairs, and merges overlaps with a standard sweep, so pauses shorter than the 120 s grouping tolerance are no longer reported as audio (recording_blocks.dart:23-52). A block whose WALs are all zero/negative length now returns 0 instead of a bogus span. O(n log n) over the handful of files in a block - no perf concern.
  • Consumers check out: auto_sync_page.dart:678 and on_the_way_page.dart:285/340 use block.seconds purely for row durations and totals, which is exactly the display #23561 describes; sync_provider.dart:727 sums per-WAL seconds directly and is unaffected. Grouping, ownership, retry and upload state are untouched.

Blocking issue (app/test/pages/conversations/recording_blocks_test.dart):

  • 'counts overlapping device and phone copies once in union (#23561)' cannot pass as written. With joinDeviceCopies: true, a phone WAL joins the device block only when _copiedFromDevice is true, i.e. originalStorage is sdcard/flashPage (recording_blocks.dart:76-79) - and originalStorage defaults to null in Wal. Your _wal(0, 75) has no originalStorage, so it groups under the phone key ('pendant-a', false) together with _wal(100, 50), while _wal(0, 75, storage: WalStorage.sdcard) groups under ('pendant-a', true). That is two blocks, and blocks.single throws. Suggested fix: model a real drained copy - add an originalStorage parameter to _wal and stamp the phone copies as WalStorage.sdcard - then either assert the two blocks' durations sum to 125, or make _wal(100, 50) a drained copy too so all three land in one block.

The other two new tests trace correctly: three 5 s WALs with 55 s gaps -> 15 s, and zero/negative lengths -> 10 s.

USER IMPACT: Offline Sync and On the Way stop counting silent gaps between recording chunks as audio - a recording with pauses will now show its real listening time instead of an inflated duration.

To land this:

  • Fix the union test as above and run flutter test test/pages/conversations/recording_blocks_test.dart so all three new tests pass.
  • Optional: add an assertion that a fully contained overlapping interval (e.g. a 30 s WAL inside a 75 s one) is not double-counted - right now only exact duplicate overlaps are covered.

by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added the flutter flutter work label Oct 25, 2026
@huynhnhatquandongnai-source

Copy link
Copy Markdown
Author

@Git-on-my-level Thank you for the insightful review! Addressed the test issue in commit 409917338d2:

  1. Model real drained copy: Added originalStorage to the _wal helper and stamped the phone copies with storage: WalStorage.disk, originalStorage: WalStorage.sdcard, so with joinDeviceCopies: true both phone and sdcard copies group cleanly under the ('pendant-a', true) block key.
  2. Contained interval assertion: Added an inner interval _wal(20, 30, ...) fully contained inside [0, 75] to verify that sub-intervals are deduplicated and not double-counted, asserting the total duration remains strictly 125 s.

Ready for re-review!

Copy link
Copy Markdown
Collaborator

Thanks for correcting the drained-device-copy fixture. I reviewed 4099173: all nine model tests pass locally, and an additional 2,000-case synthetic interval-union check passes without changing WAL metadata or order.

The equivalent duration fix has now landed through #23566 (merge 18c4a38). That PR also includes the rendered summary/day/row regression and required changelog, so no additional implementation from this PR is needed for #23561. Keeping one landed implementation avoids duplicate work; this PR is superseded for that issue.

The fix still needs a mobile release. It corrects displayed duration only; stalled transcription and customer audio recovery are separate.

@Git-on-my-level
Git-on-my-level dismissed their stale review October 26, 2026 12:31

Dismissed: the blocking concern from this review (union test grouping phone copies without originalStorage into a separate block) is resolved on head 4099173 — _wal now stamps drained phone copies with originalStorage: sdcard, all four WALs group into one block under joinDeviceCopies, and the union assertion (125 s) traces correctly against groupRecordingBlocks. Dart tests are green on this head. Follow-up review tracks the remaining, unrelated Hygiene ui-evidence contract item.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since my last review: addressed (the union test now models drained device copies correctly — verified below) · still open (Hygiene fails the ui-evidence contract) · newly introduced (nothing).

Verdict: the code side is done — the test issue I blocked on is fixed and the optional contained-interval case is covered too; what remains is one line in the PR description, not code.

Verified on this head:

  • app/test/pages/conversations/recording_blocks_test.dart — _wal now takes originalStorage and the phone copies are stamped WalStorage.sdcard, so with joinDeviceCopies: true all four WALs group under the same device key (recording_blocks.dart:94) and join into one block (gaps/overlaps within the 120 s tolerance); the union 0–75 ∪ 20–50 ∪ 100–150 = 125 s matches the assertion. The _wal(20, 30, …) piece also covers the fully-contained-overlap case from my earlier review. Dart Analyze & Tests is green here.
  • app/lib/pages/conversations/recording_blocks.dart — unchanged since my last review; the interval-union seconds getter still reads correct.

Blocking (repo contract, not code): the Hygiene job fails its ui-evidence check. PRs touching app/lib/**/*.dart must either reference a tracked screenshot under .agent-artifacts/ui-evidence/… in the description, or add an exact line to the PR description, e.g.:

UI-Evidence: none -- duration numbers only, no layout or visual change

USER IMPACT: Offline Sync and On the Way will show real listening time for recordings with pauses, instead of an inflated duration that counted silent gaps as audio.

Remaining action item:

  • Add the UI-Evidence: line (or a screenshot) to the PR description so Hygiene goes green; after that this looks ready for a maintainer merge.

by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for this contribution! Our review requested some changes (see above) and we haven't heard back in a while. If you're still working on it, just push a commit or leave a comment within the next 7 days. To keep the queue healthy we'll close this PR in 14 days if it stays inactive — and it can always be reopened once updates land. Happy to re-review!

@Git-on-my-level Git-on-my-level added the stale-candidate Candidate for kind stale follow-up label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Hey @huynhnhatquandongnai-source 👋

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work stale-candidate Candidate for kind stale follow-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(app): Offline Sync counts gaps between chunks as pending audio

3 participants