Conversation
merge_events_by_keys returned HashMap::into_values(), whose order differs between runs. Order-sensitive transforms downstream inherit that: in aw-webui's multidevice query, Android events are merged by app before union_no_overlap, so the result changed from run to run (the query parity suite in ActivityWatch/activitywatch#1467 sees a different answer on each run). Keep the groups in the order their first event appears, as aw-core does. Also fix the doc comment: events missing a key are dropped (Example 1 listed one in the output), and describe the kept payload.
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. |
|
| /// the result is deterministic (order-sensitive transforms such as | ||
| /// union_no_overlap depend on it). |
There was a problem hiding this comment.
First-seen order is not chronological
The reference to union_no_overlap suggests that deterministic first-seen order is enough for that transform. If the input events are not chronological, the merged groups will not be chronological either. Passing them directly to union_no_overlap, which processes each input in timestamp order, can produce incorrectly ordered coverage. Please clarify that callers must sort when the union needs chronological input.
| /// the result is deterministic (order-sensitive transforms such as | |
| /// union_no_overlap depend on it). | |
| /// the result is deterministic. This is not necessarily timestamp order; sort | |
| /// by timestamp before passing these events to union_no_overlap. |
Knowledge Base Used: Event transformation operators
There was a problem hiding this comment.
Agreed, fixed in e47a055: the doc now says first-seen order is deterministic but not necessarily timestamp order, and that callers must sort by timestamp before union_no_overlap (which expects chronological input). Behaviour unchanged: first-seen order matches Python's merge_events_by_keys.
🤖 AI code reviewThe PR changes merge_events_by_keys in aw-transform/src/merge.rs to return merged events in first-seen order by using a HashMap<String, usize> index into a Vec instead of collecting HashMap values. It also updates the doc comment to clarify that events missing keys are dropped and that output order is first-seen, not timestamp order. A new test merge_keeps_first_seen_order verifies the ordering and duration merging. Safe to merge — no P0/P1 findingsConfidence 5/5 ✅ No thread-worthy findings. Advisory notes follow; they are retained without opening review threads. 1 advisory finding (summary-only, not scored)These P2 guard, heuristic, trade-off, or documentation claims are retained for judgment without opening review threads.
This is a How this was verified: static preflight: fix-commit + touched-files scan (rule 7) Files changed (1) — the diff as I read it
Previous review passes
Reviewed Maintainer commands
|
Addresses review: callers must sort by timestamp before union_no_overlap.
merge_events_by_keysreturnedHashMap::into_values(), so the order of the merged events changed from run to run. Order-sensitive transforms downstream inherit that. In aw-webui's multidevice query (ActivityWatch/aw-webui#1004), Android events are merged by app beforeunion_no_overlap. The merged events overlap, so the union's result depended on the HashMap order. The query parity suite (ActivityWatch/activitywatch#1467) showed it: three runs of the same query gave three different aw-server-rust results.The groups now come out in the order their first event appears in the input, which is what aw-core (Python) does. This uses a
HashMap<String, usize>index into aVec, so there's no new dependency. Grouping, the kept first payload and the summed durations are unchanged.Also fixes the doc comment: events missing a key are dropped, but Example 1 listed one (
{ "b": 1 }) in the output (noted in ActivityWatch/activitywatch#1466).Test:
merge_keeps_first_seen_order(10 groups plus repeats). It fails on the old code and passes now.cargo test -p aw-transform merge: 7 passed.