Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d56bd65
fix(hermes): use PRAGMA temp_store=MEMORY in SessionDB to fix FK dele…
yanyunl1991 Aug 5, 2026
c1ff4ed
fix(hermes): update image-build-probes hash and test fixtures for sql…
yanyunl1991 Aug 5, 2026
6c31cf5
Merge remote-tracking branch 'origin/main' into fix/hermes-session-de…
yanyunl1991 Aug 5, 2026
4d35fb4
fix(test): add missing sqlite-temp-store fixture to three test suites…
yanyunl1991 Aug 5, 2026
6d3fd37
merge: resolve conflicts with main
github-actions[bot] Aug 5, 2026
5b03565
fix(hermes): add sha256 gate and tighten already-patched check for sq…
yanyunl1991 Aug 5, 2026
5f2d0e0
Merge remote-tracking branch 'origin/fix/hermes-session-delete-sqlite…
yanyunl1991 Aug 5, 2026
48594fd
fix(test): register sqlite temp-store patcher SHA256 ARG as integrity…
yanyunl1991 Aug 5, 2026
a22e3f7
test(hermes): exercise session deletion through host CLI
apurvvkumaria Aug 5, 2026
2fc714e
merge: refresh PR branch from main
apurvvkumaria Aug 5, 2026
f17464f
fix(hermes): reject ambiguous SQLite temp-store patches
cv Aug 5, 2026
9f46b7e
merge(main): refresh PR #8308 after gateway teardown repair
cv Aug 5, 2026
044567e
merge(main): refresh PR #8308 after Shields status repair
cv Aug 5, 2026
a89b9be
docs(hermes): describe SQLite patch states
cv Aug 5, 2026
7494b29
merge: resolve conflicts with main
github-actions[bot] Aug 5, 2026
f8dd26b
merge(main): refresh PR #8308 after Hermes cron restore
cv Aug 5, 2026
169d578
merge: preserve concurrent PR #8308 refresh
cv Aug 5, 2026
e4a19fa
docs(hermes): use controlled product names
cv Aug 5, 2026
7b797fb
merge(main): refresh PR #8308 after llama.cpp runtime
cv Aug 5, 2026
7e85eff
merge(main): refresh PR #8308
apurvvkumaria Aug 5, 2026
64e403b
merge(main): refresh PR #8308
cjagwani Aug 5, 2026
3b633c3
test(hermes): surface config hash replay failures
cjagwani Aug 5, 2026
b41d428
merge: resolve conflicts with main
github-actions[bot] Aug 6, 2026
63b3428
merge(main): refresh Hermes session deletion fix
apurvvkumaria Aug 6, 2026
78e095c
merge(main): refresh Hermes session deletion fix
apurvvkumaria Aug 6, 2026
6f044ef
test(hermes): cover SQLite patcher integrity
apurvvkumaria Aug 6, 2026
3c5bdc4
merge(main): refresh Hermes session deletion fix
apurvvkumaria Aug 6, 2026
13ce1e7
merge(main): refresh Hermes session deletion fix
apurvvkumaria Aug 6, 2026
7e9a8d2
merge(main): refresh Hermes session deletion fix
apurvvkumaria Aug 6, 2026
0178597
merge(main): refresh Hermes session deletion fix
apurvvkumaria Aug 7, 2026
588d7c0
Merge branch 'main' into fix/hermes-session-delete-sqlite-cantopen-8301
cv Aug 7, 2026
3738371
Merge branch 'main' into fix/hermes-session-delete-sqlite-cantopen-8301
cv Aug 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion agents/hermes/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ COPY scripts/gateway-control.sh /usr/local/bin/nemoclaw-gateway-control
COPY scripts/managed-gateway-control.py /usr/local/lib/nemoclaw/managed-gateway-control.py
COPY agents/hermes/validate-env-secret-boundary.py /usr/local/lib/nemoclaw/validate-hermes-env-secret-boundary.py
COPY agents/hermes/patch-session-list-preview.py /usr/local/lib/nemoclaw/patch-hermes-session-list-preview.py
COPY agents/hermes/patch-hermes-sqlite-temp-store.py /usr/local/lib/nemoclaw/patch-hermes-sqlite-temp-store.py
COPY agents/hermes/patch-discord-recovery-permissions.py /usr/local/lib/nemoclaw/patch-hermes-discord-recovery-permissions.py
COPY agents/hermes/patch-profile-policy-defaults.py /usr/local/lib/nemoclaw/patch-hermes-profile-policy-defaults.py
COPY agents/hermes/patch-langfuse-credentials.mts /usr/local/lib/nemoclaw/patch-hermes-langfuse-credentials.mts
Expand Down Expand Up @@ -310,7 +311,7 @@ RUN chmod -R a+rX /opt/nemoclaw-blueprint/
# profile hook, bashrc hook, or root-owned helper mode. Remove it once the
# minimum supported Hermes sandbox base tag guarantees those artifacts and
# test/sandbox-rlimit-hooks.test.ts covers that base.
RUN chmod 755 /usr/local/bin/nemoclaw-start /usr/local/bin/nemoclaw-managed-startup-hold /usr/local/bin/nemoclaw-managed-bootstrap /usr/local/lib/nemoclaw/sandbox-init.sh /usr/local/lib/nemoclaw/validate-hermes-env-secret-boundary.py /usr/local/lib/nemoclaw/patch-hermes-session-list-preview.py /usr/local/lib/nemoclaw/patch-hermes-discord-recovery-permissions.py /usr/local/lib/nemoclaw/patch-hermes-profile-policy-defaults.py /usr/local/lib/nemoclaw/seed-hermes-dashboard-config.py /usr/local/lib/nemoclaw/hermes-runtime-config-guard.py /usr/local/lib/nemoclaw/finalize-tirith-marker.py /usr/local/lib/nemoclaw/hermes-mcp-config-transaction.py \
RUN chmod 755 /usr/local/bin/nemoclaw-start /usr/local/bin/nemoclaw-managed-startup-hold /usr/local/bin/nemoclaw-managed-bootstrap /usr/local/lib/nemoclaw/sandbox-init.sh /usr/local/lib/nemoclaw/validate-hermes-env-secret-boundary.py /usr/local/lib/nemoclaw/patch-hermes-session-list-preview.py /usr/local/lib/nemoclaw/patch-hermes-sqlite-temp-store.py /usr/local/lib/nemoclaw/patch-hermes-discord-recovery-permissions.py /usr/local/lib/nemoclaw/patch-hermes-profile-policy-defaults.py /usr/local/lib/nemoclaw/seed-hermes-dashboard-config.py /usr/local/lib/nemoclaw/hermes-runtime-config-guard.py /usr/local/lib/nemoclaw/finalize-tirith-marker.py /usr/local/lib/nemoclaw/hermes-mcp-config-transaction.py \
&& chown root:root /usr/local/bin/nemoclaw-gateway-control /usr/local/lib/nemoclaw/gateway-supervisor.sh /usr/local/lib/nemoclaw/state-dir-guard.py /usr/local/lib/nemoclaw/managed-gateway-control.py /usr/local/lib/nemoclaw/build-hermes-mcp-digest.py /usr/local/lib/nemoclaw/openshell-child-visible-credentials.v0.0.85.json \
&& chmod 700 /usr/local/bin/nemoclaw-gateway-control \
&& chmod 500 /usr/local/lib/nemoclaw/state-dir-guard.py /usr/local/lib/nemoclaw/managed-gateway-control.py \
Expand Down Expand Up @@ -472,6 +473,20 @@ RUN /usr/bin/python3 -I /usr/local/lib/nemoclaw/patch-hermes-session-list-previe
&& HERMES_HOME="$(mktemp -d)" /opt/hermes/.venv/bin/python -I \
/opt/nemoclaw-hermes-config/image-build-probes.py session-preview

# Hermes v0.19.0 SessionDB does not set PRAGMA temp_store=MEMORY, so SQLite
# falls back to file-based temp storage for FK constraint processing (e.g. the
# ON DELETE CASCADE on session_model_usage -> sessions). The openshell exec
# context used by `nemohermes <sb> sessions delete` restricts the temp-file
# creation syscalls that SQLite's FK engine relies on, causing every
# `DELETE FROM sessions` with FK enforcement to raise
# `sqlite3.OperationalError: unable to open database file` (#8301). Inserting
# PRAGMA temp_store=MEMORY before PRAGMA foreign_keys=ON ensures FK processing
# uses in-memory storage, matching the docker-exec behaviour where this works.
RUN /usr/bin/python3 -I /usr/local/lib/nemoclaw/patch-hermes-sqlite-temp-store.py \
&& grep -q 'PRAGMA temp_store=MEMORY' /opt/hermes/hermes_state.py \
&& HERMES_HOME="$(mktemp -d)" /opt/hermes/.venv/bin/python -I \
/opt/nemoclaw-hermes-config/image-build-probes.py session-delete
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

# Hermes v0.19.0 forces the gateway-created Discord recovery ledger to 0600,
# which prevents sandbox-owned online backup and makes a sandbox-restored
# database unwritable by the gateway. The final layout uses a gateway:sandbox
Expand Down
15 changes: 15 additions & 0 deletions agents/hermes/image-build-probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ def verify_session_preview() -> None:
assert rows[0]["preview"] == "NEMOCLAW_PREVIEW_LATEST", rows


def verify_session_delete() -> None:
from hermes_state import SessionDB

db = SessionDB()
session_id = "nemoclaw-session-delete-smoke"
db.create_session(session_id, "cli")
db.append_message(session_id, "user", "probe message 1")
db.append_message(session_id, "assistant", "probe reply")
deleted = db.delete_session(session_id)
assert deleted, f"delete_session returned {deleted!r}"
rows = db.list_sessions_rich(limit=10)
assert not any(r["id"] == session_id for r in rows), "session still present after delete"


def verify_discord_recovery_source() -> None:
source = Path("/opt/hermes/plugins/platforms/discord/recovery.py").read_text(
encoding="utf-8"
Expand Down Expand Up @@ -401,6 +415,7 @@ def reopen_probe(conn):
"langfuse-credentials": verify_langfuse_credentials,
"neutral-platform-inertness": verify_neutral_platform_inertness,
"profile-policy": verify_profile_policy,
"session-delete": verify_session_delete,
"session-preview": verify_session_preview,
}

Expand Down
80 changes: 80 additions & 0 deletions agents/hermes/patch-hermes-sqlite-temp-store.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Patch SessionDB.__init__ to use in-memory temp store for SQLite FK processing.

Source-of-truth note for this localized Hermes runtime patch:
- Invalid state: Hermes v0.19.0 SessionDB does not set PRAGMA temp_store=MEMORY,
so SQLite falls back to file-based temp storage when processing FK constraints
(e.g. the ON DELETE CASCADE on session_model_usage -> sessions). When
`hermes sessions delete` is invoked via openshell exec — the code path used by
`nemohermes <sb> sessions delete <id>` — the process runs in a restricted
environment where SQLite's temp-file creation syscalls fail with
SQLITE_CANTOPEN, causing every `DELETE FROM sessions` with FK enforcement
enabled to raise `sqlite3.OperationalError: unable to open database file`
(#8301). The same command succeeds when run via `docker exec` because that
context allows the file-based temp store.
- Value being patched: pinned/prebuilt `/opt/hermes/hermes_state.py`
`SessionDB.__init__` connection setup block; specifically, the statement
immediately following `apply_wal_with_fallback()` that enables FK enforcement.
`PRAGMA temp_store=MEMORY` is inserted before `PRAGMA foreign_keys=ON` so the
in-memory store is active before any FK-constrained write.
- Source-fix constraint: NemoClaw layers a sandbox image on top of the
published Hermes runtime; the source fix belongs upstream in Hermes, not in
NemoClaw's TypeScript or wrapper code.
- Regression proof: this patcher verifies the un-patched pattern exists exactly
once (fails closed on source drift); the Dockerfile greps for the inserted
PRAGMA after patching; the image-build `session-delete` probe creates a
SessionDB, inserts a session with messages, and calls `delete_session()` to
confirm no OperationalError is raised.
- Removal condition: delete this patch when the pinned Hermes runtime natively
sets `PRAGMA temp_store=MEMORY` (or equivalent) in `SessionDB.__init__`.
"""

from __future__ import annotations

import argparse
from pathlib import Path

OLD = (
'apply_wal_with_fallback(self._conn, db_label="state.db")\n'
' self._conn.execute("PRAGMA foreign_keys=ON")'
)
NEW = (
'apply_wal_with_fallback(self._conn, db_label="state.db")\n'
' self._conn.execute("PRAGMA temp_store=MEMORY")\n'
' self._conn.execute("PRAGMA foreign_keys=ON")'
)
EXPECTED_OCCURRENCES = 1


def patch_file(path: Path) -> None:
source = path.read_text(encoding="utf-8")
old_count = source.count(OLD)
new_count = source.count('self._conn.execute("PRAGMA temp_store=MEMORY")')
if old_count == 0 and new_count >= EXPECTED_OCCURRENCES:
return
if old_count != EXPECTED_OCCURRENCES:
raise SystemExit(
"ERROR: Hermes SessionDB.__init__ connection setup shape changed; "
f"expected {EXPECTED_OCCURRENCES} unpatched occurrences, found {old_count} "
f"(already patched occurrences: {new_count})"
)
path.write_text(source.replace(OLD, NEW), encoding="utf-8")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved


def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
"path",
nargs="?",
default="/opt/hermes/hermes_state.py",
help="Hermes state module to patch",
)
args = parser.parse_args()
patch_file(Path(args.path))
return 0


if __name__ == "__main__":
raise SystemExit(main())
Loading