Skip to content

fix(state): reconnect self-heal when state.db is replaced under a live connection - #84885

Merged
teknium1 merged 2 commits into
mainfrom
fix/state-hardening-remainder
Aug 13, 2026
Merged

fix(state): reconnect self-heal when state.db is replaced under a live connection#84885
teknium1 merged 2 commits into
mainfrom
fix/state-hardening-remainder

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

state.db writes now survive the backing file being replaced under a live connection: a bounded one-shot reconnect self-heal fires on the file is not a database error class (previously a permanent wedge until process restart), and transient EIO during journal-mode probing is retried 4× instead of pushing callers onto the fail-closed unknown-mode branch.

Salvaged remainder of #82280 by @shali10 (authorship preserved on the salvaged hunks). The rest of that rollup is deliberately NOT carried:

  • Superseded: its checkpoint-strategy changes (by the PASSIVE-checkpoints PR) and its repair-serialization changes (by the cross-process repair lock PR)
  • Not carried (wrong direction): the sidecar .write.lock flock around every write transaction — SQLite's BEGIN IMMEDIATE + busy handling + the existing jittered patience loop already serialize cross-process writers; a blocking no-timeout flock held across whole transactions defeats the patience/deadline semantics and adds a stale-lock surface. Also not carried: require_wal=True (would brick NFS/SMB installs that deliberately run degraded), the FK self-heal that silently resurrects deleted sessions, and per-site NUL guards main already fixed at the choke point.

Changes

  • hermes_state.py: _is_not_a_database_error() helper; _notadb_reconnect_attempted one-shot flag + reconnect branch in _execute_write + _reconnect_after_notadb() (mirrors _connect_and_init, keeps require_wal default so NFS installs keep working); _on_disk_journal_mode transient-EIO retry (4 attempts, 50ms, None-on-final-failure preserved)
  • New tests/test_state_db_notadb_selfheal.py (9 tests: helper matching, healthy-file self-heal E2E, one-shot guard, failed-reconnect propagation, EIO retry bounded/clears/fails-fast)

Validation

Result
test_state_db_notadb_selfheal.py 9/9
+ wal_fallback + checkpoint_strategy neighbors 36/36
test_hermes_state.py 219 passed, 1 pre-existing failure (identical on clean origin/main)

Infographic

self-heal-reconnect

https://files.catbox.moe/lellbv.png

zhouou6 and others added 2 commits August 12, 2026 16:22
…try transient EIO on journal-mode probe

Salvaged remainder of PR #82280 (state.db hardening rollup):

- Runtime connection corruption: a sibling process replacing/truncating
  the backing file breaks the live write connection — every subsequent
  write raises 'file is not a database' and the gateway wedges
  permanently (messages pile up in memory). Add a bounded one-shot
  reconnect on the write path: close the broken connection, reopen the
  DB file (re-running WAL activation + schema reconciliation), retry
  the failed write once.
- _on_disk_journal_mode: retry transient 'disk i/o error' (virtualized
  block devices) a few times before returning None, so a one-shot EIO
  doesn't push callers onto the fail-closed unknown-mode branch.

The rollup's write-lock machinery, checkpoint-strategy changes, and
repair serialization are intentionally NOT included — superseded by
PRs #84277 and #69609, or wrong-direction per the POSIX
lock-cancellation findings (#71724 lineage).
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 9dcb6e8 — chore: AUTHOR_MAP for zhouou6@users.noreply.github.com → sha

⚠️ Warnings

CI timings · View report · View job

Wall time 8m4s vs 5m13s (+54.6%). 15 job(s) slower, 8 faster, 1 unchanged.

  • Python tests / Run tests slice 5/12: +125.0s
  • Python tests / Run tests slice 10/12: +119.0s
  • Python tests / Run tests slice 12/12: +114.0s
  • Python tests / Run tests slice 4/12: +110.0s
  • Python tests / Run tests slice 9/12: +95.0s

OSV vulnerability scan · View job

3 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 12, 2026
@teknium1
teknium1 merged commit 7d0b5a3 into main Aug 13, 2026
49 checks passed
@teknium1
teknium1 deleted the fix/state-hardening-remainder branch August 13, 2026 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants