fix: store timestamps in UTC so recall expiry filtering is order-correct - #11
Merged
Merged
Conversation
Recall filters expiries inside SQL by comparing ISO strings lexicographically, but records stored whatever UTC offset the client sent. When the local wall-clock date crossed a date boundary relative to UTC, still-valid memories were treated as expired and silently dropped, while list/status reported them as active. Normalise created_at/updated_at/expires_at (and the recall 'now' parameter) to +00:00 on write so string comparison matches chronological order. Cursor encoding uses the same normalisation for consistency. Fixes part of #9
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: krishna3554 <87197325+krishna3554@users.noreply.github.com>
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.
Problem
Part of #9 (item 2).
Recall filters expired memories inside SQL by comparing ISO strings lexicographically:
But records stored whatever UTC offset the client sent (
isoformat()is not normalized). When a non-UTC offset shifts the wall-clock date across the UTC date boundary, comparison breaks.Reproduced on main: memory with
expires_at = 2026-08-27T10:00:00-11:00(= 21:00Z, still valid at 20:00Z):GET /v1/memories→ statusactive(parsed-datetime comparison)POST /v1/memories/recall→ 0 results ("...T10:00:00-11:00" < "...T20:00:00+00:00"lexically)The same memory is simultaneously visible in list and invisible in recall.
Fix
Add
SQLiteMemoryRepository._utc_isoformat()and use it for every timestamp persisted into SQL-comparable columns (created_at,updated_at,expires_aton both insert and semantic-duplicate update paths) plus the recallnowparameter and cursor encoding. All stored timestamps now share a fixed+00:00offset, so lexicographic order equals chronological order. Read paths are unchanged —fromisoformathandles both.Tests
test_recall_includes_memories_expiring_after_now_regardless_of_offset— repository-level regression test using a fixed clock and a-11:00expiry one hour before cutoff