fix(grok): close the panel relay when the cost-cap kills an interactive chat (M4)

_enforce_grok_cost_budget killed + evicted a container directly. For the
interactive roles (intake/secretary) that left the panel SSE relay open with no
close sentinel, so the chat froze with no explanation. Add
PrompterLiveRegistry.close_by_agent (push a final error event, then close every
session bound to that agent) and call it from the cost-cap watchdog when the
killed agent is the intake or secretary, so the panel reports the chat ended on
the cost cap instead of hanging.
This commit is contained in:
Renn F
2026-06-18 20:18:26 +02:00
parent a0b73cf69b
commit f314723c98
3 changed files with 42 additions and 0 deletions
+14
View File
@@ -22,6 +22,20 @@ def test_open_get_close() -> None:
assert reg.get("s1") is None
def test_close_by_agent_closes_matching_sessions_with_error() -> None:
reg = PrompterLiveRegistry()
reg.open("s1", "intake-1")
reg.open("s2", "secretary-1") # different agent — must survive
closed = reg.close_by_agent("intake-1", error="cost cap")
assert closed == ["s1"]
assert reg.get("s1") is None # closed + popped
assert reg.is_alive("s2") # untouched
# The error event is queued before the close sentinel so the panel sees it.
sess = reg.open("s3", "intake-1")
reg.close_by_agent("intake-1", error="boom")
assert sess.queue.get_nowait() == {"kind": "error", "text": "boom"}
def test_park_and_find_by_task() -> None:
"""A parked session is discoverable by task id for board-feedback injection."""
reg = PrompterLiveRegistry()