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

Aperta
#210 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
22/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend, data

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Python
Stelle
65
Fork
74
Merge medio
6g 14h
PR unite (30g)
13

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ActivityWatch/aw-core

Tutte le issue di ActivityWatch/aw-core

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.