Correctness bugs: heartbeat cache, query cache invalidation, commit rollback state
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
The issue identifies four areas: aw-datastore/src/worker.rs, aw-server/src/android/mod.rs, aw-server/src/endpoints/query.rs, and commit handling in work_loop. Start by reviewing the linked fixes #826, #827, #830, and #831 and the described repro steps. Done means each cache or in-memory state remains consistent after the relevant delete, write, race, or failed commit.
Written by the indexing model from the issue text.
Description
A correctness review of master (at 1d101d4) found the following bugs. Fixing PRs will be linked to the items below as they land.
-
Stale heartbeat cache after deleting events, deleting a bucket, or renaming a bucket. — fix: #826
The datastore worker caches each bucket's last heartbeat (last_heartbeatinaw-datastore/src/worker.rs). It is invalidated onInsertEvents, but not onDeleteEventsById,DeleteBucketorRenameBucket. The next heartbeat with the same data then merges into a row that no longer exists, and fails with:InternalError("replace_last_event matched 0 rows for event_id 1 - cache/DB inconsistency")That heartbeat is lost and the client gets a 500. The heartbeat after that recovers, because the bad cache entry is removed before the error. Repro: send two heartbeats, then either delete the latest event or delete and re-create the bucket, then send another heartbeat with the same data. This is easy to hit by deleting the current event from the web UI while a watcher is running.
-
On Android, JNI writes skip query-cache invalidation. — fix: #831
The query cache is enabled by default on Android too (server_state.query_cache_enabled = server_config.query_cacheinaw-server/src/android/mod.rs). But the JNI functionsheartbeat,createBucket,migrateHostnameand the bucket renames write straight to the datastore. The cache is only invalidated in the HTTP handlers (endpoints/bucket.rs,endpoints/import.rs). So when the usage watcher backfills events for a past day after the web UI has cached that day, the stale result is served until the app restarts. Bucket creates and renames over JNI also leave cachedfind_bucketresults wrong. -
A race in the query endpoint can cache a stale result when a read-only reader is in use. — fix: #827
query()inaw-server/src/endpoints/query.rsflushes pending writes once, at the start of the request (pending_overlapping/force_commit). It readsquery_cache.generation()later, once per period. Suppose a write to a past period arrives mid-request. Itsinvalidate()has already run when a later period reads the generation, so that period's generation includes the write. But the period is evaluated on the reader, which cannot see the write until the writer's batch commits.put()then finds no newer overlapping write and stores the stale result, which stays until another write touches that range. This needs a multi-period request (Year / All time views) running while past events are edited or imported. -
A failed commit leaves the worker's in-memory state out of sync with the database. — fix: #830
Whentx.commit()fails inwork_loop, only the privacy engine is restored. The bucket cache inDatastoreInstanceand thelast_heartbeatcache keep the rolled-back changes:- A bucket whose creation was rolled back is still listed.
- A bucket whose deletion was rolled back disappears.
- Cached heartbeats can point at rows that were rolled back.
The legacy-import path already rebuilds
DatastoreInstanceafter a rollback. Doing the same here, and clearinglast_heartbeat, would fix it. This only happens on real commit failures, such as a full disk.
- Dominant language
- Rust
- Stars
- 322
- Forks
- 105
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 22
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ActivityWatch/aw-server-rust
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ActivityWatch/aw-server-rust#798 · 1 comment ·
Maintainers usually reply within 1 day
-
Allow configuring sync dir in the `aw-sync/config.toml` filePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 58/100
ActivityWatch/aw-server-rust#853 · 1 comment ·
Maintainers usually reply within 1 day
-
aw-sync: rowid upgrade bootstrap does not recover backfills lost under the old timestamp cursorOpen
Difficulty 5/5 Over a week Newbie friendliness 25/100
ActivityWatch/aw-server-rust#793 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
ActivityWatch/aw-server-rust#790 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
ActivityWatch/aw-server-rust#717 · 2 comments ·
Maintainers usually reply within 1 day
All issues in ActivityWatch/aw-server-rust
Similar issues
-
CI/CD ignore-for-release
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
eclipse-ankaios/ankaios#844 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
std: `SliceIndex<str>` missing for `std::ops` ranges, so generic `R: SliceIndex<str>` bounds failOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
symposium-dev/symposium#530 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day