The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): `hermes sessions delete` on an unfinished turn points to discard
Teknium4857d1c035bf
diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.pyindex c93ea686819..856b8d79288 100644--- a/hermes_cli/sessions_cmd.py+++ b/hermes_cli/sessions_cmd.py@@ -616,12 +616,24 @@ def _cmd_delete(db, args):returnelif _pinned_note:print(f"Warning: deleting a pinned session '{resolved_session_id}'.")+ from hermes_state_runtime import RuntimeStoreErrortry:if not db.delete_session(resolved_session_id, sessions_dir=_sessions_dir(), exclude_active_write_guards=True):return _not_found(args.session_id)except SessionActiveWriteGuardError as exc:print(f"Cannot delete active session: {exc}")return 1+ except RuntimeStoreError as exc:+ # The ledger refuses to delete a session with accepted, unfinished turns; say what to do.+ if exc.reason == 'unknown_execution':+ print(f"Cannot delete session '{resolved_session_id}': a turn was lost across a gateway restart. "+ f"Acknowledge it first with: hermes sessions discard {resolved_session_id}")+ elif exc.reason == 'session_busy':+ print(f"Cannot delete session '{resolved_session_id}': it has a queued or running turn. "+ "Wait for it to finish (or stop it), then retry.")+ else:+ print(f"Cannot delete session '{resolved_session_id}': {exc.reason}")+ return 1print(f"Deleted session '{resolved_session_id}'.")diff --git a/tests/hermes_cli/test_sessions_delete.py b/tests/hermes_cli/test_sessions_delete.pyindex 03df47f48b4..684d2abc0fe 100644--- a/tests/hermes_cli/test_sessions_delete.py+++ b/tests/hermes_cli/test_sessions_delete.py@@ -40,6 +40,35 @@ def test_sessions_delete_accepts_unique_id_prefix(monkeypatch, capsys):}assert "Deleted session '20260315_092437_c9a6ff'." in output[email protected]('status', ['queued', 'unknown'])+def test_sessions_delete_with_unfinished_turn_points_to_discard(tmp_path, monkeypatch, capsys, status):+ """P3: the ledger's session_busy / unknown_execution refusal is a user-facing answer (exit 1+ with what to do), not an uncaught RuntimeStoreError traceback."""+ import hermes_cli.main as main_mod+ import hermes_state+ import hermes_state_runtime as rt+ from hermes_state import SessionDB++ db = SessionDB(tmp_path / 'state.db')+ db.create_session('s1', source='cli')+ epoch = rt.begin_runtime_epoch(db, instance_id='a')+ rt.admit_session_input(db, epoch=epoch, principal_id='p', session_id='s1', request_id='r', payload={'text': 'x'})+ if status == 'unknown':+ rt.claim_session_input(db, epoch=epoch, session_id='s1')+ rt.recover_session_inputs(db, epoch=rt.begin_runtime_epoch(db, instance_id='b'))+ monkeypatch.setattr(hermes_state, 'SessionDB', lambda *args, **kwargs: db)+ monkeypatch.setattr(sys, 'argv', ['hermes', 'sessions', 'delete', 's1', '--yes'])+ with pytest.raises(SystemExit) as exited:+ main_mod.main()+ output = capsys.readouterr().out+ assert exited.value.code == 1+ assert ('hermes sessions discard s1' in output) == (status == 'unknown'), output+ assert 'queued or running turn' in output or status == 'unknown', output+ reopened = SessionDB(tmp_path / 'state.db')+ assert reopened.get_session('s1') is not None+ reopened.close()++def _run_prune(monkeypatch, capsys, argv_tail, candidates=None, skipped_open=0):"""Run `hermes sessions prune <argv_tail>` against a FakeDB, capturingthe filter kwargs passed to list_prune_candidates. Auto-confirms."""