activitywatch icon indicating copy to clipboard operation
activitywatch copied to clipboard

aw-watcher-window randomly crashes on swift strategy

Open zagrski opened this issue 2 years ago • 12 comments

  • [x] I am on the latest ActivityWatch version.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • OS name and version: macOS Sonoma 14.0
  • ActivityWatch version: 0.12.2

Describe the bug

aw-watcher-window seems to be crashing at random intervals with no logs when run normally with swift strategy.

I tried running the watcher via terminal and different strategy (both jxa and applescript) and both seemed to work with no issues. I was not able, however, to run the watcher with different strategy via the menu bar.

It can easily get annoying when you don't receive a GUI error message on crash and thus have to constantly check whether the watcher is actually still running.

To Reproduce

Not sure how to consistently reproduce this issue. Sometimes the watcher can run for a few hours with no crashes just to crash 3 times in the next 10 minutes.

Expected behavior

aw-watcher-window to work all the time.

Documentation

Logs when the watcher is run via terminal with verbose setting enabled:

/Applications/ActivityWatch.app/Contents/MacOS/aw-watcher-window --strategy swift --verbose
2023-11-02 20:56:05 [DEBUG]: SingleInstance lockfile: /Users/jaqobb/Library/Caches/activitywatch/client_locks/aw-watcher-window-at-127.0.0.1-on-5600  (aw_client.singleinstance:22)
2023-11-02 20:56:05 [DEBUG]: queue path '/Users/jaqobb/Library/Application Support/activitywatch/aw-client/queued/aw-watcher-window.v1.persistqueue'  (aw_client.client:407)
2023-11-02 20:56:05 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
usage: aw-watcher-window [-h] [--host HOST] [--port PORT] [--testing]
                         [--exclude-title] [--verbose] [--poll-time POLL_TIME]
                         [--strategy {jxa,applescript,swift}]
aw-watcher-window: error: unrecognized arguments: -B -S -E -s -c from multiprocessing.resource_tracker import main;main(6)
usage: aw-watcher-window [-h] [--host HOST] [--port PORT] [--testing]
                         [--exclude-title] [--verbose] [--poll-time POLL_TIME]
                         [--strategy {jxa,applescript,swift}]
aw-watcher-window: error: unrecognized arguments: --multiprocessing-fork tracker_fd=7 pipe_handle=9
2023-11-02 20:56:06 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
2023-11-02 20:56:06 [DEBUG]: Starting new HTTP connection (1): 127.0.0.1:5600  (urllib3.connectionpool:228)
2023-11-02 20:56:06 [DEBUG]: http://127.0.0.1:5600 "POST /api/0/buckets/aw-watcher-window_jaqobb-laptop.local HTTP/1.1" 304 0  (urllib3.connectionpool:456)
2023-11-02 20:56:06 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:436)
2023-11-02 20:56:06 [aw-watcher-window-macos] [INFO] Failed to create bucket
main/macos.swift:282: Fatal error: Unexpectedly found nil while unwrapping an Optional value
2023-11-02 20:57:36 [DEBUG]: queue path '/Users/jaqobb/Library/Application Support/activitywatch/aw-client/queued/aw-watcher-window.v1.persistqueue'  (aw_client.client:407)

My guess is that the crash happens because of the error in the second to last line.

Additional context

zagrski avatar Nov 02 '23 20:11 zagrski

Hi there! As you're new to this repo, please make sure you've used an appropriate issue template and searched for duplicates (it helps us focus on actual development!). We'd also like to suggest that you read our contribution guidelines and our code of conduct. Thanks a bunch for opening your first issue! 🙏

github-actions[bot] avatar Nov 02 '23 20:11 github-actions[bot]

Would you mind trying the latest beta to see if the problem still exists there? :)

BelKed avatar Nov 02 '23 21:11 BelKed

Curious if this ever happened before you upgraded to macOS 14 Sonoma? (I have yet to upgrade)

ErikBjare avatar Nov 03 '23 15:11 ErikBjare

Would you mind trying the latest beta to see if the problem still exists there? :)

After upgrading to 0.12.3b12 the problem seems to no longer occur (after more detailed checking, I found that the [macos] guards against missing notification data PR most likely fixed that bug). However, I don't know whether this is just me being overly suspicious but when using IntelliJ (I also have Activity Watcher plugin installed), I have a feeling that some data is not being recorded.

Curious if this ever happened before you upgraded to macOS 14 Sonoma? (I have yet to upgrade)

I'm sorry but I can't really confirm that, as I only started using AW on a daily basis after upgrading to Sonoma.

zagrski avatar Nov 03 '23 16:11 zagrski

Well, I just bumped into something similar. Lost all data since yesterday at ~15:35 (UTC+1h).

No idea what went wrong, but running it from the terminal for now, so I can make sure I get log output if something happens. (output from the underlying swift script is not included in the logs...)

Curiously enough, I had a window watcher running in parallel in testing mode (reporting to testing server), which didn't crash.

Edit 2023-11-16: Turns out I was running v0.12.2b7, which could be the culprit, it might actually be fixed in later betas (explains why the separately running, more recent, aw-watcher-window didn't crash).

ErikBjare avatar Nov 04 '23 17:11 ErikBjare

I have the same issue on macOS 13.5.1 Ventura , will try the beta

theolundqvist avatar Nov 15 '23 08:11 theolundqvist

@theolundqvist Did it happen more than once for you?

ErikBjare avatar Nov 15 '23 09:11 ErikBjare

@theolundqvist Did it happen more than once for you?

Yes quite often, not in the beginning, but now almost every day

theolundqvist avatar Nov 15 '23 09:11 theolundqvist

Wow, sorry about that. I hope you're having luck with the beta.

ErikBjare avatar Nov 15 '23 14:11 ErikBjare

I had another look at the log @jaqobb posted and noticed (not sure how I missed before):

main/macos.swift:282: Fatal error: Unexpectedly found nil while unwrapping an Optional value

However, in the latest version of the macos.swift file, there's no unwrap on line 282, so I checked the commit history and found the commit which fixes it: https://github.com/ActivityWatch/aw-watcher-window/commit/82d9673a8b6e14df06186d94c2984b4580c472f5

So, all betas released after 2023-2-22 should have the fix.

It doesn't explain the crash I had on v0.12.2b7, but that was a one-off that has never happened since.

ErikBjare avatar Nov 16 '23 11:11 ErikBjare

@ErikBjare Ok! I have not had any crashes with the beta so far!

theolundqvist avatar Nov 17 '23 16:11 theolundqvist