Skip to content

The agent that grows with you

fix(cli): the /queue dock drops an admission the owner no longer lists

Tekniumfa464f71fc47
diff --git a/hermes_cli/gateway_connection.py b/hermes_cli/gateway_connection.py
index 06d7eabc471..a8005630e7c 100644
--- a/hermes_cli/gateway_connection.py
+++ b/hermes_cli/gateway_connection.py
@@ -74,6 +74,9 @@ class SessionState:
# ``/queue`` admission whose ``message.start`` this viewer dropped unpainted (a local turn's
# drain or pump) is in ``missed``. Both make the idle tick read its receipt (``recover_queued``).
self.pending_seq = 0
+ # ``admission_id -> pending_seq`` when this viewer queued it: the dock shows it only until the
+ # owner publishes a list after that (``gateway_queue.published_queue``).
+ self.queued_at: dict = {}
self.recovered_seq = 0
self.missed: set = set()
# ``session.replay_gap``s seen, and how many a re-attach covered: the owner retired this viewer's
diff --git a/hermes_cli/gateway_queue.py b/hermes_cli/gateway_queue.py
index 30b916511ec..759300a92d2 100644
--- a/hermes_cli/gateway_queue.py
+++ b/hermes_cli/gateway_queue.py
@@ -32,7 +32,9 @@ def submit_queued(cli, store, text: str) -> str:
admission = (receipt or {}).get("admission_id")
if not admission:
raise GatewayClientError("the gateway did not admit the queued prompt")
- _state(cli, store).queued_inputs[admission] = text
+ state = _state(cli, store)
+ state.queued_inputs[admission] = text
+ state.queued_at[admission] = state.pending_seq
return admission
@@ -65,13 +67,20 @@ def queued_rows(cli, store) -> list[tuple[str, str]]:
def published_queue(cli, store) -> list[str]:
- """The texts the owner last published as queued, plus this viewer's admissions not yet in that list
- (no RPC: the dock repaints on every tick)."""
+ """The texts the owner last published as queued, plus this viewer's admissions submitted after that
+ list (no RPC: the dock repaints on every tick).
+
+ The owner's published list is authoritative: an admission it no longer lists (cancelled, replaced or
+ steered by another client, or started) is not shown as queued, even while ``queued_inputs`` still
+ owes its turn a paint."""
state = _state(cli, store)
+ for gone in [admission for admission in state.queued_at if admission not in state.queued_inputs]:
+ state.queued_at.pop(gone, None)
rows = [row for row in state.pending or () if isinstance(row, dict)]
known = {row.get("admission_id") for row in rows}
- return ([str(row.get("text") or "") for row in rows if row.get("status") == "queued"]
- + [text for admission, text in state.queued_inputs.items() if admission not in known])
+ fresh = [text for admission, text in state.queued_inputs.items()
+ if admission not in known and state.queued_at.get(admission, -1) >= state.pending_seq]
+ return [str(row.get("text") or "") for row in rows if row.get("status") == "queued"] + fresh
def cancel(cli, store, admission: str) -> bool:
@@ -90,4 +99,5 @@ def replace(cli, store, admission: str, text: str) -> str | None:
new = (receipt or {}).get("admission_id")
if new:
state.queued_inputs[new] = text
+ state.queued_at[new] = state.pending_seq
return new
diff --git a/tests/hermes_cli/test_cli_queue_gateway_fifo.py b/tests/hermes_cli/test_cli_queue_gateway_fifo.py
index e48f8fe5cbb..ea2e47d6138 100644
--- a/tests/hermes_cli/test_cli_queue_gateway_fifo.py
+++ b/tests/hermes_cli/test_cli_queue_gateway_fifo.py
@@ -343,3 +343,71 @@ def test_a_queued_turn_the_owner_ran_before_this_viewer_reattached_is_still_pain
assert state.queued_inputs == {}
finally:
conn.close()
+
+
+def test_dock_drops_a_cli_queued_admission_another_client_cancelled():
+ """Review N5-F1: another client retired the CLI's queued admission (prompt.cancel, replace, steer).
+ The owner's next published pending list omits it; the dock must stop listing it as queued."""
+ from hermes_cli.cli_session_dock import queued_prompts
+ from tests.hermes_cli.test_gateway_agent import SID
+ from tests.hermes_cli.test_gateway_tools_notify import _connected, _idle_cli
+ conn, _client = _connected()
+ try:
+ cli = _idle_cli(conn)
+ state = conn.state(SID)
+ state.queued_inputs["adm-q"] = TEXT
+ state.apply_event("session.info", {"pending": [{"admission_id": "adm-q", "status": "queued",
+ "sequence": 1, "text": TEXT}]})
+ assert queued_prompts(cli) == [TEXT]
+ state.apply_event("session.info", {"pending": []}) # another client cancelled it
+ assert queued_prompts(cli) == [], "retired admission still painted as queued"
+ finally:
+ conn.close()
+
+
+def test_dock_shows_a_fresh_submit_until_the_owner_publishes_its_list():
+ """The gap between the submit's receipt and the owner's next pending list: the new admission is shown;
+ the first list published after it decides."""
+ from hermes_cli import gateway_queue
+ from hermes_cli.cli_session_dock import queued_prompts
+ from tests.hermes_cli.test_gateway_agent import SID
+ from tests.hermes_cli.test_gateway_tools_notify import _connected, _idle_cli
+ conn, _client = _connected()
+ try:
+ cli = _idle_cli(conn)
+ state = conn.state(SID)
+ state.apply_event("session.info", {"pending": []})
+ gateway_queue.submit_queued(cli, cli._session_db, TEXT) # FakeClient admits it as adm-1
+ assert queued_prompts(cli) == [TEXT]
+ state.apply_event("session.info", {"pending": [{"admission_id": "adm-1", "status": "queued",
+ "sequence": 1, "text": TEXT}]})
+ assert queued_prompts(cli) == [TEXT]
+ state.apply_event("session.info", {"pending": []})
+ assert queued_prompts(cli) == []
+ finally:
+ conn.close()
+
+
+def test_a_queued_admission_another_client_cancelled_is_forgotten_not_painted():
+ """A remembered admission that settled without running (cancelled by Ink/Desktop) is dropped from
+ ``queued_inputs`` on the next published list; nothing is painted for it."""
+ from tests.hermes_cli.test_gateway_agent import SID
+ from tests.hermes_cli.test_gateway_tools_notify import _connected, _idle_cli
+ conn, client = _connected()
+ try:
+ cli = _idle_cli(conn)
+ state = conn.state(SID)
+ state.queued_inputs["adm-q"] = TEXT
+ real = client.rpc
+
+ async def rpc(method, **params):
+ if method == "prompt.receipt":
+ client.calls.append((method, params))
+ return {"admission_id": "adm-q", "status": "terminal", "outcome": "cancelled"}
+ return await real(method, **params)
+ client.rpc = rpc
+ state.apply_event("session.info", {"pending": []})
+ cli._drain_process_notifications("cli-idle")
+ assert cli._pending_input.empty() and state.queued_inputs == {}
+ finally:
+ conn.close()