fix(macos): fall back to jxa when exclude_title/exclude_titles configured#120
Conversation
The swift strategy uses a native binary subprocess that sends heartbeats directly to the AW server, bypassing all Python filtering. When a user sets exclude_title=true or exclude_titles=[...] in the config, the swift strategy silently ignores these settings. Fix: detect title exclusion config before starting, and fall back to the jxa strategy with a warning message. The jxa strategy runs through Python's heartbeat_loop which properly applies exclude_title filtering. Fixes ActivityWatch/activitywatch#1141 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 2a4b330 in 8 seconds. Click for details.
- Reviewed
24lines of code in1files - Skipped
0files when reviewing. - Skipped posting
0draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
Workflow ID: wflow_zBqyCHtf2dFKw3cB
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Greptile SummaryThis PR fixes a long-standing macOS-only bug where Key changes:
Finding:
Confidence Score: 4/5
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[main starts] --> B{sys.platform == darwin<br/>and strategy == swift?}
B -- No --> E[heartbeat_loop<br/>with current strategy]
B -- Yes --> C{exclude_title or<br/>exclude_titles set?}
C -- No --> D[spawn Swift binary<br/>subprocess.Popen<br/>bypasses Python filtering]
C -- Yes --> F[log WARNING:<br/>falling back to jxa]
F --> G[args.strategy = jxa]
G --> E
D --> H[p.wait — Swift binary<br/>sends heartbeats directly<br/>to AW server]
E --> I[Python filtering applied<br/>exclude_title / exclude_titles<br/>work correctly]
Last reviewed commit: 2a4b330 |
| if ( | ||
| sys.platform == "darwin" | ||
| and args.strategy == "swift" | ||
| and (args.exclude_title or args.exclude_titles) | ||
| ): |
There was a problem hiding this comment.
The fallback condition at line 80 checks args.exclude_titles with a plain truthiness test, but the actual filtering at lines 119–120 excludes None entries with if title is not None. This means if a user's TOML config contains exclude_titles = [null] (or produces a list of only None values), the fallback will trigger unnecessarily — the list evaluates as truthy even though no actual patterns will be active after filtering.
To align the fallback guard with the actual runtime behavior in heartbeat_loop, filter out None entries before testing truthiness:
| if ( | |
| sys.platform == "darwin" | |
| and args.strategy == "swift" | |
| and (args.exclude_title or args.exclude_titles) | |
| ): | |
| if ( | |
| sys.platform == "darwin" | |
| and args.strategy == "swift" | |
| and (args.exclude_title or any(t is not None for t in args.exclude_titles)) | |
| ): |
|
Please create a follow-up issue to actually fix this for the swift-part of the watcher (which is the more stable default). |
|
Created #121 as follow-up for native Swift exclude_title support, per your request. |
Problem
On macOS, the default strategy is
swift, which spawns a native binary subprocess that sends heartbeats directly to the AW server. This subprocess bypasses all Python filtering, soexclude_titleandexclude_titlessettings are silently ignored.Reported in: ActivityWatch/activitywatch#1141
Root Cause
In
main.py:The Swift binary accepts only positional args (server address, bucket ID, hostname, client name), with no support for exclusion flags.
Fix
Before spawning the Swift binary, check if title exclusion is configured. If so, log a warning and fall back to the
jxastrategy, which runs throughheartbeat_loopand properly applies the filtering.This is a minimal, safe fix — no Swift code changes required. Users who rely on
exclude_titleget working behavior with a clear log message. Users who don't configure exclusions continue using swift unchanged.Testing
ast.parseAlternative Considered
Adding native
--exclude-titlesupport to the Swift binary — more work, deferred.Important
Add fallback to
jxastrategy inmain.pyfor macOS whenexclude_titleorexclude_titlesis configured, bypassing unsupportedswiftstrategy.main.py, added a check to fall back tojxastrategy ifexclude_titleorexclude_titlesis configured on macOS, instead of usingswiftstrategy.jxastrategy due to unsupported exclusions inswift.ast.parsefor syntax correctness.This description was created by
for 2a4b330. You can customize this summary. It will automatically update as commits are pushed.