The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): show unknown admissions and discard guidance on resume
unsupportedpastelsb3deb0a4a4ab
diff --git a/hermes_cli/gateway_chat_view.py b/hermes_cli/gateway_chat_view.pyindex a97750653ee..8bb97bd81c6 100644--- a/hermes_cli/gateway_chat_view.py+++ b/hermes_cli/gateway_chat_view.py@@ -13,6 +13,7 @@ class GatewayChatView:self.session_id = snapshot["stored_session_id"]self.generation = snapshot.get("execution_generation", 0)self.prompts = {p["prompt_id"]: p for p in snapshot.get("prompts", [])}+ self.pending = snapshot.get("pending", [])self.quiet = quietself.finite = Falseself.streams = {}@@ -22,6 +23,19 @@ class GatewayChatView:from hermes_cli.gateway_mutations import PreparedMutationsself.mutations = PreparedMutations()+ def show_pending(self):+ unknown = any(row["status"] == "unknown" for row in self.pending)+ if unknown:+ print("Execution outcome unknown after restart. Discard acknowledges the lost turn "+ "without replaying it; queued work may then continue.", file=sys.stderr)+ for row in self.pending:+ admission = row["admission_id"]+ if row["status"] == "unknown":+ print(f"Unknown admission: {admission}\n/discard {admission}", file=sys.stderr)+ elif row["status"] == "queued":+ context = "waiting behind unknown work" if unknown else "waiting to run"+ print(f"Queued admission: {admission} ({context})", file=sys.stderr)+def show_prompt(self, prompt):print(f"\n{prompt.get('description') or prompt.get('question') or 'Approval required'}", file=sys.stderr)if prompt.get("command"):@@ -131,6 +145,7 @@ class GatewayChatView:async def run(self, query=None, *, oneshot=False):self.quiet = self.quiet or oneshotself.finite = oneshot+ self.show_pending()for prompt in self.prompts.values():self.show_prompt(prompt)renderer = asyncio.create_task(self.render())diff --git a/tests/hermes_cli/test_gateway_chat_unknown.py b/tests/hermes_cli/test_gateway_chat_unknown.pynew file mode 100644index 00000000000..363ecad03c4--- /dev/null+++ b/tests/hermes_cli/test_gateway_chat_unknown.py@@ -0,0 +1,85 @@+"""Resume must expose the admission needed by the existing fenced discard control."""+import argparse+import asyncio+from contextlib import nullcontext+import json++import pytest+++async def test_resume_displays_unknown_and_queue_then_discards_with_refreshed_generation(monkeypatch, capsys):+ from websockets.asyncio.server import serve++ from hermes_cli import gateway_chat++ unknown_id = "admission-unknown-0123456789abcdef0123456789abcdef"+ queued_id = "admission-queued-fedcba9876543210fedcba9876543210"+ snapshot = {+ "stored_session_id": "stored",+ "execution_generation": 9,+ "pending": [+ {"admission_id": unknown_id, "status": "unknown", "execution_generation": 4},+ {"admission_id": queued_id, "status": "queued", "execution_generation": None},+ ],+ }+ refreshed = {+ **snapshot,+ "execution_generation": 10,+ "pending": [{**snapshot["pending"][0], "execution_generation": 5}, snapshot["pending"][1]],+ }+ calls = []++ async def peer(ws):+ async for raw in ws:+ request = json.loads(raw)+ method, params = request["method"], request["params"]+ calls.append((method, params))+ result = {}+ if method == "session.resume":+ resumes = sum(name == "session.resume" for name, _ in calls)+ result = snapshot if resumes == 1 else refreshed+ await ws.send(json.dumps({"jsonrpc": "2.0", "id": request["id"], "result": result}))++ class Input:+ submitted = False++ async def prompt_async(self, _prompt):+ if self.submitted:+ return "/quit"+ output = capsys.readouterr()+ # The user must be able to copy the full admission ID, not guess it+ # from the session ID or inspect the gateway's storage.+ commands = [line.strip() for line in output.err.splitlines() if line.strip().startswith("/discard ")]+ assert commands == [f"/discard {unknown_id}"]+ assert "unknown" in output.err.lower()+ assert any(queued_id in line and "queued" in line.lower() for line in output.err.splitlines())+ assert "waiting" in output.err.lower()+ assert "without replay" in output.err.lower()+ assert output.out == ""+ assert calls == [+ ("runtime.describe", {}),+ ("session.resume", {"session_id": snapshot["stored_session_id"]}),+ ], "Rendering recovery controls must not submit or resolve any work"+ self.submitted = True+ return commands[0]++ monkeypatch.setattr("prompt_toolkit.PromptSession", Input)+ monkeypatch.setattr("prompt_toolkit.patch_stdout.patch_stdout", nullcontext)+ async with serve(peer, "127.0.0.1", 0) as server:+ port = server.sockets[0].getsockname()[1]+ monkeypatch.setenv("HERMES_TUI_GATEWAY_URL", f"ws://127.0.0.1:{port}")+ assert await asyncio.wait_for(+ gateway_chat.run_gateway_chat(argparse.Namespace(resume=snapshot["stored_session_id"])), 5+ ) == 0++ assert calls == [+ ("runtime.describe", {}),+ ("session.resume", {"session_id": snapshot["stored_session_id"]}),+ ("session.resume", {"session_id": snapshot["stored_session_id"]}),+ ("prompt.resolve_unknown", {+ "session_id": snapshot["stored_session_id"],+ "admission_id": unknown_id,+ "execution_generation": refreshed["pending"][0]["execution_generation"],+ }),+ ]