mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-07 02:51:50 +00:00
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.
This commit is contained in:
parent
2e4b65b9f5
commit
dda12775f2
3 changed files with 16 additions and 16 deletions
|
|
@ -1144,16 +1144,14 @@ class SessionDB:
|
||||||
session_ids = self._session_lineage_root_to_tip(session_id)
|
session_ids = self._session_lineage_root_to_tip(session_id)
|
||||||
|
|
||||||
with self._lock:
|
with self._lock:
|
||||||
rows = []
|
placeholders = ",".join("?" for _ in session_ids)
|
||||||
for sid in session_ids:
|
rows = self._conn.execute(
|
||||||
cursor = self._conn.execute(
|
|
||||||
"SELECT role, content, tool_call_id, tool_calls, tool_name, "
|
"SELECT role, content, tool_call_id, tool_calls, tool_name, "
|
||||||
"reasoning, reasoning_content, reasoning_details, codex_reasoning_items, "
|
"reasoning, reasoning_content, reasoning_details, codex_reasoning_items, "
|
||||||
"codex_message_items "
|
"codex_message_items "
|
||||||
"FROM messages WHERE session_id = ? ORDER BY timestamp, id",
|
f"FROM messages WHERE session_id IN ({placeholders}) ORDER BY timestamp, id",
|
||||||
(sid,),
|
tuple(session_ids),
|
||||||
)
|
).fetchall()
|
||||||
rows.extend(cursor.fetchall())
|
|
||||||
|
|
||||||
messages = []
|
messages = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,7 @@ _stdout_lock = threading.Lock()
|
||||||
_cfg_lock = threading.Lock()
|
_cfg_lock = threading.Lock()
|
||||||
_cfg_cache: dict | None = None
|
_cfg_cache: dict | None = None
|
||||||
_cfg_mtime: float | None = None
|
_cfg_mtime: float | None = None
|
||||||
|
_cfg_path = None
|
||||||
_SLASH_WORKER_TIMEOUT_S = max(
|
_SLASH_WORKER_TIMEOUT_S = max(
|
||||||
5.0, float(os.environ.get("HERMES_TUI_SLASH_TIMEOUT_S", "45") or 45)
|
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:
|
def _load_cfg() -> dict:
|
||||||
global _cfg_cache, _cfg_mtime
|
global _cfg_cache, _cfg_mtime, _cfg_path
|
||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
p = _hermes_home / "config.yaml"
|
p = _hermes_home / "config.yaml"
|
||||||
mtime = p.stat().st_mtime if p.exists() else None
|
mtime = p.stat().st_mtime if p.exists() else None
|
||||||
with _cfg_lock:
|
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)
|
return copy.deepcopy(_cfg_cache)
|
||||||
if p.exists():
|
if p.exists():
|
||||||
with open(p) as f:
|
with open(p) as f:
|
||||||
|
|
@ -460,6 +461,7 @@ def _load_cfg() -> dict:
|
||||||
with _cfg_lock:
|
with _cfg_lock:
|
||||||
_cfg_cache = copy.deepcopy(data)
|
_cfg_cache = copy.deepcopy(data)
|
||||||
_cfg_mtime = mtime
|
_cfg_mtime = mtime
|
||||||
|
_cfg_path = p
|
||||||
return data
|
return data
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
@ -467,7 +469,7 @@ def _load_cfg() -> dict:
|
||||||
|
|
||||||
|
|
||||||
def _save_cfg(cfg: dict):
|
def _save_cfg(cfg: dict):
|
||||||
global _cfg_cache, _cfg_mtime
|
global _cfg_cache, _cfg_mtime, _cfg_path
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
path = _hermes_home / "config.yaml"
|
path = _hermes_home / "config.yaml"
|
||||||
|
|
@ -475,6 +477,7 @@ def _save_cfg(cfg: dict):
|
||||||
yaml.safe_dump(cfg, f)
|
yaml.safe_dump(cfg, f)
|
||||||
with _cfg_lock:
|
with _cfg_lock:
|
||||||
_cfg_cache = copy.deepcopy(cfg)
|
_cfg_cache = copy.deepcopy(cfg)
|
||||||
|
_cfg_path = path
|
||||||
try:
|
try:
|
||||||
_cfg_mtime = path.stat().st_mtime
|
_cfg_mtime = path.stat().st_mtime
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
@ -1769,7 +1772,7 @@ def _(rid, params: dict) -> dict:
|
||||||
return _ok(
|
return _ok(
|
||||||
rid,
|
rid,
|
||||||
{
|
{
|
||||||
"count": len(session.get("history", [])),
|
"count": len(history),
|
||||||
"messages": _history_to_messages(history),
|
"messages": _history_to_messages(history),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ export function inkCacheSizes(): InkCacheSizes {
|
||||||
export type EvictLevel = 'all' | 'half'
|
export type EvictLevel = 'all' | 'half'
|
||||||
|
|
||||||
export function evictInkCaches(level: EvictLevel = 'half'): InkCacheSizes {
|
export function evictInkCaches(level: EvictLevel = 'half'): InkCacheSizes {
|
||||||
const before = inkCacheSizes()
|
|
||||||
const keep = level === 'half' ? 0.5 : 0
|
const keep = level === 'half' ? 0.5 : 0
|
||||||
|
|
||||||
evictWidthCache(keep)
|
evictWidthCache(keep)
|
||||||
|
|
@ -42,5 +41,5 @@ export function evictInkCaches(level: EvictLevel = 'half'): InkCacheSizes {
|
||||||
evictSliceCache(keep)
|
evictSliceCache(keep)
|
||||||
evictLineWidthCache(keep)
|
evictLineWidthCache(keep)
|
||||||
|
|
||||||
return before
|
return inkCacheSizes()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue