fix(sqlite): compare idempotency CreatedAt in UTC instead of as offset-dependent strings - #916
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #916 +/- ##
==========================================
+ Coverage 95.85% 95.93% +0.07%
==========================================
Files 275 275
Lines 11895 11902 +7
Branches 1125 1125
==========================================
+ Hits 11402 11418 +16
+ Misses 275 265 -10
- Partials 218 219 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SQLiteIdempotencyKeyRepositorystoredCreatedAtand boundvalidFromas round-trip ("O") strings with whatever offset the caller passed, and then compared them asTEXT. String order only matches time order when both values use the same offset, so a key stored as13:00+02:00(11:00Z) was reported as existing for a12:00Zcutoff, and the reverse case reported valid keys as expired. The repository now normalizes every timestamp to UTC before it binds it, and compares legacy rows that still carry a non-UTC offset as points in time.Closes #860
Changes
src/NetEvolve.Pulse.SQLite/Idempotency/SQLiteIdempotencyKeyRepository.csToUtcStringhelper (ToUniversalTime().ToString("O", CultureInfo.InvariantCulture)). All four bind sites use it:ExistsAsync.validFrom,StoreAsync.createdAt, andTryReserveAsync.createdAt/validFrom. The issue only lists the first two because it predates feat(idempotency): refresh expired idempotency keys atomically on reserve and store #909.TryReserveAsynchad the same defect.IdempotencyStorealready writes (...+00:00). No schema change and no data migration are needed.ExistsAsyncand theTryReserveAsyncupsert (ON CONFLICT ... DO UPDATE ... WHERE) use a shared SQL condition:+00:00are compared as text. This is fixed width, so it is exact to 100 ns, which is the same behavior as before for all rows the built-in store writes.julianday(CreatedAt)vs.julianday(@validFrom), so rows written with a non-UTC offset by earlier versions are handled correctly. The fallback is precise to the millisecond.tests/NetEvolve.Pulse.Tests.Integration/Idempotency/SQLiteAdoNetIdempotencyTests.cs: five SQLite-specific integration tests (see below).No new ADR: this follows the accepted
2026-01-21-datetimeoffset-and-timeprovider-usagedecision and the existingToUniversalTime()pattern of the SQLite outbox, audit and dead-letter stores.Bug hunt
ExistsAsyncreports a key stored with a larger offset as existing although it was created before the cutoff (issue scenario)Should_Treat_Offset_Key_Before_Cutoff_As_AbsentExistsAsyncreports a key as expired when the cutoff carries a larger offset (reverse case)Should_Treat_Key_After_Offset_Cutoff_As_PresentTryReserveAsync(added in #909) does not refresh an expired key stored with a non-UTC offsetShould_Reserve_Offset_Key_Before_CutoffTryReserveAsyncrefreshes (steals) a live key when the cutoff carries a larger offsetShould_Not_Reserve_Key_After_Offset_CutoffShould_Compare_Legacy_Offset_Row_In_UtcDateTimeOffsetvalues with a non-zero offset (Npgsql only accepts offset 0 fortimestamptz)IdempotencyTestsBasefor this reasonImpact
IIdempotencyKeyRepositoryfromNetEvolve.Pulse.SQLitedirectly with non-UTC offsets. The built-inIdempotencyStorealways passesTimeProvider.GetUtcNow(), so its rows and comparisons are unchanged.Test evidence
dotnet test --project tests/NetEvolve.Pulse.Tests.Integration -c Release -f net10.0 --treenode-filter "/*/*/SQLiteAdoNetIdempotencyTests/*"on the test commit: 5 failed (the new tests), 15 succeeded, 3 skipped.--treenode-filter "/*/*/SQLite*IdempotencyTests/*"(ADO.NET + EF Core SQLite, all TFMs): 123 total, 105 succeeded, 0 failed (18 skipped, provider capability skips).dotnet build Pulse.slnx -c Release: 0 warnings, 0 errors.csharpier check .: clean.