agentleFS
srinitudesrinitude/hermes-toolbox/skills/autonomous-ai-agents/hermes-state-db-wal/SKILL.md

hermes-state-db-wal

Skill1 starsChanged 5 months agoMITView on GitHub

Use when diagnosing Hermes state.db WAL advisories.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    after hermes doctor --fix, the user asks whether the WAL shrank

    line 21
  2. Very specific:

    Do not treat a large physical WAL alone as corruption or as a failed plan or policy validation.

    line 24
  3. Very specific:

    all clients closed cleanly so the last close can remove -wal and -shm, or

    line 73
  4. Very specific:

    Never delete state.db-wal while any Hermes process has the DB open.

    line 76
  5. Distinctive:

    Do not issue checkpoint PRAGMAs while explaining size unless the user asked for cleanup.

    line 80
  6. Distinctive:

    Verify sizes and a quick integrity check before restarting Hermes.

    line 111
  7. Distinctive:

    Do not invent “delete the wal file” as the default fix.

    line 112

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Hermes state.db WAL diagnosis

Use when:

  • hermes doctor warns about a large state.db-wal (often >50 MiB)
  • the user asks what WAL is or why doctor flagged session storage
  • after hermes doctor --fix, the user asks whether the WAL shrank
  • session search or multi-process Hermes use may be holding the session DB open

Do not treat a large physical WAL alone as corruption or as a failed plan or policy validation. Session-store maintenance is separate from SOUL, AGENTS, and workspace-policy correctness unless state.db integrity or lock errors block work.

Core model

Hermes keeps the canonical session store at $HERMES_HOME/state.db (default ~/.hermes/state.db) with SQLite Write-Ahead Logging:

PathRole
state.dbMain DB (sessions, FTS, messages)
state.db-walCommitted changes not yet fully absorbed or still allocated for reuse
state.db-shmShared-memory WAL index and locks (not the primary content)

Writers append to the WAL. Readers can proceed concurrently. A checkpoint copies eligible WAL pages into state.db. After reset or reuse, the physical -wal file often stays at its high-water size even when little content is still active.

Upstream: https://sqlite.org/wal.html

Doctor thresholds (physical size only)

Hermes Doctor checks the on-disk byte size of state.db-wal, not active frames:

  • informational above ~10 MiB
  • warning above ~50 MiB

Source of truth in a git install: hermes_cli/doctor.py (WAL size check near the session-store health section). Re-open that file if numbers drift.

Pitfall: Doctor can keep warning while logical active content is only a few MiB.

What hermes doctor --fix does

Doctor fix runs approximately:

PRAGMA wal_checkpoint(PASSIVE);

PASSIVE:

  • copies frames that can be checkpointed without waiting hard for every reader or writer
  • does not truncate the allocated WAL file to zero
  • can leave physical size unchanged while reducing active frames

So after --fix:

  1. Measure physical size again.
  2. Measure active frames from the SHM index (below).
  3. Report both. Do not claim disk was reclaimed if only mxFrame dropped.

To shrink the physical file, SQLite needs either:

  • all clients closed cleanly so the last close can remove -wal and -shm, or
  • a controlled TRUNCATE (or RESTART + truncate path) with no active multi-process use

Never delete state.db-wal while any Hermes process has the DB open. Committed data may still depend on it.

Safe read-only inspection (preferred first)

Do not issue checkpoint PRAGMAs while explaining size unless the user asked for cleanup.

  1. Confirm open clients: lsof $HERMES_HOME/state.db $HERMES_HOME/state.db-wal $HERMES_HOME/state.db-shm
  2. Record physical sizes of state.db, state.db-wal, state.db-shm
  3. Parse the WAL header for page size and frame capacity (see references/wal-probe.md)
  4. Parse the SHM header for mxFrame and nBackfill (native endian on the host)
  5. Active logical size ≈ 32 + mxFrame * (page_size + 24) when page_size is 4096 (frame header is 24 bytes)
  6. Compare active MiB to physical MiB; if active ≪ physical, the advisory is mostly high-water allocation

Hermes session code sets journal_mode=WAL with macOS durability helpers; it does not custom-set wal_autocheckpoint on state.db in normal setup. SQLite’s default auto-checkpoint is 1000 pages. Confirm in hermes_state.py (apply_wal_with_fallback) if behavior changes.

Urgency rubric

Low urgency when:

  • SHM headers consistent (isInit, matching dual header copies)
  • integrity and doctor schema checks pass
  • Hermes still reads and writes sessions
  • active frames are modest relative to allocation

Escalate when:

  • active frames stay large and keep growing
  • database is locked, malformed schema, or I/O errors appear
  • disk is constrained and physical WAL keeps climbing after real load

Controlled reclaim (only when user wants disk back)

  1. Tell the user every Hermes surface must stop: CLI/TUI, desktop, gateway, dashboard, other profiles using the same $HERMES_HOME if shared incorrectly.
  2. Back up state.db (and preferably the trio of db/wal/shm if present).
  3. With no other clients, run a TRUNCATE-style checkpoint under SQLite, or allow a clean last-close.
  4. Verify sizes and a quick integrity check before restarting Hermes.
  5. Do not invent “delete the wal file” as the default fix.

Response shape for users

Lead with the answer (shrank or not), then a small before/after table: physical size, active frames, estimated active MiB. Separate “logical checkpoint progress” from “disk reclaimed.” Keep WAL mechanics short unless the user asked for a full lesson.

References

  • references/wal-probe.md — header fields, probe snippets, PASSIVE vs TRUNCATE

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.