flood, filter_period_intersect and query2 string parsing return wrong results on valid input

Đang mở
#210 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 6 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
22/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, data

Hướng nghiên cứu

Start with aw_transform/flood.py (final normalize pass, around line 158) and aw_transform/filter_period_intersect.py (cursor logic at lines 53-56); the reproductions in the issue give exact inputs to run. Bug 3 is a smaller, self-contained fix in aw_query/query2.py, where the escape check must track whether the preceding backslash is itself escaped. Done means the three reproduction cases return the expected events and strings ending in an escaped backslash parse. The flood fix needs a sweep-line redesign, so this is not a first-timer task as a whole.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

These three wrong results came out of a bug hunt on master (4496e2e). Each was reproduced twice: once by the reviewer and once independently. None of them is covered by an open issue or PR. Fixes for two other findings are open separately: #208 (filter_keyvals_regex on non-string values) and #209 (unclosed list/dict literals).

1. flood drops the tail of an event that contains a nested event with different data

aw_transform/flood.py, final normalize pass, around line 158. The outer event is cut at the nested event's start, and the part after the nested event ends is never restored.

flood([ev(0, 600, url="a.com"), ev(100, 100, url="b.com")])
# observed: a.com [0,100) and b.com [100,200), total 200s
# expected: a.com [200,600) as well, total 600s

You hit this with flood(concat(...)) across buckets, or with one bucket written by two watcher instances. The time gets undercounted rather than deduplicated. A correct fix needs a sweep-line normalize pass. Putting the tail back inside the current loop breaks the sort invariant for later overlapping events.

2. filter_period_intersect loses time when input events overlap each other

aw_transform/filter_period_intersect.py:53-56. Once an event runs past the end of a filter event, the cursor moves on, so a later input event that starts inside that filter period is skipped.

filter_period_intersect([ev(0, 10, title="long"), ev(2, 2, title="short")],
                        [ev(0, 3, status="not-afk"), ev(5, 5, status="not-afk")])
# observed: long [0,3) and long [5,10); "short" is missing (expected short [2,3))

You hit this with custom queries that concat several browser or window buckets and then filter by not-afk.

3. query2 strings cannot end in an escaped backslash

aw_query/query2.py treats a quote as escaped whenever the previous character is \, even when that backslash is itself escaped (\\). The string never closes.

RETURN = "C:\\";   ->  QueryParseException: Failed to parse string

A category rule whose regex ends in a literal backslash (for example a Windows path, serialized the way aw-webui does it) therefore breaks every Activity query on the Python aw-server.

Also observed, lower priority: on the Python server, user-supplied regexes in categorize and filter_keyvals_regex run on backtracking re. A pattern like (.*)*X$ against a 28-character title held the GIL for about 20s. aw-server-rust is not affected.

Lower priority (reproduced once by the reviewer only; not independently re-run)
  • categorize accepts a category name given as a string instead of a list and splits it into characters: "Programming" becomes ['P','r',...], ranked by string length (classify.py:210,282). aw-server-rust rejects this input.
  • simplify_window_titles raises an uncaught KeyError for events without the key (simplify.py:19), which shows up as an HTTP 500 rather than a query error.
  • Deeply nested literals: parse cost is depth × size, about 31s for a 1MB payload at depth 900. 1000 nested [ raise a raw RecursionError, and a 5000-digit integer a raw ValueError.
  • The _compiled_rules_cache and _plan_cache in classify.py limit the number of entries but not their size. 16 large categorize rule sets pinned about 560MB.
  • Event.__eq__ ignores id but __ne__ is inherited from dict, so a == b and a != b can both be True.
  • AW_PROFILE is not sanitized: ../.. moves the data directory outside the activitywatch-* dirs.
Ngôn ngữ chính
Python
Star
65
Fork
74
Merge trung bình
6 ngày 14 giờ
Pull request đã merge (30 ngày)
13

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ActivityWatch/aw-core

Tất cả issue của ActivityWatch/aw-core

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.