Skip to content

fix(sync): clamp offline times + keep 60s shards cohesive (#4770, #4771) - #11094

Closed
aryanorastar wants to merge 13 commits into
BasedHardware:mainfrom
aryanorastar:fix/4770-offline-future-dated
Closed

aryanorastar wants to merge 13 commits into
BasedHardware:mainfrom
aryanorastar:fix/4770-offline-future-dated

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Offline sync no longer creates or displays conversations dated in the future when device RTC / phone clock is a few minutes ahead (Offline conversations are FUTURE dated #4770).
  • Also Offline Sync creating mistaken duration date conversations #4771: successive ~60s offline shards with the same mild future skew no longer collapse into many one-minute conversations dated at sync time. v1 + v2 compute one batch-shared clock shift (newest_end - now) before closest-conversation assignment so relative offsets and total duration survive.
  • Client: normalizeWalTimerStart clamps device-sourced Wal.timerStart at addExternalWal and on WAL load so the sync UI never shows a future start; duration is preserved by shifting the window to end at phone now.
  • Backend: mild capture-time skew (within SYNC_CAPTURE_MAX_FUTURE_SKEW_SECONDS, default 300s) is accepted on upload; the sync pipeline shifts capture windows so started_at/finished_at never exceed server now.
  • Far-future timestamps are still rejected.

Test plan

  • python3 -m pytest normalize + batch-shift + ordered-assignment contracts (incl. 5×60s Offline Sync creating mistaken duration date conversations #4771 span)
  • flutter test test/unit/wal_timer_start_normalize_test.dart (4 passed)
  • Manual: sync an offline WAL whose device timestamp is ~2–3 minutes ahead of phone wall clock; sync list + conversation time must be ≤ now and duration unchanged
  • Manual: multi-minute offline backlog with mild RTC skew lands as one cohesive conversation, not N×~1min rows dated “today”

Product invariants affected

none

Failure class (fixes)

Failure-Class: none


Also covers the short-shard fragmentation symptom reported in #5747 (same batch clock-shift path as #4771). Race path already fixed by #7819. Live vs offline conversation_creation_timeout policy remains a possible residual after this lands — reassess then; do not treat as full close of #5747 until that check.

aryanorastar and others added 2 commits August 5, 2026 00:13
…ever future-dated (BasedHardware#4770)

Mild phone-clock skew (a few minutes ahead) either rejected uploads or let
started/finished times land after server now. Allow skew within
SYNC_CAPTURE_MAX_FUTURE_SKEW_SECONDS, then shift the capture window so
duration is preserved and conversations never appear in the future.

Verification: pytest unit tests for normalize_capture_window + filename
timestamp skew (5 passed).

Failure-Class: none
Co-authored-by: Cursor <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

BasedHardware#4770)

Device RTC (SD-card / Limitless flash / ring) can run ahead of the phone
clock; normalize at addExternalWal and on WAL load so the sync list and
upload path see a capture window that ends at phone now.

Verification: flutter test test/unit/wal_timer_start_normalize_test.dart (4 passed).

Failure-Class: none
Co-authored-by: Cursor <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Follow-up from deeper root-cause pass: the sync UI shows Wal.timerStart from device RTC before upload, so backend clamp alone wouldn't fix the on-device list.

Pushed a client choke-point: normalizeWalTimerStart at addExternalWal + WAL load, with unit coverage for the +3min skew case from the issue.

@aryanorastar
aryanorastar requested a review from mdmohsin7 as a code owner August 4, 2026 18:49
@aryanorastar aryanorastar changed the title fix(backend): clamp offline sync times so conversations are never future-dated (#4770) fix: clamp offline sync times so conversations are never future-dated (#4770) Aug 4, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/utils/sync/pipeline.py Resolved
Comment thread backend/utils/sync/pipeline.py Resolved
Comment thread backend/utils/sync/pipeline.py Resolved
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Addressed cubic P1 on the current head:

  • normalize_capture_window now runs before get_closest_conversation_to_timestamps (and before create/merge), so multi-VAD offline WALs with mild future skew merge into the conversation created from earlier segments instead of splitting.
  • Added a regression unit covering successive future segments overlapping after clamp.
  • Bumped the pipeline.py line-count baseline with justification.

Also fixed the Dart analyzer ratchet (prefer_const_declarations) on the WAL timerStart normalize tests.

@Git-on-my-level Git-on-my-level added the needs-maintainer-review Needs a human maintainer to sign off before merge label Aug 4, 2026

@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.

Thanks for the follow-up on #4770. I reviewed the current head after the client-side clamp and the backend pre-lookup normalization changes.

This looks directionally good to me: the fix now covers both places future timestamps could surface, and the added regression coverage exercises the client clamp, mild future upload acceptance, backend capture-window normalization, and the multi-segment merge case that would otherwise split conversations. The checks are green on this head.

I don't see a blocking correctness issue in the current diff. Since this spans client + backend sync timestamp behavior, I’m marking it for maintainer review rather than formal approval, but my technical signal is positive.


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

BasedHardware#4771)

Independent per-window normalize collapsed successive future-skewed WALs onto
[now-60, now], recreating one-minute conversation spam dated at sync time.
Compute one batch shift (newest_end - now) and apply it in v1 + v2 assignment.

Failure-Class: none
Co-authored-by: Cursor <[email protected]>
@aryanorastar aryanorastar changed the title fix: clamp offline sync times so conversations are never future-dated (#4770) fix(sync): clamp offline times + keep 60s shards cohesive (#4770, #4771) Aug 5, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

PR Metadata Preflight failed on the product-file line-count ratchet: backend/routers/sync.py grew 2053 → 2060 from the batch-shared clock-shift wiring in 8b855531.

Pushed a baseline raise to 2060 with justification (+7 for the ordered-assignment batch shift for #4771). Pipeline baseline was already updated on the prior commit.

aryanorastar and others added 2 commits August 5, 2026 20:01
…e#4770)

Move maximum_future_skew_seconds into request_validation (lanes already
imports from there) and use it from upload validation + pipeline staging
so the env default cannot drift across the three former copies.

Failure-Class: none
Co-authored-by: Cursor <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Resolved the backend-routers.json conflict against current main on 580e4364:

Also landed cubic P3: maximum_future_skew_seconds() now lives in utils.request_validation and is the single source for upload validation, lane classification, and pipeline staging (f97da414). Focused suite: 80 passed.

@mdmohsin7 still needs code-owner review when you have a moment (#4770/#4771).

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Batch-shared clock shift for skewed offline shards (#4770/#4771) looks right; approving — CI still pending and the manual sync checks are unticked, so not merging.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@mdmohsin7 Friendly bump on the code-owner review for #4770/#4771.

Current head 580e4364:

  • @kodjima33 approved (holding merge until CI finishes + acknowledging unticked manual sync checks)
  • Hygiene/Formatting/Dart/Android/Sync gauntlets green; Backend unit suite was still running last I checked
  • Cubic P3 centralized on maximum_future_skew_seconds(); line-count baseline conflict with main resolved

If the client WAL clamp + backend batch clock-shift approach looks good, an APPROVE from you clears the merge gate. Thanks!

…Hardware#4770)

MagicMock stubs of utils.request_validation (cloud_tasks / file_paths
suites) were turning maximum_future_skew_seconds into a MagicMock and
breaking timedelta math. Keep the single helper in utils.sync.capture_skew
and unload real utils.sync.* after the file_paths AutoMock import so
lanes does not leak a mocked parse_sync_filename_timestamp into later tests.

Co-authored-by: Cursor <[email protected]>
@aryanorastar

aryanorastar commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator Author

Backend unit suite was red after f97da414 centralized maximum_future_skew_seconds() into utils.request_validation.

Root cause: suites that AutoMock / MagicMock utils.request_validation (test_sync_file_paths_filename_none, test_sync_cloud_tasks) left lanes/pipeline calling a MagicMock for skew → TypeError: unsupported type for timedelta seconds component: MagicMock. After that fixed, the same AutoMock import also left a real utils.sync.lanes bound to a MagicMock parse_sync_filename_timestamp, which polluted later cloud_tasks cases into 422 backfill_lookback_exceeded.

Fix @9bfeda37:

  • Single helper now lives in utils.sync.capture_skew (os-only); upload validation / lanes / pipeline all import it from there (request_validation re-exports for callers).
  • test_sync_file_paths_filename_none unloads real utils.sync.* after the AutoMock import so later suites get a clean lanes module.

Focused suite (file_paths + cloud_tasks + ordered-assignment + two-lane + request_validation contracts): 170 passed.

still needs code-owner review when CI goes green on this tip.

…dware#4770)

Pyright reportUnusedImport failed the backend unit contract once
maximum_future_skew_seconds no longer reads env from request_validation.

Co-authored-by: Cursor <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Backend unit suite was still red on @9bfeda37 — not pytest this time.

Pyright contract: Import "os" is not accessed (reportUnusedImport) in utils/request_validation.py after the skew helper moved to utils.sync.capture_skew.

Dropped the unused import @Head. Should clear the 1-error pyright gate.

@Git-on-my-level Git-on-my-level added the backend Backend Task (python) label Aug 5, 2026

@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.

Thanks for continuing to tighten this. I reviewed the current head after the batch-shared clock-shift update.

This is a positive technical signal from me. The client-side Wal.timerStart normalization covers the on-device list/upload choke point, and the backend now accepts bounded clock skew while normalizing before closest-conversation lookup. The shared batch shift in both sync paths is the important follow-up for #4771: it preserves the relative spacing of successive ~60s offline shards instead of independently collapsing each shard onto [now-60, now].

The focused coverage looks appropriate here: client normalization tests, upload timestamp contract coverage, backend window/batch-shift regression tests, and ordered-assignment checks that both pipelines pass the shared shift into process_segment. Current CI is green.

I don’t see a blocking correctness issue in this diff. Keeping maintainer review required before merge because this changes client + backend sync timestamp semantics and has outstanding manual device/backlog validation in the PR checklist, but the implementation direction looks sound.


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

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level Thanks for the re-confirm on the batch-shared clock shift.

Agreed the outstanding gap is maintainer/manual device backlog smoke (mild RTC skew + multi-minute offline shards → one cohesive convo). No further author code changes pending on 70d090d8.

@mdmohsin7 Friendly bump for code-owner review when you have a window — CI is green, @kodjima33 already APPROVED (holding merge for CO + unticked manual checks). Head also covers the #5747 60s-shard fragmentation symptom under clock skew (commented on that issue today); still tagged #4770/#4771 as the primary scope.

Resolve product-file line-count baseline conflicts:
- mcp_sse.py: take main 1968 + SCA-294 justifications
- sync.py: keep 2060 + BasedHardware#4771 batch clock-shift justification
- pipeline.py: keep 2520; combine soft-cap + BasedHardware#4770/BasedHardware#4771 raise text

Co-authored-by: Cursor <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Resolved merge conflicts against current main @172b0800:

Line-count ratchet OK on the PR file set. Still needs @mdmohsin7 code-owner APPROVE.

@mdmohsin7

Copy link
Copy Markdown
Member

This is no longer an occuring issue and was fixed in firmware 3.0.17 when RTC was enabled for the device

@mdmohsin7 mdmohsin7 closed this Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Hey @aryanorastar 👋

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

backend Backend Task (python) needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants