Skip to content

MOBILE-548: Send the age of an event as dateTimeOffset on its first attempt too - #854

Merged
enotniy merged 2 commits into
feature/MOBILE-541from
feature/MOBILE-548
Nov 18, 2026
Merged

enotniy merged 2 commits into
feature/MOBILE-541from
feature/MOBILE-548

Conversation

@enotniy

@enotniy enotniy commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

https://tracker.yandex.ru/MOBILE-548

An event that stayed in the database without a failed send attempt went out with dateTimeOffset=0, so the backend dated it by the moment it arrived, not by the moment it happened. This is the case when the app is killed before the first attempt, when the queue is cancelled in the background, or when delivery is not enabled yet. On the next launch, up to six months later (MBDatabaseRepository.lifeLimitDate), an old Inapp.Show looked like a show that had just happened, including for an in-app stopped weeks earlier.

Event.dateTimeOffset returned 0 unless the event had a retryTimestamp. The zero comes from 6409b8e and ca43347 (2022), which stopped small negative offsets on the first attempt. #846 clamps the offset at 0, so the guard is no longer needed: the offset is now always the age of the event.

Behaviour change. A fresh event is sent with an offset of a few milliseconds instead of 0.

Tests

  • DatabaseRepositoryTestCase: an Inapp.Show stored three days ago with no send attempt is returned by the delivery query, and the request built from it carries a three-day dateTimeOffset (fails without the fix: 0.0 is not equal to 259200000.0); the same event created before the clock was set back goes out with dateTimeOffset=0. retryTimestamp is left unset, as for a real event that was never tried.
  • GuaranteedDeliveryTestCase: testDateTimeOffset_WhenNotRetry_isZero pinned the old behaviour and now checks that a new event has an offset under a second.
  • VersioningTestCase sorted events by dateTimeOffset, which was 0 for every event; it now sorts by enqueueTimeStamp.

Checked

  • The full Mindbox test plan passes on an iPhone 16 simulator; swiftlint --strict is clean.
  • Mutation check: 11 mutants of Event.dateTimeOffset and of the dateTimeOffset query parameter in EventRoute (retry-only guard, inverted guard, no clamp, min for max, clamp at 1, constant 0, seconds for milliseconds, flipped sign, age from retryTimestamp, constant 0 in the request, parameter omitted) are all killed by DatabaseRepositoryTestCase and GuaranteedDeliveryTestCase.
  • By hand: an event held back by a breakpoint in DeliveryOperation.main() and sent on the next launch carries its age in dateTimeOffset.

Stacked on #846 (base feature/MOBILE-541): merge after it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tests check the constructed event instead of the queried result and set retryTimestamp to zero rather than leaving it unset, so the intended fetch path and returned retry state and offset remain unverified.

1 open issue
What changed in this PR

Updates Mindbox’s iOS event delivery to send an event’s age on its first attempt, preserving the original timing of events held in the database.

Changes:

  • Calculate offsets regardless of retry status, retaining the nonnegative clamp.
  • Add delayed-first-send and clock-rollback regression tests.
  • Sort versioning test events by enqueue time instead of offset.
File Description
MindboxTests/​Versioning/​VersioningTestCase.swift Orders events by enqueue timestamp.
MindboxTests/​Mock/​MockEvent.swift Aligns mock offsets with first-attempt behavior.
MindboxTests/​GuaranteedDelivery/​GuaranteedDeliveryTestCase.swift Adds offset cases and adjusts timing assertions.
MindboxTests/​Database/​DatabaseRepositoryTestCase.swift Adds persisted-event offset regression cases.
Mindbox/​Model/​Event.swift Removes the retry-only offset guard.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor
TestsPassed ✅SkippedFailedTime ⏱
Unit tests report3156 ran3156 ✅4m 19s 360ms

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

Изменение в Event.swift корректное. Во всех трёх сценариях из тикета offset считается при сборке запроса, в том числе после отложенной отправки из #846. Замечания касаются только тестов, они inline.

В описании PR написано «up to a month later», но события хранятся до 6 месяцев (MBDatabaseRepository.lifeLimitDate). Значит, offset может доходить примерно до 184 дней. В тикете та же неточность.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tests do not verify a nonzero offset for fresh, first-attempt events, so an incorrect zero offset could go undetected.

1 open issue
1 resolved since last review

Review effort: Balanced

@enotniy
enotniy merged commit 427bd3f into feature/MOBILE-541 Nov 18, 2026
8 checks passed
@enotniy
enotniy deleted the feature/MOBILE-548 branch November 18, 2026 10:21
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.

3 participants