fix(tui): harden active-session temp file handling

- create HERMES_TUI_ACTIVE_SESSION_FILE with mkstemp instead of a predictable tmp path and always cleanup in finally
- add assertions that launch wiring uses a randomized session file path and removes it on exit
This commit is contained in:
Brooklyn Nicholson
2026-04-26 22:51:18 -05:00
committed by Teknium
parent 4b28140912
commit 7a6128cc4f
2 changed files with 19 additions and 12 deletions

View File

@@ -1057,9 +1057,10 @@ def _launch_tui(
import tempfile
env = os.environ.copy()
active_session_file = os.path.join(
tempfile.gettempdir(), f"hermes-tui-active-session-{os.getpid()}.json"
active_session_fd, active_session_file = tempfile.mkstemp(
prefix="hermes-tui-active-session-", suffix=".json"
)
os.close(active_session_fd)
env["HERMES_TUI_ACTIVE_SESSION_FILE"] = active_session_file
env["HERMES_PYTHON_SRC_ROOT"] = os.environ.get(
"HERMES_PYTHON_SRC_ROOT", str(PROJECT_ROOT)
@@ -1088,18 +1089,20 @@ def _launch_tui(
env["HERMES_TUI_RESUME"] = resume_session_id
argv, cwd = _make_tui_argv(tui_dir, tui_dev)
code: Optional[int] = None
try:
code = subprocess.call(argv, cwd=str(cwd), env=env)
except KeyboardInterrupt:
code = 130
try:
code = subprocess.call(argv, cwd=str(cwd), env=env)
except KeyboardInterrupt:
code = 130
if code in (0, 130):
_print_tui_exit_summary(resume_session_id, active_session_file)
try:
os.unlink(active_session_file)
except OSError:
pass
if code in (0, 130):
_print_tui_exit_summary(resume_session_id, active_session_file)
finally:
try:
os.unlink(active_session_file)
except OSError:
pass
sys.exit(code)