```bash
echo "Lesson: Agent State Database Lock Issues — Cleanup Protoco"
wc -l lessons/contrib/agent-state-database-lock-cleanup.mdExpected Output:
Lesson: Agent State Database Lock Issues — Cleanup Protoco
# (line count)Agent framework uses a SQLite-based state database to persist conversation context, session metadata, and operational state. Under certain conditions (forced termination, WSL snapshot restore, concurrent multi-session), the database can become locked or corrupted.
Symptoms:
Error: database is lockedOperationalError: unable to open database fileSQLite locking mechanism does not handle forced termination well. When the agent process is killed (SIGKILL, WSL shutdown, OOM), in-progress write transactions leave the database in a locked state.
ls -la ~/.<agent>/
# Agent State Database Lock Issues — Cleanup Protocol# Stop the agent first
<agent> stop
# Remove journal and WAL files
rm -f ~/.<agent>/state.db-journal
rm -f ~/.<agent>/state.db-wal
rm -f ~/.<agent>/state.db-shm
# Optional: reset the database (loses session history)
rm -f ~/.<agent>/state.db<agent> --version
<agent> # Should start cleanly<agent> stop) instead of killing the process--restart=always may hit this on repeated crash loops