From dda12775f219a20278df2e8c757995222060a309 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Sun, 26 Apr 2026 21:24:54 -0500 Subject: [PATCH] fix(tui): address Copilot review follow-ups Keep history metadata consistent with lineage replay, globally order replayed lineage messages, and make Ink cache eviction report post-eviction sizes. Also keys TUI config cache by path to avoid cross-home test leakage. --- hermes_state.py | 18 ++++++++---------- tui_gateway/server.py | 11 +++++++---- .../hermes-ink/src/ink/cache-eviction.ts | 3 +-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/hermes_state.py b/hermes_state.py index 68f8143db2..b06d548bbc 100644 --- a/hermes_state.py +++ b/hermes_state.py @@ -1144,16 +1144,14 @@ class SessionDB: session_ids = self._session_lineage_root_to_tip(session_id) with self._lock: - rows = [] - for sid in session_ids: - cursor = self._conn.execute( - "SELECT role, content, tool_call_id, tool_calls, tool_name, " - "reasoning, reasoning_content, reasoning_details, codex_reasoning_items, " - "codex_message_items " - "FROM messages WHERE session_id = ? ORDER BY timestamp, id", - (sid,), - ) - rows.extend(cursor.fetchall()) + placeholders = ",".join("?" for _ in session_ids) + rows = self._conn.execute( + "SELECT role, content, tool_call_id, tool_calls, tool_name, " + "reasoning, reasoning_content, reasoning_details, codex_reasoning_items, " + "codex_message_items " + f"FROM messages WHERE session_id IN ({placeholders}) ORDER BY timestamp, id", + tuple(session_ids), + ).fetchall() messages = [] for row in rows: diff --git a/tui_gateway/server.py b/tui_gateway/server.py index 29d2d018c7..af10da5dfd 100644 --- a/tui_gateway/server.py +++ b/tui_gateway/server.py @@ -124,6 +124,7 @@ _stdout_lock = threading.Lock() _cfg_lock = threading.Lock() _cfg_cache: dict | None = None _cfg_mtime: float | None = None +_cfg_path = None _SLASH_WORKER_TIMEOUT_S = max( 5.0, float(os.environ.get("HERMES_TUI_SLASH_TIMEOUT_S", "45") or 45) ) @@ -443,14 +444,14 @@ def _normalize_completion_path(path_part: str) -> str: def _load_cfg() -> dict: - global _cfg_cache, _cfg_mtime + global _cfg_cache, _cfg_mtime, _cfg_path try: import yaml p = _hermes_home / "config.yaml" mtime = p.stat().st_mtime if p.exists() else None with _cfg_lock: - if _cfg_cache is not None and _cfg_mtime == mtime: + if _cfg_cache is not None and _cfg_mtime == mtime and _cfg_path == p: return copy.deepcopy(_cfg_cache) if p.exists(): with open(p) as f: @@ -460,6 +461,7 @@ def _load_cfg() -> dict: with _cfg_lock: _cfg_cache = copy.deepcopy(data) _cfg_mtime = mtime + _cfg_path = p return data except Exception: pass @@ -467,7 +469,7 @@ def _load_cfg() -> dict: def _save_cfg(cfg: dict): - global _cfg_cache, _cfg_mtime + global _cfg_cache, _cfg_mtime, _cfg_path import yaml path = _hermes_home / "config.yaml" @@ -475,6 +477,7 @@ def _save_cfg(cfg: dict): yaml.safe_dump(cfg, f) with _cfg_lock: _cfg_cache = copy.deepcopy(cfg) + _cfg_path = path try: _cfg_mtime = path.stat().st_mtime except Exception: @@ -1769,7 +1772,7 @@ def _(rid, params: dict) -> dict: return _ok( rid, { - "count": len(session.get("history", [])), + "count": len(history), "messages": _history_to_messages(history), }, ) diff --git a/ui-tui/packages/hermes-ink/src/ink/cache-eviction.ts b/ui-tui/packages/hermes-ink/src/ink/cache-eviction.ts index 4e3ac4d216..0c5a08aaba 100644 --- a/ui-tui/packages/hermes-ink/src/ink/cache-eviction.ts +++ b/ui-tui/packages/hermes-ink/src/ink/cache-eviction.ts @@ -34,7 +34,6 @@ export function inkCacheSizes(): InkCacheSizes { export type EvictLevel = 'all' | 'half' export function evictInkCaches(level: EvictLevel = 'half'): InkCacheSizes { - const before = inkCacheSizes() const keep = level === 'half' ? 0.5 : 0 evictWidthCache(keep) @@ -42,5 +41,5 @@ export function evictInkCaches(level: EvictLevel = 'half'): InkCacheSizes { evictSliceCache(keep) evictLineWidthCache(keep) - return before + return inkCacheSizes() }