aw-server 0.13.2 startup loop on corrupt SQLite DB; .recover restores data

Open
#1,412 3 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python, sqlite
Domain
backend, cli, databases

Research direction

Look at the aw-server startup code, likely in aw_server or aw_core, to see where the SQLite database is opened and how errors are handled. The issue suggests adding a recovery fallback when corruption is detected. You'll need to understand the existing storage backend (Peewee/SQLite) and design a safe recovery flow that preserves the corrupt file and either automatically recovers or shows instructions. Check for related code from issue #271. Testing will involve simulating a corrupt database file and verifying the new behavior.

Written by the indexing model from the issue text.

Description

Environment

  • ActivityWatch / aw-server: 0.13.2
  • macOS 15.7.3 (24G419), arm64
  • Storage backend: Peewee / SQLite

Observed behavior

aw-server repeatedly exited during startup with:

sqlite3.DatabaseError: database disk image is malformed
peewee.DatabaseError: database disk image is malformed

The bundled app's restart action produced the same startup failure. The database file was last modified on July 25, and the first retained log containing this error was July 27. I do not know what originally caused the corruption.

An independent read-only SQLite check reproduced it:

$ sqlite3 -readonly peewee-sqlite.v2.db 'PRAGMA quick_check;'
Error: in prepare, database disk image is malformed (11)

There was no -wal, -journal, or backup file beside the database.

Recovery result

After preserving the original file, the standard SQLite recovery path succeeded:

sqlite3 corrupt.db '.recover' | sqlite3 recovered.db
sqlite3 -readonly recovered.db 'PRAGMA integrity_check;'
# ok

Recovered data:

  • 2 buckets
  • 148,065 events
  • Event range: 2026-01-30 through 2026-07-25
  • 0 invalid event JSON rows
  • 0 orphaned event rows

After replacing the corrupt database with the recovered one, the actual bundled aw-server started successfully. Both /api/0/info and /api/0/buckets/ returned HTTP 200, and the full ActivityWatch app then launched normally.

Suggested improvement

Could aw-server or aw-qt preserve the corrupt file and offer an automatic recovery/backup fallback (or at least show actionable recovery instructions) instead of remaining in a restart loop? This appears related to the older closed issue #271, but reproduces on 0.13.2 and the SQLite .recover path preserved the data successfully.

Dominant language
Python
Stars
19.7k
Forks
1.1k
Avg merge
2d 19h
Merged PRs (30d)
14

Getting set up

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/activitywatch

All issues in ActivityWatch/activitywatch

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.