Skip to content

fix(query): report invalid custom filter regex as query errors - #193

Merged
ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/custom-filter-regex-query-error
Nov 7, 2026
Merged

ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/custom-filter-regex-query-error

Conversation

@TimeToBuildBob

@TimeToBuildBob TimeToBuildBob commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Catch re.error only at q2_filter_keyvals_regex and raise QueryFunctionException with the regex compiler diagnostic. The existing aw-server query route then returns HTTP 400 instead of an internal HTTP 500.

Closes #192.

The low-level transform still raises re.error; matching semantics, category-rule fallback, and event-data TypeError behavior are unchanged. re.error is used rather than the newer re.PatternError spelling to retain Python 3.8 support.

Reproduction

On master c7821899, POST /api/0/query/ with cache disabled and query RETURN = filter_keyvals_regex([], "title", "["); returns HTTP 500 (unterminated character set at position 0). This also happens with populated events.

With this patch the same real Flask route returns HTTP 400:

{"type": "QueryFunctionException", "message": "Invalid regex: unterminated character set at position 0"}

Verification

  • New interpreter regressions observed RED before the production change: 6 malformed-pattern cases failed, 6 controls passed.
  • pytest tests/test_query_filter_regex.py tests/test_query2.py tests/test_transforms.py -q: 130 passed.
  • pytest tests -q: 374 passed, 5 skipped.
  • make typecheck: 37 source files clean.
  • Pinned Ruff 0.15.4 check/format and hook-enabled commit passed.
  • Real offline Flask POST matrix (aw-server 994ea988, synthetic MemoryStorage, cache disabled, no listener or personal history): 12 cases. Three invalid patterns × empty/populated input change 500 → 400, while valid matching/nonmatching/empty-pattern controls remain 200 with identical results. Original filing-time HTTP probe is GREEN against the branch.
  • make test-fast is not a target in this repository; the full small package test suite above was used instead.

Retained HTTP replay and RED/GREEN JSON: /home/bob/data/regex-query-ab07/ on Bob's machine. Source merge and fetched-master interpreter/HTTP replay remain the task's completion gate; this PR does not claim a deployed release.

Hosted runner follow-through

Initial hosted Build run 40767673028 stopped in setup-python before executing tests: Python 3.8 is unavailable for Ubuntu 26.04 (ubuntu-latest). Commit 2066a46 carries the identical Ubuntu 22.04 pin already validated by #187 and #189. Windows/macOS entries and the Python floor are unchanged. Greptile 5/5 covered product commit 0bf8314; the follow-up changes only the Linux runner pin. Final hosted checks are pending.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

The PR converts malformed patterns passed to q2_filter_keyvals_regex into QueryFunctionException, keeping the compiler's error message.

  • Invalid regexes now return clear query errors.

Reviews (2) · Last reviewed commit: "fix(query): report invalid custom filter..." · Reviewed by Greptile

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Checked head 2066a4666d36: five hosted checks pass; the macOS Python 3.8 test is still running. No review findings or unanswered human comments. No additional code change or rerun is needed now; maintainer merge remains required (Bob has Triage access). The fetched-master interpreter/HTTP replay remains gated on merge.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@TimeToBuildBob

TimeToBuildBob commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI code review

Adds a re.error handler to q2_filter_keyvals_regex in aw_query/functions.py that raises QueryFunctionException with the compiler diagnostic and suppresses exception chaining. Adds tests for invalid patterns through the query interpreter, valid matching results, low-level regex exceptions, and event-data TypeError propagation.

Safe to merge — no P0/P1 findings

Confidence 5/5

✅ No findings. The diff looks correct to me on this pass.

Files changed (2) — the diff as I read it
  • aw_query/functions.py — Imports re and wraps filter_keyvals_regex to translate re.error into QueryFunctionException with an "Invalid regex:" message.
  • tests/test_query_filter_regex.py — Adds a MemoryStorage fixture and tests for invalid patterns, valid filtering, unchanged transform exceptions, and event-data TypeError propagation.
Previous review passes
commit score findings engine when
2066a4666d36 5/5 0 subscription 2026-10-28 21:22 UTC

Reviewed 94c0b2e9f5ab · panel: codex:gpt-6.1-sol + claude-code:sonnet · subscription engine · 14s · about this reviewer

Maintainer commands

@TimeToBuildBob review (own line) — fresh review · @TimeToBuildBob fix — a worker acts on the findings. Once per comment; 👀 = received.

Git-Session-Id: 6833e3b2-8ce8-4432-b3fd-05de48afd45d
@TimeToBuildBob
TimeToBuildBob force-pushed the fix/custom-filter-regex-query-error branch from 2066a46 to 94c0b2e Compare November 6, 2026 15:42
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Rebased onto current master 1dcab4cc38cd098026e1db4fd49a51cd3c3290fd and pushed head 94c0b2e9f5ab4128f79f01c1544ebad01573e32b. The redundant runner-only commit dropped automatically: master already carries the identical Ubuntu 22.04 pin. There is now no .github diff; existing dependency/test setup is unchanged. git range-diff confirms the product patch is unchanged. In an isolated per-worktree dependency environment with isolated XDG paths, python -m pytest tests/test_query_filter_regex.py tests/test_query2.py tests/test_transforms.py -q passed 140 tests. Fresh Greptile review requested successfully through the guarded helper for this head. Hosted checks/review are pending; no merge performed.

@ErikBjare
ErikBjare merged commit e919457 into ActivityWatch:master Nov 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid custom filter regex becomes HTTP 500 instead of a query error

2 participants