fix(transform): sort by (timestamp, duration) and add flood idempotency tests - #145
Merged
ErikBjare merged 1 commit intoJul 22, 2026
Conversation
…cy tests Port two improvements from ActivityWatch#105 that weren't included in ActivityWatch#143: 1. Sort key change: sort by (timestamp, duration) instead of just timestamp. When multiple events share the same timestamp, shorter events now sort first. This matches aw-server-rust's sort_by_timestamp behavior and gives deterministic, spec-aligned ordering. 2. Two new tests from ActivityWatch#105: - test_flood_idempotent: verifies repeated flood() calls produce the same result (important correctness property) - test_flood_unsafe_gap: verifies overlapping differing-data events don't double-count time (validates the normalization pass from ActivityWatch#143)
Greptile SummaryThis PR makes flood processing deterministic for events with equal timestamps. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(transform): sort by (timestamp, dura..." | Re-trigger Greptile |
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.
Ports two remaining improvements from #105 that weren't included in #143.
Changes
1. Sort key:
(timestamp, duration)instead of justtimestampWhen multiple events share the same timestamp, shorter events now sort first. This gives a deterministic processing order for same-timestamp inputs and aligns with aw-server-rust's behavior (its
sort_by_timestampprocesses shorter events first when timestamps are equal).2. Two new tests
test_flood_idempotent: verifies that callingflood()repeatedly on its own output returns the same result — an important correctness property. Adapted from fix: refactored flood to better behavior #105.test_flood_unsafe_gap: verifies that overlapping events with differing data don't double-count time (validates the normalization pass added in fix(transform): normalize flood() output to remove overlapping events #143). Adapted from fix: refactored flood to better behavior #105.Both tests pass on the current master (no other code changes needed).
aw-server-rust spec comparison
Per Erik's request, I compared the Python implementation against aw-server-rust's flood.rs. The sort key change above aligns them. One notable remaining divergence:
Positive gap, differing data: aw-server-rust does "meet in the middle" — each event extends by
gap/2. The Python implementation does "longer wins" — the longer event fills the entire gap. The normalization pass from #143 means both implementations produce overlap-free output, but the gap-split point differs. Leaving this for a separate discussion since it's a more significant behaviour change.