Skip to content

fix: add "disk i/o error" to _WAL_INCOMPAT_MARKERS so stale-SHM/EIO after unclean shutdown falls back to DELETE journal mode #46797

Open

Description

@risers-chevron

fix_hermes_state.patch

Bug Description

After an unclean host shutdown (power loss, OOM kill, forced Docker stop), macOS gRPC-FUSE can leave a stale .db-shm shared-memory file on disk. When the container restarts and apply_wal_with_fallback() in hermes_state.py tries to open the kanban DB in WAL mode, SQLite raises:

sqlite3.OperationalError: disk i/o error

apply_wal_with_fallback checks the error message against _WAL_INCOMPAT_MARKERS to decide whether to fall back to DELETE journal mode. "disk i/o error" is not in the markers list, so the function re-raises instead of falling back. The dispatcher's 60-second retry loop catches and swallows the exception — the DB is retried every tick with the same stale-SHM state and the same EIO result.

Impact: Dispatcher silently dead after every unclean shutdown until .db-shm is manually removed. All kanban tasks stuck in ready state; no workers spawn. No visible alert.

Observed incident: 75-minute outage after host crash (omlx OOM + forced Docker stop). All tasks stalled. Recovery required manual removal of stale .db-shm file.

Steps to Reproduce

  1. macOS host, Docker Desktop with virtiofs or gRPC-FUSE
  2. Start Hermes with WAL-mode kanban DB
  3. Force-kill the container: docker kill --signal SIGKILL hermes (or host power-loss / OOM kill)
  4. Restart container — the .db-shm file remains on disk from the crashed session
  5. apply_wal_with_fallback() raises sqlite3.OperationalError: disk i/o error every 60s
  6. Dispatcher never starts; all ready tasks remain unprocessed indefinitely

Expected Behavior

EIO on a WAL open should trigger the fallback to DELETE journal mode, allowing the dispatcher to start normally on the next tick without manual intervention. The stale .db-shm should be bypassed (SQLite in DELETE mode doesn't use SHM).

Actual Behavior

apply_wal_with_fallback() raises sqlite3.OperationalError: disk i/o error, which is not in _WAL_INCOMPAT_MARKERS. The function re-raises instead of falling back to DELETE mode. The 60-second dispatcher tick loop catches and swallows the exception, retrying indefinitely. Dispatcher never starts; all kanban tasks stay in ready state with no workers spawning. No Telegram alert fired (LLM-backed health-check cron saw empty results and reported "ok").

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

No response

Debug Report

version:          0.16.0 (2026.6.5) [a118b94a]
os:               Linux 6.12.76-linuxkit aarch64
python:           3.13.5
profile:          local-admin
gateway:          running (s6 (container supervisor), pid 2050)
platforms:        telegram
cron_jobs:        8 active / 13 total
skills:           48
config_overrides:
  agent.max_turns: 150
  agent.gateway_timeout: 3600
Note: gateway deployment in Docker container; hermes debug share --local used instead of upload.

Operating System

macOS host + Docker Desktop (gRPC-FUSE/virtiofs); container: Linux 6.12.76-linuxkit aarch64

Python Version

3.13.5

Hermes Version

0.16.0 (2026.6.5) [a118b94]

Additional Logs / Traceback (optional)

Repeated in gateway log every ~60s after restart:
sqlite3.OperationalError: disk i/o error

Stale file on host filesystem after crash:
.hermes/kanban.db-shm  (present, non-zero size, from crashed session)

Manual fix that restored dispatcher: rm .hermes/kanban.db-shm; container restart

Root Cause Analysis (optional)

In hermes_state.py, apply_wal_with_fallback() catches sqlite3.OperationalError and checks the message against _WAL_INCOMPAT_MARKERS. If the message matches, it falls back to DELETE journal mode. If not, it re-raises.

The current _WAL_INCOMPAT_MARKERS includes "locking protocol" and "not authorized" but not "disk i/o error". On macOS Docker Desktop with gRPC-FUSE or virtiofs, a forced shutdown leaves a stale .db-shm file. On restart, any WAL pragma raises EIO (disk i/o error) because the SHM file exists but belongs to a dead process. Since EIO is not in the markers, the fallback never triggers.

Safety of the fix: EIO on a fresh WAL open means no live process holds a valid SHM. It is safe to force-downgrade to DELETE mode. The patch adds "disk i/o error" to _WAL_INCOMPAT_MARKERS AND introduces _WAL_FORCE_DELETE_MARKERS — a separate tuple for cases where we bypass the on-disk WAL header guard (normally we refuse to downgrade a WAL DB if another process set WAL). For EIO, that guard is overridden because the SHM is physically inaccessible.

File: hermes_state.py, around lines 128 (_WAL_INCOMPAT_MARKERS) and 280 (apply_wal_with_fallback).

Proposed Fix (optional)

--- a/hermes_state.py
+++ b/hermes_state.py
@@ -128,6 +128,16 @@
 _WAL_INCOMPAT_MARKERS = (
     "locking protocol",       # SQLITE_PROTOCOL on NFS/SMB
     "not authorized",         # Some FUSE mounts block WAL pragma outright
+    "disk i/o error",         # EIO from gRPC-FUSE/VirtioFS when SHM is stale after unclean shutdown
+)
+
+# Markers for which we force-fallback to DELETE even when the on-disk DB
+# header already says WAL.  Normally we refuse to downgrade a WAL database
+# (another process may be using WAL mode).  But EIO on the SHM file means
+# WAL is physically unusable regardless of the header — no live process can
+# be holding a valid SHM, so switching to DELETE is safe.
+_WAL_FORCE_DELETE_MARKERS = (
+    "disk i/o error",
 )
 
 # Last SessionDB() init error, per-process.  Surfaced in /resume and
@@ -270,10 +280,16 @@
         if not any(marker in msg for marker in _WAL_INCOMPAT_MARKERS):
             # Unrelated OperationalError — don't silently swallow.
             raise
-        # Don't downgrade if another process already set WAL on disk.
-        existing = _on_disk_journal_mode(conn)
-        if existing == "wal":
-            raise
+        # For EIO (stale SHM after crash) we force DELETE even if the on-disk
+        # header says WAL — the SHM is inaccessible so WAL cannot be used, and
+        # no live process holds a valid SHM open.  For other markers
+        # (locking-protocol, not-authorized) we keep the conservative guard:
+        # don't downgrade if another process already set WAL on disk.
+        force_delete = any(marker in msg for marker in _WAL_FORCE_DELETE_MARKERS)
+        if not force_delete:
+            existing = _on_disk_journal_mode(conn)
+            if existing == "wal":
+                raise
         _log_wal_fallback_once(db_label, exc)
         conn.execute("PRAGMA journal_mode=DELETE")
         return "delete"

Patch file: fix_hermes_state.patch — 40 lines, 2 hunks, -p0 (no path prefix stripping). Verified: patch --dry-run -p0 applies cleanly to upstream v2026.6.12.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Activity

  1. added
    type/bugSomething isn't working
    comp/cronCron scheduler and job management
    P2Medium — degraded but workaround exists
    on Jun 15, 2026
  2. alt-glitch commented on Jun 15, 2026

    @alt-glitch

    Related: #31014 and #31294 — both CLOSED PRs that deliberately removed "disk i/o error" from _WAL_INCOMPAT_MARKERS, citing real B-tree corruption (161/166 task_links records destroyed) when a transient EIO triggered a silent WAL->DELETE downgrade producing mixed-mode corruption. This proposal re-adds the same EIO marker, which contradicts that prior direction. It does differ in that it gates the downgrade behind a separate _WAL_FORCE_DELETE_MARKERS and overrides the on-disk WAL-header guard only for stale-SHM EIO (arguing no live process holds a valid SHM). Maintainer review needed to confirm this narrower override does not reintroduce the #31014/#31294 corruption path. Also related: #30816 and #30846 (other apply_wal_with_fallback EIO/filesystem-incompat reports).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/install-updateInstaller, updater, packaging, wheels, doctorcomp/cronCron scheduler and job managementtype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions