Repository navigation
Conversation
adapt_datetime_epoch interpreted naive datetimes in the process local timezone and convert_timestamp returned local wall clock time, so a database written on a non-UTC host stored event_ts and created_ts offset by the local UTC offset, and a reader in another timezone got shifted timestamps that made TTL checks report fresh rows as OUTSIDE_MAX_AGE. Treat naive datetimes as UTC in adapt_datetime_epoch and return naive UTC datetimes from convert_timestamp, matching the naive means UTC contract of to_naive_utc and make_tzaware. Rows already written by non-UTC hosts keep their shifted epochs and are not migrated automatically. Add regression tests that flip the process TZ between the write and read sides, assert the on-disk epochs equal the true UTC epochs, and check TTL status through the production TTL path. Signed-off-by: PandaAB <104823169+PandaAB@users.noreply.github.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
Devin Review found 1 potential issue.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| """Convert a Unix epoch timestamp to a naive UTC datetime.""" | ||
| return datetime.fromtimestamp(int(val), tz=timezone.utc).replace(tzinfo=None) |
There was a problem hiding this comment.
🔴 Incorrect timestamps for existing SQLite features
After upgrading in place, convert_timestamp misreads rows that older versions wrote with a nonzero timezone offset. The old reader reversed that offset on the same host. Now online retrieval can mark fresh features expired or expired features fresh.
Learn more
SQLite keeps the latest feature values and their timestamps in an on-disk database. Previously, online_write_batch supplied naive UTC datetimes to an adapter that interpreted them in the writer's local timezone. The old reader reversed that shift when it ran under the same timezone and the conversion round-tripped. update preserves existing tables, so the new converter reads the same integers as UTC. online_read labels the result UTC, and the freshness check uses it without correction. Incremental materialization starts at the last completed interval and does not automatically replay all existing rows.
Example: A Shanghai deployment writes a feature at 05:34 UTC. Before upgrading, it reads back 05:34 UTC. At 05:39 UTC after upgrading, the same row reads back 21:34 UTC on the previous day and returns OUTSIDE_MAX_AGE for a one-hour TTL.
Recommended fix: Provide an upgrade path that rebuilds the affected online rows from authoritative feature data before the new reader serves them. Document how to rebuild and repopulate the store rather than relying on incremental materialization. Do not infer the original writer's timezone from the current reader's timezone: legacy and corrected epochs have the same integer representation. Add a regression test that writes a row with the legacy adapter and reads it after upgrading.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Good callout, and I agree with not trying to infer the original writer timezone in convert_timestamp since legacy and UTC epochs have the same integer representation.
This is the upgrade trade-off noted in # Misc. Hosts running in UTC are unaffected. For non-UTC hosts upgrading in place with an existing SQLite database, the clean recovery path is to rebuild or run a full feast materialize <start> <end> (rather than feast materialize-incremental, which only processes new intervals) so existing rows are rewritten with true UTC epochs.
Happy to add a short upgrade note in the docs or PR release note if maintainers want to highlight this for non-UTC SQLite deployments.
franciscojavierarceo
left a comment
There was a problem hiding this comment.
the existing-row compatibility concern needs a shipped upgrade path. older non-UTC writers stored shifted integer epochs that the old local-time reader reversed; the new UTC reader reinterprets those same rows, changing TTL decisions immediately after upgrade. the new tests only write with the new adapter. we need to document the required rebuild or full-range rematerialization in the SQLite docs, explain that incremental materialization leaves old rows unchanged, and add a legacy-epoch regression covering the recovery. the original writer timezone cannot safely be inferred from the integer alone.
Add an upgrade note to the SQLite online store reference explaining that event_ts and created_ts are now stored as UTC, that environments which already ran in UTC are unaffected, and that non-UTC environments need to rebuild the SQLite file or run a full feast materialize backfill over the existing data, while feast materialize-incremental never rewrites rows stored before its interval. Add a regression test that seeds a row the way the old local-time adapter wrote it, verifies that the UTC adapters read it back shifted and outside the TTL window, verifies that materialize-incremental leaves it untouched, and verifies that a full materialize backfill restores the true UTC epoch and a PRESENT status. Signed-off-by: PandaAB <104823169+PandaAB@users.noreply.github.com>
Thanks for the review, @franciscojavierarceo. I have pushed an update addressing both points:
|
What this PR does / why we need it:
The SQLite online store converted datetimes through the process local timezone.
adapt_datetime_epochcalleddatetime.timestamp()on the naive UTC datetime thatonline_write_batchnormalized withto_naive_utc(), andconvert_timestampcalleddatetime.fromtimestamp()without a timezone. On any non-UTC host (for example, local development inAmerica/New_YorkorAsia/Shanghaipaired with aUTCcontainer), storedevent_tsandcreated_tsepochs are shifted by the writer's UTC offset, and reading the database from a different timezone returns shifted timestamps that can push fresh rows past TTL (OUTSIDE_MAX_AGE).This PR treats naive datetimes as UTC in
adapt_datetime_epochand returns naive UTC datetimes fromconvert_timestamp, matching the naive-means-UTC contract documented byto_naive_utcandmake_tzaware.Which issue(s) this PR fixes:
None filed. Reproduced locally by writing and reading the same SQLite online store across different process timezones (
UTC,America/New_York, andAsia/Shanghai): raw on-disk epochs were offset by the writer's local UTC offset,online_readreturned shifted timestamps, and TTL checks reported fresh rows asOUTSIDE_MAX_AGE.Checks
git commit -s)Testing Strategy
Added
sdk/python/tests/unit/infra/online_store/test_sqlite_utc_timestamps.pyto test cross-timezone write/read pairs (UTC/UTC,Asia/Shanghai/UTC,UTC/Asia/Shanghai,America/New_York/UTC), verify raw on-disk epochs equal true UTC epochs, and check TTL status via_populate_response_from_feature_data.Misc
Note on compatibility: existing rows previously written on a non-UTC host retain their stored offset epochs and are not automatically migrated by this change.