Skip to content

The agent that grows with you

fix(groups): allow member actor fields and send retry coordinates on serve

unsupportedpastels55f188d9ae9c
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index 6e3d8d9f92e..00a14a5d44b 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -1594,9 +1594,13 @@ export interface RoomEvent {
created_at: number
idempotent?: boolean
}
+/** ``hosted_rooms._ACTOR_FIELDS``; member replies carry ``profile`` plus, when known, ``display_name`` and the peer ``connection_id`` (``hosted_room_discussion._member_actor``). */
export interface RoomActor {
kind: string
id: string
+ profile?: string | null
+ display_name?: string | null
+ connection_id?: string | null
}
export interface GroupsCreateParams {
profile?: string | null
@@ -1626,7 +1630,7 @@ export interface GroupsStateResult {
room: Room
driver_status?: RoomDriverStatus | null
}
-/** ``HostedRoomService.status(room_id)``; ``pending_actions`` rows are ``{kind: retry, task_id}`` or the driver's approval action (``kind: approval`` + run/session/approval context). ``member_activity`` lists live tasks in admission order (absent from older gateways). */
+/** ``HostedRoomService.status(room_id)``; ``pending_actions`` rows are the exact attempt (``hosted_room_service.attempt_action``: ``kind`` + ``member_id``/``task_id``/``execution_generation``) or the driver's approval action (``kind: approval`` + run/session/approval context). ``member_activity`` lists live tasks in admission order (absent from older gateways). */
export interface RoomDriverStatus {
running: boolean
working: boolean
@@ -1728,6 +1732,8 @@ export interface GroupsRetryParams {
profile?: string | null
room_id: string
task_id: string
+ member_id?: string | null
+ execution_generation?: number | null
}
export interface GroupsRetryResult {
retried?: boolean
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index a5ebc6d5a98..0b113e1ab38 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -20039,6 +20039,30 @@
"task_id": {
"title": "Task Id",
"type": "string"
+ },
+ "member_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Member Id"
+ },
+ "execution_generation": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Execution Generation"
}
},
"required": [
@@ -33591,6 +33615,7 @@
},
"RoomActor": {
"additionalProperties": false,
+ "description": "``hosted_rooms._ACTOR_FIELDS``; member replies carry ``profile`` plus, when known,\n``display_name`` and the peer ``connection_id`` (``hosted_room_discussion._member_actor``).",
"properties": {
"kind": {
"title": "Kind",
@@ -33599,6 +33624,42 @@
"id": {
"title": "Id",
"type": "string"
+ },
+ "profile": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Profile"
+ },
+ "display_name": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Display Name"
+ },
+ "connection_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Connection Id"
}
},
"required": [
@@ -33766,7 +33827,7 @@
},
"RoomDriverStatus": {
"additionalProperties": false,
- "description": "``HostedRoomService.status(room_id)``; ``pending_actions`` rows are ``{kind: retry, task_id}``\nor the driver's approval action (``kind: approval`` + run/session/approval context).\n``member_activity`` lists live tasks in admission order (absent from older gateways).",
+ "description": "``HostedRoomService.status(room_id)``; ``pending_actions`` rows are the exact attempt\n(``hosted_room_service.attempt_action``: ``kind`` + ``member_id``/``task_id``/``execution_generation``)\nor the driver's approval action (``kind: approval`` + run/session/approval context).\n``member_activity`` lists live tasks in admission order (absent from older gateways).",
"properties": {
"running": {
"title": "Running",
diff --git a/gateway/session_hosted_controls.py b/gateway/session_hosted_controls.py
index e4df18297e3..028213e4050 100644
--- a/gateway/session_hosted_controls.py
+++ b/gateway/session_hosted_controls.py
@@ -2,6 +2,7 @@
from gateway import hosted_room_driver as tasks
from hermes_state_runtime import RuntimeStoreError
from tui_gateway.hosted_room_driver import HostedRoomBinding
+from tui_gateway.hosted_room_service import attempt_action, task_member_id
class HostedControls:
@@ -14,7 +15,7 @@ class HostedControls:
task = next((t for t in tasks.list_tasks(self.db_path, room_id=room_id)
if t['identity'].task_id == task_id), None)
if (task is None or task['execution_generation'] != execution_generation
- or (task['payload'].get('target_member_id') or task['payload'].get('target_profile')) != member_id):
+ or task_member_id(task) != member_id):
raise RuntimeStoreError('stale_generation')
if not any(m.get('member_id') == member_id
and m.get('profile') == task['payload']['target_profile']
@@ -72,10 +73,8 @@ class HostedControls:
for task in tasks.list_tasks(self.db_path, room_id=room_id):
if task['status'] not in {'indeterminate', 'deferred'}:
continue
- member = task['payload'].get('target_member_id') or task['payload']['target_profile']
- if self._member_is_peer(room_id, member):
+ if self._member_is_peer(room_id, task_member_id(task)):
continue
- actions.append({'kind': 'discard' if task['status'] == 'indeterminate' else 'retry',
- 'member_id': member, 'task_id': task['identity'].task_id,
- 'execution_generation': task['execution_generation']})
+ actions.append(attempt_action(
+ 'discard' if task['status'] == 'indeterminate' else 'retry', task))
return {**result, 'pending_actions': actions}
diff --git a/tests/tui_gateway/test_groups_log_member_actor.py b/tests/tui_gateway/test_groups_log_member_actor.py
new file mode 100644
index 00000000000..732e403f7a3
--- /dev/null
+++ b/tests/tui_gateway/test_groups_log_member_actor.py
@@ -0,0 +1,39 @@
+"""``groups.log`` serves member replies whose actor carries the profile/display/connection stamp."""
+
+from __future__ import annotations
+
+import pytest
+
+import tui_gateway.server as srv
+from gateway import hosted_rooms
+from tui_gateway import methods_groups
+
+
+def home(tmp_path, monkeypatch):
+ path = tmp_path / ".hermes"
+ (path / "profiles" / "ops").mkdir(parents=True)
+ (path / "profiles" / "ops" / "config.yaml").write_text("{}\n")
+ monkeypatch.setenv("HERMES_HOME", str(path))
+ methods_groups.stop_hosted_room_service(timeout=1.0)
+ methods_groups.start_hosted_room_service()
+ yield path
+ methods_groups.stop_hosted_room_service(timeout=1.0)
+
+
+def test_log_with_a_stamped_member_actor_satisfies_its_contract(home):
+ room = srv.handle_request({"id": 1, "method": "groups.create", "params": {
+ "room_id": "room-1", "name": "Room",
+ "members": [{"member_id": "default", "profile": "default", "handle": "hermes"},
+ {"member_id": "ops", "profile": "ops", "handle": "ops", "display_name": "Ops"}]}})
+ actor = {"kind": "member", "id": "ops", "profile": "ops", "display_name": "Ops",
+ "connection_id": "peer-1"}
+ hosted_rooms.append_event(
+ hosted_rooms.default_db_path(), room_id="room-1", event_id="reply-1", kind="message.member",
+ actor=actor, payload={"text": "Done", "thread_id": "thread-1"},
+ authority_gateway_id=room["result"]["room"]["authority_gateway_id"], authority_epoch=1)
+
+ response = srv.handle_request(
+ {"id": 2, "method": "groups.log", "params": {"room_id": "room-1", "since_seq": 0}})
+
+ assert response["result"]["events"][-1]["actor"] == actor
diff --git a/tests/tui_gateway/test_groups_methods.py b/tests/tui_gateway/test_groups_methods.py
index 3111b14b3fb..a22d768085a 100644
--- a/tests/tui_gateway/test_groups_methods.py
+++ b/tests/tui_gateway/test_groups_methods.py
@@ -722,8 +722,8 @@ def test_retry_and_approval_controls_forward_only_exact_local_coordinates(
turn_id="turn-1",
)
service = SimpleNamespace(
- retry_room_task=lambda room_id, task_id: (
- calls.append(("retry", room_id, task_id))
+ retry_room_task=lambda room_id, **kwargs: (
+ calls.append(("retry", room_id, kwargs))
or {
"identity": identity,
"status": "queued",
@@ -740,7 +740,7 @@ def test_retry_and_approval_controls_forward_only_exact_local_coordinates(
retried = _result(
srv._methods["groups.retry"](
1,
- {"room_id": "room-1", "task_id": "task-1"},
+ {"room_id": "room-1", "member_id": "ops", "task_id": "task-1", "execution_generation": 1},
)
)
approved = _result(
@@ -768,7 +768,7 @@ def test_retry_and_approval_controls_forward_only_exact_local_coordinates(
}
assert approved == {"approved": True, "result": {"resolved": 1}}
assert calls == [
- ("retry", "room-1", "task-1"),
+ ("retry", "room-1", {"member_id": "ops", "task_id": "task-1", "execution_generation": 1}),
(
"approve",
"room-1",
diff --git a/tests/tui_gateway/test_groups_retry_coordinates.py b/tests/tui_gateway/test_groups_retry_coordinates.py
new file mode 100644
index 00000000000..ab7284e86bf
--- /dev/null
+++ b/tests/tui_gateway/test_groups_retry_coordinates.py
@@ -0,0 +1,56 @@
+"""Standalone ``groups.state`` retry rows carry the exact attempt ``groups.retry`` accepts back."""
+
+from __future__ import annotations
+
+import threading
+import time
+from types import SimpleNamespace
+
+import tui_gateway.server as srv
+from gateway import hosted_room_driver as driver
+from tui_gateway.hosted_room_service import HostedRoomService
+
+
+def _deferred_room(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path)
+ (tmp_path / ".hermes" / "profiles" / "reviewer").mkdir(parents=True)
+ (tmp_path / ".hermes" / "profiles" / "reviewer" / "config.yaml").write_text("{}\n")
+ server = SimpleNamespace(_methods={}, _sessions={}, _sessions_lock=threading.Lock())
+ service = HostedRoomService(server, db_path=tmp_path / ".hermes" / "state.db")
+ service.create_room(room_id="room", name="Room", members=[
+ {"member_id": "worker", "profile": "default", "handle": "worker"},
+ {"member_id": "reviewer", "profile": "reviewer", "handle": "reviewer"}])
+ service.send(room_id="room", event_id="source", payload={"text": "Review", "thread_id": "thread"})
+ binding = service.bindings()[0]
+ task = driver.list_tasks(service.db_path, room_id="room", status="queued")[0]
+ now = [time.time()]
+ service.runtime.clock = clock = lambda: now[0]
+ old = driver.acquire_lease(
+ service.db_path, room_id="room", gateway_id=binding.gateway_id, authority_epoch=1,
+ process_generation="old", ttl_seconds=1, clock=clock)
+ driver.start_task(service.db_path, task["identity"], old, expected_cancel_generation=0, clock=clock)
+ now[0] += 2
+ lease = service.runtime._ensure_lease(binding)
+ driver.recover_room(service.db_path, lease, clock=clock)
+ driver.defer_indeterminate_task(
+ service.db_path, task["identity"], lease, expected_execution_generation=1,
+ expected_cancel_generation=0, reason="member_unavailable", clock=clock)
+ monkeypatch.setattr(srv, "get_hosted_room_service", lambda: service)
+ return service, task["identity"].task_id
+
+
+def test_retry_row_round_trips_through_groups_retry(tmp_path, monkeypatch):
+ service, task_id = _deferred_room(tmp_path, monkeypatch)
+
+ [action] = [a for a in service.status("room")["pending_actions"] if a["kind"] == "retry"]
+ assert action == {"kind": "retry", "member_id": "worker", "task_id": task_id,
+ "execution_generation": 1}
+ coordinates = {key: value for key, value in action.items() if key != "kind"}
+
+ stale = srv.handle_request({"id": 1, "method": "groups.retry", "params": {
+ "room_id": "room", **coordinates, "execution_generation": 2}})
+ assert "error" in stale
+ retried = srv.handle_request(
+ {"id": 2, "method": "groups.retry", "params": {"room_id": "room", **coordinates}})
+ assert retried["result"]["task"]["status"] == "queued"
diff --git a/tui_gateway/contracts/groups_bot_relay.py b/tui_gateway/contracts/groups_bot_relay.py
index 065e4859e80..041328af68a 100644
--- a/tui_gateway/contracts/groups_bot_relay.py
+++ b/tui_gateway/contracts/groups_bot_relay.py
@@ -29,8 +29,14 @@ class RoomMember(OpenModel):
class RoomActor(Result):
+ """``hosted_rooms._ACTOR_FIELDS``; member replies carry ``profile`` plus, when known,
+ ``display_name`` and the peer ``connection_id`` (``hosted_room_discussion._member_actor``)."""
+
kind: str
id: str
+ profile: str | None = None
+ display_name: str | None = None
+ connection_id: str | None = None
class RoomEvent(Result):
@@ -216,7 +222,8 @@ class RoomMemberActivity(Result):
class RoomDriverStatus(Result):
- """``HostedRoomService.status(room_id)``; ``pending_actions`` rows are ``{kind: retry, task_id}``
+ """``HostedRoomService.status(room_id)``; ``pending_actions`` rows are the exact attempt
+ (``hosted_room_service.attempt_action``: ``kind`` + ``member_id``/``task_id``/``execution_generation``)
or the driver's approval action (``kind: approval`` + run/session/approval context).
``member_activity`` lists live tasks in admission order (absent from older gateways)."""
@@ -346,6 +353,9 @@ method("groups.approve", params=GroupsApproveParams, result=GroupsApproveResult,
class GroupsRetryParams(RoomParams):
task_id: str
+ # The pending action's exact attempt; absent only from clients that predate it.
+ member_id: str | None = None
+ execution_generation: int | None = None
class RoomTaskReceipt(Result):
diff --git a/tui_gateway/hosted_room_service.py b/tui_gateway/hosted_room_service.py
index 19583e2166f..ce853df33d6 100644
--- a/tui_gateway/hosted_room_service.py
+++ b/tui_gateway/hosted_room_service.py
@@ -37,6 +37,16 @@ _STOPPABLE_STATUSES = ("queued", "running", "indeterminate", "deferred", "stoppi
_RETRYABLE_STATUSES = ("indeterminate", "deferred")
+def task_member_id(task: Mapping[str, Any]) -> str:
+ return str(task["payload"].get("target_member_id") or task["payload"]["target_profile"])
+
+
+def attempt_action(kind: str, task: Mapping[str, Any]) -> dict[str, Any]:
+ """A pending action naming the exact attempt ``groups.retry``/``discard`` fence on."""
+ return {"kind": kind, "member_id": task_member_id(task), "task_id": task["identity"].task_id,
+ "execution_generation": task["execution_generation"]}
+
+
def _hosted_room_turn_timeout_seconds() -> float:
try:
agent_timeout = float(os.getenv("HERMES_AGENT_TIMEOUT", "1800"))
@@ -524,10 +534,14 @@ class HostedRoomService:
self.runtime.wakeup()
return len(tasks)
- def retry_room_task(self, room_id: str, *, task_id: str) -> dict[str, Any]:
+ def retry_room_task(
+ self, room_id: str, *, task_id: str, member_id: str | None = None,
+ execution_generation: int | None = None) -> dict[str, Any]:
"""Retry one uncertain or deferred task only after explicit user action."""
candidates = self._list_tasks(room_id, _RETRYABLE_STATUSES)
- task = next((c for c in candidates if c["identity"].task_id == task_id), None)
+ task = next((c for c in candidates if c["identity"].task_id == task_id
+ and member_id in (None, task_member_id(c))
+ and execution_generation in (None, c["execution_generation"])), None)
if task is None:
raise driver.InvalidTaskTransitionError("no retryable room task matches task_id")
return self.runtime.retry_indeterminate(task["identity"])
@@ -579,16 +593,14 @@ class HostedRoomService:
tasks = driver.list_tasks(self.db_path, room_id=room_id)
counts = Counter(str(task["status"]) for task in tasks)
pending_actions = [
- {"kind": "retry", "task_id": task["identity"].task_id}
- for task in tasks if task["status"] in _RETRYABLE_STATUSES]
+ attempt_action("retry", task) for task in tasks if task["status"] in _RETRYABLE_STATUSES]
with self._policy_lock:
pending_actions.extend(
dict(action) for (action_room_id, _member_id), action
in self._pending_actions.items() if action_room_id == room_id)
# Who is answering right now: clients render per-member working indicators from it.
member_activity = [
- {"member_id": str(task["payload"].get("target_member_id") or task["payload"]["target_profile"]),
- "status": str(task["status"])}
+ {"member_id": task_member_id(task), "status": str(task["status"])}
for task in tasks if task["status"] in _LIVE_STATUSES]
return {
"running": runtime["running"], "working": bool(member_activity),
diff --git a/tui_gateway/methods_groups.py b/tui_gateway/methods_groups.py
index 5778910f213..2f94d7d17fb 100644
--- a/tui_gateway/methods_groups.py
+++ b/tui_gateway/methods_groups.py
@@ -449,7 +449,8 @@ def _(rid, params: dict, service) -> dict:
def _(rid, params: dict, service) -> dict:
"""Retry one indeterminate room task after explicit user confirmation."""
task = service.retry_room_task(
- str(params.get("room_id") or ""), task_id=str(params.get("task_id") or ""))
+ str(params.get("room_id") or ""), task_id=str(params.get("task_id") or ""),
+ member_id=params.get("member_id"), execution_generation=params.get("execution_generation"))
if not isinstance(task, dict):
task = {}
identity = task.get("identity")