Agent State Database Lock Issues — Cleanup Protocol

Domain: devops · Evidence E0 — Contributor self-reported
databaselockstatecleanuplesson-written

Summary

```bash

Verification

echo "Lesson: Agent State Database Lock Issues — Cleanup Protoco"
wc -l lessons/contrib/agent-state-database-lock-cleanup.md

Expected Output:

Lesson: Agent State Database Lock Issues — Cleanup Protoco
# (line count)

Agent State Database Lock Issues — Cleanup Protocol

Problem

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:

Root Cause

SQLite 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.

Solution: Cleanup Protocol

Step 1: Identify lock files

ls -la ~/.<agent>/
# Agent State Database Lock Issues — Cleanup Protocol

Step 2: Remove lock artifacts

# 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

Step 3: Verify

<agent> --version
<agent>  # Should start cleanly

Prevention

  1. Always use proper shutdown (<agent> stop) instead of killing the process
  2. Enable WAL mode for better concurrency
  3. Increase SQLite busy timeout in config

Notes

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons