NotifyWorker treats a failed category query as zero time and reports success

Open Beginner friendly
#431 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Start with parseCategorySeconds in workers/NotifyWorker.kt:203-229 and the failing NotifyWorkerExecutionTest described in the issue. Check how the function handles the androidQuery response when it contains an error object, then run the test with {"error":"x"} as the fake backend response. Done means the query failure surfaces so the worker returns Result.retry() instead of reporting success.

Written by the indexing model from the issue text.

Description

bug

When the native query fails, NotifyWorker treats the day as zero time and returns Result.success(). Category alerts for that run are skipped and nothing records the failure.

parseCategorySeconds (workers/NotifyWorker.kt:203-229) passes the androidQuery result to JSONArray(...). On a query failure the native side returns {"error": "…"} instead (aw-server-rust aw-server/src/android/mod.rs, create_error_object). This happens, for example, when the aw-watcher-android bucket is missing, when a category regex doesn't compile, or when the datastore errors. The exception is logged and swallowed, and the function returns {null: 0.0}. No threshold can be crossed, so the worker reports success instead of retry().

Failing test (NotifyWorkerExecutionTest, using its fake backend): make androidQuery return {"error":"x"} and expect Result.retry(). Today the result is Result.success(). At the unit level:

@Test
fun queryErrorObjectIsNotZeroSeconds() {
    assertThrows(Exception::class.java) { parseCategorySeconds("""{"error":"x"}""") }
}

It fails today because the function returns {null=0.0}.

Fix direction: detect the error object and surface it as a failure, so the existing retry/backoff path runs.

Same parse pattern as the widget issue #430; filed separately because the symptom and fix site differ.

Priority: medium (alerts silently skipped). This repo only has a priority: high label, so no priority label is set.

fingerprint: workers/NotifyWorker.kt — androidQuery error object counted as 0 seconds, success instead of retry

Found by code review on master 3b820d61. I verified the trigger path against aw-server-rust 67432e66. I have not run it on a device.

Dominant language
Kotlin
Stars
291
Forks
73
Avg merge
4d 5h
Merged PRs (30d)
27

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ActivityWatch/aw-android

All issues in ActivityWatch/aw-android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.