fix: prevent sync timestamp corruption with type-safe UnixSecs wrapper (#157)#160
Merged
Conversation
The sync replay path stored HLC wall_ms (milliseconds) directly into created_at/modified_at columns, while local creation stored Unix seconds. The frontend multiplies by 1000 expecting seconds, so synced notes displayed dates like year 56000+. Fix: introduce UnixSecs(i64) newtype that makes this mismatch a compile error. HlcTimestamp::to_unix_secs() is the only conversion path. No From<i64> impl forces callers to use named constructors. serde(transparent) preserves JSON format — no frontend changes needed. Closes #157
This was referenced Apr 24, 2026
careck
added a commit
that referenced
this pull request
Apr 24, 2026
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
Synced notes displayed wildly wrong dates (year 56000+) because the sync replay path stored HLC
wall_ms(milliseconds) in columns that expect Unix seconds. This PR fixes the bug and makes it structurally impossible to recur.apply_incoming_operationinsync.rswrotets.wall_ms as i64(milliseconds) intocreated_at/modified_atcolumns, while local creation wrotechrono::Utc::now().timestamp()(seconds). Frontend doesnew Date(timestamp * 1000).HlcTimestamp::to_unix_secs()UnixSecs(i64)newtype onNote,UserScript, andAttachmentMetatimestamp fields — assigning raw milliseconds is now a type errortest_apply_incoming_create_note_stores_seconds_timestampverified red-greenKey design decisions
From<i64>— forcesUnixSecs::now(),UnixSecs::from_secs(), orts.to_unix_secs()#[serde(transparent)]— JSON unchanged, no frontend impactFiles changed (18)
timestamp.rsUnixSecs+ traitshlc.rsto_unix_secs()methodnote.rs,user_script.rs,attachment.rsi64→UnixSecssync.rsts.wall_ms→ts.to_unix_secs()notes.rs,scripts.rs,hooks.rs,undo.rs,attachments.rs,export.rs,mod.rschrono::Utc::now().timestamp()→UnixSecs::now()tests.rs,scripting/tests.rs,display_helpers.rsUnixSecs::ZERO/from_secs()Test plan
cargo test -p krillnotes-core— 608/608 passcargo check -p krillnotes-desktop— cleanSupersedes #158 and #159. Closes #157.