Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: ActivityWatch watchers always crash after startup #5988

Open
2 tasks done
ondt opened this issue Oct 22, 2024 · 0 comments
Open
2 tasks done

bug: ActivityWatch watchers always crash after startup #5988

ondt opened this issue Oct 22, 2024 · 0 comments
Assignees
Labels
bug triage Issues or feature request that have not been triaged yet

Comments

@ondt
Copy link

ondt commented Oct 22, 2024

Are you following the right branch?

  • My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • I have searched the existing issues

Issue description

Both aw-watcher-afk and aw-watcher-window are crashing on startup:

-- Boot d98014b0da0a4689aa35788c5e380235 --
říj 14 21:51:52 desktop systemd[2894]: Started ActivityWatch watcher 'aw-watcher-window'.
říj 14 21:51:53 desktop aw-watcher-window[2978]: Traceback (most recent call last):
říj 14 21:51:53 desktop aw-watcher-window[2978]:   File "/nix/store/69g5zb7z36cf04lazngghn4qykh2faz7-aw-watcher-window-0.12.2/bin/.aw-watcher-window-wrapped", line 9, in <module>
říj 14 21:51:53 desktop aw-watcher-window[2978]:     sys.exit(main())
říj 14 21:51:53 desktop aw-watcher-window[2978]:              ^^^^^^
říj 14 21:51:53 desktop aw-watcher-window[2978]:   File "/nix/store/69g5zb7z36cf04lazngghn4qykh2faz7-aw-watcher-window-0.12.2/lib/python3.12/site-packages/aw_watcher_window/main.py", line 40, in main
říj 14 21:51:53 desktop aw-watcher-window[2978]:     raise Exception("DISPLAY environment variable not set")
říj 14 21:51:53 desktop aw-watcher-window[2978]: Exception: DISPLAY environment variable not set
říj 14 21:51:53 desktop systemd[2894]: activitywatch-watcher-aw-watcher-window.service: Main process exited, code=exited, status=1/FAILURE
říj 14 21:51:53 desktop systemd[2894]: activitywatch-watcher-aw-watcher-window.service: Failed with result 'exit-code'.

When I start them manually using systemctl --user restart activitywatch-watcher-aw-watcher-afk.service activitywatch-watcher-aw-watcher-window.service or systemctl --user restart activitywatch.target, they crash again when the system is shutting down:

říj 15 16:32:46 desktop systemd[2894]: Started ActivityWatch watcher 'aw-watcher-window'.
říj 15 16:32:46 desktop aw-watcher-window[474433]: 2024-10-15 16:32:46 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
říj 15 16:32:47 desktop aw-watcher-window[474433]: 2024-10-15 16:32:47 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:447)
říj 20 20:01:34 desktop aw-watcher-window[474433]: 2024-10-20 20:01:34 [WARNING]: X server closed connection, exiting  (aw_watcher_window.xlib:52)
říj 20 20:01:34 desktop aw-watcher-window[474433]: 2024-10-20 20:01:34 [ERROR]: Fatal error, stopping  (aw_watcher_window.main:111)
říj 20 20:01:34 desktop aw-watcher-window[474433]: Traceback (most recent call last):
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/hlzfdwqhmglqxx9bdbm6b3g89bpx9qdk-python3.12-xlib-0.33/lib/python3.12/site-packages/Xlib/protocol/display.py", line 583, in send_and_recv
říj 20 20:01:34 desktop aw-watcher-window[474433]:     i = self.socket.send(self.data_send)
říj 20 20:01:34 desktop aw-watcher-window[474433]:         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
říj 20 20:01:34 desktop aw-watcher-window[474433]: BrokenPipeError: [Errno 32] Broken pipe
říj 20 20:01:34 desktop aw-watcher-window[474433]: During handling of the above exception, another exception occurred:
říj 20 20:01:34 desktop aw-watcher-window[474433]: Traceback (most recent call last):
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/69g5zb7z36cf04lazngghn4qykh2faz7-aw-watcher-window-0.12.2/lib/python3.12/site-packages/aw_watcher_window/xlib.py", line 43, in get_current_window
říj 20 20:01:34 desktop aw-watcher-window[474433]:     window_id = _get_current_window_id()
říj 20 20:01:34 desktop aw-watcher-window[474433]:                 ^^^^^^^^^^^^^^^^^^^^^^^^
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/69g5zb7z36cf04lazngghn4qykh2faz7-aw-watcher-window-0.12.2/lib/python3.12/site-packages/aw_watcher_window/xlib.py", line 22, in _get_current_window_id
říj 20 20:01:34 desktop aw-watcher-window[474433]:     window_prop = screen.root.get_full_property(atom, X.AnyPropertyType)
říj 20 20:01:34 desktop aw-watcher-window[474433]:                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/hlzfdwqhmglqxx9bdbm6b3g89bpx9qdk-python3.12-xlib-0.33/lib/python3.12/site-packages/Xlib/xobject/drawable.py", line 472, in get_full_property
říj 20 20:01:34 desktop aw-watcher-window[474433]:     prop = self.get_property(property, property_type, 0, sizehint)
říj 20 20:01:34 desktop aw-watcher-window[474433]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/hlzfdwqhmglqxx9bdbm6b3g89bpx9qdk-python3.12-xlib-0.33/lib/python3.12/site-packages/Xlib/xobject/drawable.py", line 455, in get_property
říj 20 20:01:34 desktop aw-watcher-window[474433]:     r = request.GetProperty(display = self.display,
říj 20 20:01:34 desktop aw-watcher-window[474433]:         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/hlzfdwqhmglqxx9bdbm6b3g89bpx9qdk-python3.12-xlib-0.33/lib/python3.12/site-packages/Xlib/protocol/rq.py", line 1368, in __init__
říj 20 20:01:34 desktop aw-watcher-window[474433]:     self.reply()
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/hlzfdwqhmglqxx9bdbm6b3g89bpx9qdk-python3.12-xlib-0.33/lib/python3.12/site-packages/Xlib/protocol/rq.py", line 1380, in reply
říj 20 20:01:34 desktop aw-watcher-window[474433]:     self._display.send_and_recv(request = self._serial)
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/hlzfdwqhmglqxx9bdbm6b3g89bpx9qdk-python3.12-xlib-0.33/lib/python3.12/site-packages/Xlib/protocol/display.py", line 586, in send_and_recv
říj 20 20:01:34 desktop aw-watcher-window[474433]:     raise self.socket_error
říj 20 20:01:34 desktop aw-watcher-window[474433]: Xlib.error.ConnectionClosedError: Display connection closed by server: [Errno 32] Broken pipe
říj 20 20:01:34 desktop aw-watcher-window[474433]: During handling of the above exception, another exception occurred:
říj 20 20:01:34 desktop aw-watcher-window[474433]: Traceback (most recent call last):
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/69g5zb7z36cf04lazngghn4qykh2faz7-aw-watcher-window-0.12.2/lib/python3.12/site-packages/aw_watcher_window/main.py", line 106, in heartbeat_loop
říj 20 20:01:34 desktop aw-watcher-window[474433]:     current_window = get_current_window(strategy)
říj 20 20:01:34 desktop aw-watcher-window[474433]:                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/69g5zb7z36cf04lazngghn4qykh2faz7-aw-watcher-window-0.12.2/lib/python3.12/site-packages/aw_watcher_window/lib.py", line 59, in get_current_window
říj 20 20:01:34 desktop aw-watcher-window[474433]:     return get_current_window_linux()
říj 20 20:01:34 desktop aw-watcher-window[474433]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/69g5zb7z36cf04lazngghn4qykh2faz7-aw-watcher-window-0.12.2/lib/python3.12/site-packages/aw_watcher_window/lib.py", line 10, in get_current_window_linux
říj 20 20:01:34 desktop aw-watcher-window[474433]:     window = xlib.get_current_window()
říj 20 20:01:34 desktop aw-watcher-window[474433]:              ^^^^^^^^^^^^^^^^^^^^^^^^^
říj 20 20:01:34 desktop aw-watcher-window[474433]:   File "/nix/store/69g5zb7z36cf04lazngghn4qykh2faz7-aw-watcher-window-0.12.2/lib/python3.12/site-packages/aw_watcher_window/xlib.py", line 55, in get_current_window
říj 20 20:01:34 desktop aw-watcher-window[474433]:     raise FatalError()
říj 20 20:01:34 desktop aw-watcher-window[474433]: aw_watcher_window.exceptions.FatalError
říj 20 20:01:34 desktop systemd[2894]: activitywatch-watcher-aw-watcher-window.service: Consumed 15min 27.513s CPU time, 35.1M memory peak, 0B memory swap peak.
-- Boot 07ade846107241ec9f670f1a4d469fdf --

It seems like the watchers are started before Xorg is started, and when shutting down they aren't stopped before Xorg is stopped.

This is my ActivityWatch config:

  services.activitywatch = {
    enable = true;
    package = pkgs.aw-server-rust;
    watchers = {
      aw-watcher-afk.package = pkgs.aw-watcher-afk;
      aw-watcher-window.package = pkgs.aw-watcher-window;
    };
  };

Workaround

The problem can be fixed by adding the following snippet to the home-manager config:

  systemd.user.targets.activitywatch = {
    Unit.After = lib.mkForce [ "graphical-session.target" ];
    Install.WantedBy = lib.mkForce [ "graphical-session.target" ];
  };

Note that this workaround is not ideal because activitywatch.target itself shouldn't really need a GUI. I'm not sure if there is a way to tell whether an arbitrary watcher needs to be started after graphical-session.target or not.

Maintainer CC

@foo-dogsquared

System information

 - system: `"x86_64-linux"`
 - host os: `Linux 6.11.4, NixOS, 24.05 (Uakari), 24.05.20241019.a9b86fc`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.8`
 - channels(root): `""`
 - nixpkgs: `/nix/store/lbqj1cndic4121whnx8xm0jgb1c8x4xx-source`
@ondt ondt added bug triage Issues or feature request that have not been triaged yet labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Issues or feature request that have not been triaged yet
Projects
None yet
Development

No branches or pull requests

4 participants