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

Gap of Negative Duration could NOT be Fixed - AW Server stuck in loop without exiting #1125

Open
2 tasks done
TheFibonacciEffect opened this issue Jan 7, 2025 · 20 comments
Open
2 tasks done

Comments

@TheFibonacciEffect
Copy link

TheFibonacciEffect commented Jan 7, 2025

  • I am on the latest ActivityWatch version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS name and version: Arch Linux x86_64
  • ActivityWatch version: v0.13.2

Describe the bug

Within one specific week I am getting:

 2025-01-07 06:06:55 [WARNING]: Gap was of negative duration but could be safely merged (-165.163s). This message will only show once per batch.  (aw_transform.flood:46)
 2025-01-07 06:06:55 [WARNING]: Gap was of negative duration and could NOT be safely merged (-330.409s). This warning will only show once per batch.  (aw_transform.flood:52)

the query will run out of time and the banner
AxiosError: timeout of 90000ms exceeded. See dev console (F12) and/or server logs for more info.
is displayed at the top of the webpage. However the activitywatch server will still continue to use 100% of one CPU core until manually stopped.

To Reproduce

I start the server
image
The server is running
image
I can change to the previous week, no problem
image
Note the cpu load on the right, the spike occurs when I change the week, but its okay, because the calculation is finished after some time.
Now if I change to the week before that the CPU load does not decrease
image
At some time a timeout message is displayed and a warning in the logs
image
But even though the request is supposed to time out, the CPU usage stays at 100%
image
Pressing Ctrl C does not do anything
image
But sending SIGTERM works
image
image

Expected behavior

Just seeing the stats of that week

Documentation

Logs:
aw-log-bug.log

Additional context

Maybe related to #239

Copy link

github-actions bot commented Jan 7, 2025

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! 🙏

@TheFibonacciEffect
Copy link
Author

I will keep looking for more issues that are relevant to this issue to see if something fixes this.

@TheFibonacciEffect
Copy link
Author

TheFibonacciEffect commented Jan 7, 2025

In Issue #907 someone also got the same "gap of negative duration could NOT be fixed" message, but then the aw server crashed, mine does not seem to crash. That had to do with some event missing the "title" key.
However in mine there is also a week that can not be viewed. So it propably has to do with some bad event.

@TheFibonacciEffect TheFibonacciEffect changed the title Gap of Negative Duration could NOT be Fixed Gap of Negative Duration could NOT be Fixed - AW Server stuck in loop without exiting Jan 7, 2025
@TheFibonacciEffect
Copy link
Author

I think this is the line where the logger displayes the negative duration: https://github.com/ActivityWatch/aw-core/blob/6a58ec59c16c57933fce7bad4453449168c83ebd/aw_transform/flood.py#L53

@0xbrayo
Copy link
Member

0xbrayo commented Jan 11, 2025

Does this also happen using aw-server-rust?

@TheFibonacciEffect
Copy link
Author

TheFibonacciEffect commented Jan 12, 2025

@0xbrayo I think its the default activity watch server. I will try with the rust one later.

@0xbrayo
Copy link
Member

0xbrayo commented Jan 12, 2025

Please do, I'll try to investigate what might be causing but it's hard without being able to reproduce it.

@TheFibonacciEffect
Copy link
Author

TheFibonacciEffect commented Jan 12, 2025

@0xbrayo As far as I can tell the issue does not occur in aw-server-rust : )
I cloned the repo, built the project, ran it in debugging mode using cargo and tested it by stepping through the last weeks.

@TheFibonacciEffect
Copy link
Author

TheFibonacciEffect commented Jan 12, 2025

Left is the default aw-server, right is the aw-server-rust
image

@0xbrayo
Copy link
Member

0xbrayo commented Jan 12, 2025

Left is the default aw-server, right is the aw-server-rust

Implies that the bug is somehow related to the implementation in the default python server. Check the logs for the rust server and see if there's any issues there about Negative duration

@TheFibonacciEffect
Copy link
Author

TheFibonacciEffect commented Jan 13, 2025

Yes, it is mentioned multiple times in the logs

[2025-01-13 10:53:23][INFO][rocket_cors::_]: Verifying origin: http://127.0.0.1:5666
[2025-01-13 10:53:23][INFO][rocket_cors::_]: Origin has an exact match
[2025-01-13 10:53:23][INFO][rocket::server]: POST /api/0/query/ application/json:
[2025-01-13 10:53:23][INFO][rocket::server::_]: Matched: (query) POST /api/0/query/ application/json
[2025-01-13 10:53:23][WARN][aw_transform::flood]: Gap was of negative duration (-PT1501.606Ss), but could be safely merged. This error will only show once per batch.
[2025-01-13 10:53:24][INFO][rocket::server::_]: Outcome: Success(200 OK)
[2025-01-13 10:53:24][DEBUG][rocket::server]: sending response: Response {
    status: 200,
    version: HTTP/1.1,
    headers: {
        "content-type": "application/json",
        "server": "Rocket",
        "x-frame-options": "SAMEORIGIN",
        "x-content-type-options": "nosniff",
        "permissions-policy": "interest-cohort=()",
        "access-control-allow-origin": "http://127.0.0.1:5666",
        "content-length": "1631",
    },
    body: Body(
        Streaming,
    ),
}
[2025-01-13 10:53:24][INFO][rocket::server::_]: Response succeeded.

however there it seems like everything could be safetly merged.

@TheFibonacciEffect
Copy link
Author

Im migrating to aw-server-rust now, I think that solves the issue for me.

@TheFibonacciEffect
Copy link
Author

So I dont know if I should close the issue with that, or if it is kept open. As far as I understand activity watch wants to switch to the rust server anyways at some point.

@0xbrayo
Copy link
Member

0xbrayo commented Jan 15, 2025 via email

@TheFibonacciEffect
Copy link
Author

TheFibonacciEffect commented Jan 17, 2025

I am somehow still getting the error, despite having now switched to aw-server-rust when making a query on that same week:

[2025-01-17 08:43:48][WARN][aw_transform::flood]: Gap was of negative duration (-PT165.163Ss), but could be safely merged. This error will only show once per batch.
[2025-01-17 08:43:48][WARN][aw_transform::flood]: Gap was of negative duration and could NOT be safely merged (-PT330.409Ss). This warning will only show once per batch.
[2025-01-17 08:43:49][ERROR][panic]: thread 'rocket-worker-thread' panicked at 'called `Result::unwrap()` on an `Err` value: RuntimeError(BacktrackLimitExceeded)': aw-transform/src/classify.rs:55
   0: <unknown>
   1: <unknown>
...

Image

An improvement is that the server does not keep running after crashing.

Maybe it is possible that the rust server used on the 0.13.2-1 version of activity watch is not the newest version and that the aw-server-rust repo contains a fix to this issue that is not checked out here 🤔 . I will investigate further.

EDIT: No the commits that are checked out in these two repos are the same.

@TheFibonacciEffect
Copy link
Author

By the way, is there any way to restart the activitywatch server after it crashed? Running aw-qt & disown -a still seems to close activitywatch when I close the terminal window?

@TheFibonacciEffect
Copy link
Author

TheFibonacciEffect commented Jan 17, 2025

I just double checked, yes, the aw-server-rust when checked out from the github repo, does indeed work without problems.
This also still works when importing my own settings.

@0xbrayo
Copy link
Member

0xbrayo commented Jan 17, 2025

By the way, is there any way to restart the activitywatch server after it crashed? Running aw-qt & disown -a still seems to close activitywatch when I close the terminal window?

I don't use aw-qt much. But since you are on linux you can set up a systemd service to run aw-server-rust with the restart=always option true. Chatgpt or Claude can help you figure it out.

I just double checked, yes, the aw-server-rust when checked out from the github repo, does indeed work without problems.
This also still works when importing my own settings.

The latest version of the aw-server-rust does not have the same issue?

@TheFibonacciEffect
Copy link
Author

I just double checked, yes, the aw-server-rust when checked out from the github repo, does indeed work without problems.
This also still works when importing my own settings.

The latest version of the aw-server-rust does not have the same issue?

It does not have the issue when I start it using cargo from where I cloned the repo, however the issue does occur when I start activitywatch with aw-qt or when it is started automaticially when I log in. I am using the acvititywatch-bin package for arch linux. I will try to build activitywatch from this repo from source and see if that solves it. (possibly only after the exam phase which ends in 2 weeks)

@0xbrayo
Copy link
Member

0xbrayo commented Jan 17, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants