From a28e13b6e647a999bace538bf52b8596d2822018 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Wed, 23 Sep 2026 03:55:48 -0700 Subject: [PATCH] fix(tui_gateway): bind the session cwd around manual /compress session.compress runs compress_now on the RPC thread without the session context, so the compaction-boundary system-prompt rebuild resolved the backend's cwd (the process HOME) and persisted a prompt whose cwd line every later process rejects as stale runtime. The next resume (TUI or 'hermes chat --resume') then rebuilt the prompt from scratch - a second prompt-cache miss right after the sanctioned compaction one - and, on the oneshot path, skipped the tools pin. Bind the session cwd exactly like the sibling prompt-persist sites (server.py _persist_live_session_system_prompt, methods_slash.py). Exposed by tests/e2e/core/history/test_prefix_stability.py[tui_gateway_restarts]. --- tui_gateway/session_compression.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tui_gateway/session_compression.py b/tui_gateway/session_compression.py index 05d5b8ad36..e2e6f54975 100644 --- a/tui_gateway/session_compression.py +++ b/tui_gateway/session_compression.py @@ -242,7 +242,13 @@ def _compress_session_history( request = parse_compress_args(focus_topic or "") if request.aggressive: raise ValueError(AGGRESSIVE_UNSUPPORTED) - result = compress_now(agent, before_messages, request, task_id=session.get("session_key") or "default") + # RPC thread: bind the session cwd, or the boundary prompt rebuild resolves the backend's cwd and + # persists a prompt every other process then rejects as stale runtime (fresh build, no tools pin). + tokens = _set_session_context(session.get("session_key") or "", cwd=_session_cwd(session)) + try: + result = compress_now(agent, before_messages, request, task_id=session.get("session_key") or "default") + finally: + _clear_session_context(tokens) if result.status == "preview": return 0, _get_usage(agent) # Lock-skipped: raise so callers surface a clear message instead of "No changes from compression".