fix(transform): port aw-core's flood() so both servers agree - #748
Conversation
aw-core's flood() was fixed in ActivityWatch/aw-core#143 so that its output never double-counts time (ActivityWatch/activitywatch#1369), but the Rust flood() still let overlapping events with different data through. Port aw-core's algorithm: - a pairwise pass that merges same-data events and splits gaps between differing events at the midpoint, for gaps up to and including pulsetime (was: strictly less than) - a normalization pass in which the later of two overlapping events with different data wins, and zero-duration events are dropped - sort by (timestamp, duration) like aw-core The flood() query function now takes an optional pulsetime in seconds, defaulting to 5 like aw-core. Fixes #746
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@greptileai review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7324b3285b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
The pairwise pass leaves a merged-away event as a zero-duration placeholder at the end of the merged event, so a chain of same-data events (e.g. three adjacent 10 s events) came out of normalization as adjacent pieces. Merge touching same-data events in normalization too, like ActivityWatch/aw-core#165. Also check the pulsetime argument's effect in a query test.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e780b24a67
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@greptileai review |
🤖 AI code reviewThis PR ports aw-core's flood() behavior into the Rust aw-transform crate, adding a normalization pass to eliminate overlapping events, dropping zero-duration events, filling gaps up to and including pulsetime, and adding an optional pulsetime argument to the flood query function. It also updates the flood tests and adds new tests for the new behavior, including randomized no-overlap checks. Safe to merge — no P0/P1 findingsConfidence 5/5 ✅ No findings. The diff looks correct to me on this pass. Files changed (3) — the diff as I read it
Reviewed Maintainer commands
|
Fixes #746.
ActivityWatch/aw-core#143 fixed ActivityWatch/activitywatch#1369 (flood leaving overlapping events, so time was counted twice) in aw-core only. The Rust
flood()still let overlapping events with different data through, and differed from aw-core in a few other ways found by the parity suite in ActivityWatch/activitywatch#1467. This ports aw-core'sflood()so both servers return the same events.Changes
gap <= pulsetime, was<).flood(events, 10)now works in queries. The default stays 5 s. Negative or non-finite values are an error.negative_gap_trim_thres).Item 5 in the issue (adjacent same-data events) was an aw-core bug: aw-core skipped zero gaps and didn't merge them. Rust's result was the intended one, so this keeps it, and ActivityWatch/aw-core#165 fixes aw-core.
One behaviour change worth noting: an event with different data contained in a longer event now truncates the longer one at the contained event's start. The tail of the longer event is dropped, as in aw-core.
test_flood_containing_diffis updated to that.Tests
flood()on the same input.cargo test -p aw-transform -p aw-query,cargo clippy --workspace -- -D warningsandcargo fmt --checkpass locally.Parity suite (ActivityWatch/activitywatch#1467)
Run locally against a release build of this branch:
flood,flood_pulsetime,flood:no_overlap_positive, and 2union_no_overlap_floodedcases). No new failures.floodcases and 10 canonical-query cases XPASS, and noflood/flood_pulsetimexfail is left. The rest (theadjacentscenario and same-data chains) needs both sides.Independent of #744 and #749: no shared code.