Compare commits

...

3 Commits

Author SHA1 Message Date
Hermes Agent
929e3da00f fix: expand tilde in get_hermes_home() and get_optional_skills_dir()
Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 1m0s
Resolves #478. HERMES_HOME=~/... was returned as a literal path with
~ instead of expanding to the user's home directory. Same issue with
HERMES_OPTIONAL_SKILLS.

Fixes:
- get_hermes_home(): Path(...).expanduser() on the env var value
- get_optional_skills_dir(): Path(override).expanduser()
- Updated docstring to document tilde expansion

This affects any caller that sets HERMES_HOME=~/custom-path in their
.env or shell environment — the tilde was never expanded, causing
FileNotFoundError or creating directories in literal '~/...' paths.
2026-04-13 21:36:35 -04:00
954fd992eb Merge pull request 'perf: lazy session creation — defer DB write until first message (#314)' (#449) from whip/314-1776127532 into main
Some checks failed
Forge CI / smoke-and-build (push) Failing after 55s
Forge CI / smoke-and-build (pull_request) Failing after 1m12s
perf: lazy session creation (#314)

Closes #314.
2026-04-14 01:08:13 +00:00
Metatron
f35f56e397 perf: lazy session creation — defer DB write until first message (closes #314)
Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 56s
Remove eager create_session() call from AIAgent.__init__(). Sessions
are now created lazily on first _flush_messages_to_session_db() call
via ensure_session() which uses INSERT OR IGNORE.

Impact: eliminates 32.4% of sessions (3,564 of 10,985) that were
created at agent init but never received any messages.

The existing ensure_session() fallback in _flush_messages_to_session_db()
already handles this pattern — it was originally designed for recovery
after transient SQLite lock failures. Now it's the primary creation path.

Compression-initiated sessions still use create_session() directly
(line ~5995) since they have messages to write immediately.
2026-04-13 20:52:06 -04:00
2 changed files with 7 additions and 26 deletions

View File

@@ -12,9 +12,10 @@ def get_hermes_home() -> Path:
"""Return the Hermes home directory (default: ~/.hermes).
Reads HERMES_HOME env var, falls back to ~/.hermes.
Expands ~ to the user's home directory.
This is the single source of truth — all other copies should import this.
"""
return Path(os.getenv("HERMES_HOME", Path.home() / ".hermes"))
return Path(os.getenv("HERMES_HOME", str(Path.home() / ".hermes"))).expanduser()
def get_optional_skills_dir(default: Path | None = None) -> Path:
@@ -25,7 +26,7 @@ def get_optional_skills_dir(default: Path | None = None) -> Path:
"""
override = os.getenv("HERMES_OPTIONAL_SKILLS", "").strip()
if override:
return Path(override)
return Path(override).expanduser()
if default is not None:
return default
return get_hermes_home() / "optional-skills"

View File

@@ -1001,30 +1001,10 @@ class AIAgent:
self._session_db = session_db
self._parent_session_id = parent_session_id
self._last_flushed_db_idx = 0 # tracks DB-write cursor to prevent duplicate writes
if self._session_db:
try:
self._session_db.create_session(
session_id=self.session_id,
source=self.platform or os.environ.get("HERMES_SESSION_SOURCE", "cli"),
model=self.model,
model_config={
"max_iterations": self.max_iterations,
"reasoning_config": reasoning_config,
"max_tokens": max_tokens,
},
user_id=None,
parent_session_id=self._parent_session_id,
)
except Exception as e:
# Transient SQLite lock contention (e.g. CLI and gateway writing
# concurrently) must NOT permanently disable session_search for
# this agent. Keep _session_db alive — subsequent message
# flushes and session_search calls will still work once the
# lock clears. The session row may be missing from the index
# for this run, but that is recoverable (flushes upsert rows).
logger.warning(
"Session DB create_session failed (session_search still available): %s", e
)
# Lazy session creation: defer until first message flush (#314).
# _flush_messages_to_session_db() calls ensure_session() which uses
# INSERT OR IGNORE — creating the row only when messages arrive.
# This eliminates 32% of sessions that are created but never used.
# In-memory todo list for task planning (one per agent/session)
from tools.todo_tool import TodoStore