fix(query): don't modify events that other query variables still hold - #172
Merged
Merged
Conversation
period_union cleared .data on the events it returned, and events that weren't merged with another were the input objects themselves. Queries share event objects between variables (filter_keyvals_regex returns the same objects), so e.g. aw-client's always_active_pattern query not_treat_as_afk = filter_keyvals_regex(events, "app", "Slack"); not_afk = period_union(not_afk, not_treat_as_afk); events = filter_period_intersect(events, not_afk); wiped app/title from the Slack window events in 'events'. aw-server-rust doesn't mutate its inputs. Return new events instead.
…er variables' events Query variables share Event objects (`other = events;`, or a filter that returns the same objects), and categorize, tag and split_url_events set keys in event.data in place. So in aw-webui's multidevice query not_afk = events; events = categorize(events, ...); the Android events in not_afk got $category as well. aw-server-rust has value semantics. The query wrappers now pass copies (a new Event and data dict per event, which is all these transforms modify).
Member
Author
|
@greptileai review |
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. |
|
This was referenced Sep 26, 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.
Found while measuring the query parity suite (ActivityWatch/activitywatch#1467) for the ActivityWatch/activitywatch#1466 changes. Query variables share Event objects, and several transforms modified their input events in place, so one variable's events changed when another was transformed. aw-server-rust has value semantics, so the servers disagreed on the canonical queries.
period_unioncleared.dataon the events it returned, and events it didn't merge were the input objects themselves. aw-client's and aw-webui'salways_active_patternquery doesso Slack/Terminal window events lost
appandtitleand were categorizedUncategorized. It now returns new events.categorize,tag,split_url_eventsset keys inevent.datain place. In aw-webui'smultideviceQuery(not_afk = events; events = categorize(events, ...)), the Android events innot_afkgot$categorytoo. The query wrappers now pass copies: a new Event anddatadict per event, which is all these transforms modify. Theaw_transformfunctions themselves are unchanged.I checked the other query transforms for input mutation (flood, merge, chunk, sort, limit, filters, union_no_overlap, concat, simplify): they don't modify their inputs.
Tests:
test_period_union_does_not_modify_inputs, and a query-level test covering all three transforms plus the always_active pattern on every datastore. Both fail before the fix. 308 passed locally.Parity: on top of the #1466 PR (#173), this fixes 64 more canonical-query cases: aw-client
fullDesktopQuery+always_active/+browserand webuimultidevice(from 451 known failures to 166 with both PRs). The remainingmultidevice-webui-android-mergecases come from aw-server-rust'smerge_events_by_keysreturning HashMap order (ActivityWatch/aw-server-rust#757).