Skip to content

The agent that grows with you

fix: retain hosted profile discovery and cross-owner recovery controls

Teknium980be81424ad
diff --git a/gateway/run_runtime.py b/gateway/run_runtime.py
index 3ddc1e1a8ca..de557870944 100644
--- a/gateway/run_runtime.py
+++ b/gateway/run_runtime.py
@@ -99,10 +99,10 @@ async def drain_gateway_runtime(runner):
descriptor = getattr(runner, 'session_runtime_descriptor', None)
if descriptor is None:
return
- from gateway.session_hosted_service import stop_hosted_service
- await stop_hosted_service(runner)
runner._draining = True
descriptor.update(state='draining', capabilities=[])
+ from gateway.session_hosted_service import stop_hosted_service
+ await stop_hosted_service(runner)
# Withdraw the public ingress callback without disconnecting egress needed
# by already admitted work. Base adapters refuse before stamping acceptance.
for adapter in runner.adapters.values():
diff --git a/gateway/session_group_controls.py b/gateway/session_group_controls.py
index 341c27db1c1..bd4b5f67b9a 100644
--- a/gateway/session_group_controls.py
+++ b/gateway/session_group_controls.py
@@ -268,4 +268,14 @@ def _profiles(authority, actor, home, params):
"ORDER BY COALESCE(last_activity_at,started_at) DESC LIMIT 1", (actor.subject,)).fetchone()
if latest:
row['last_session'] = summary(authority.db.get_session(latest[0]))
- return {'profiles': [row], 'bot_mode_protocol': True}
+ profiles = [row]
+ service = getattr(authority, 'hosted_room_service', None)
+ if service is not None:
+ for configured, target in service.profile_homes().items():
+ if target != home:
+ # Configured execution destinations are discovery metadata, not
+ # permission to read another owner's state/configuration.
+ profiles.append({'name': configured, 'path': str(target), 'is_default': False,
+ 'model': '', 'provider': '', 'description': '',
+ 'display_name': configured, 'skill_count': 0})
+ return {'profiles': profiles, 'bot_mode_protocol': True}
diff --git a/gateway/session_hosted_service.py b/gateway/session_hosted_service.py
index 833ecdba00b..418c41b58ed 100644
--- a/gateway/session_hosted_service.py
+++ b/gateway/session_hosted_service.py
@@ -191,9 +191,11 @@ async def ensure_hosted_service(runner):
loop = asyncio.get_running_loop()
service = await asyncio.to_thread(CanonicalHostedRoomService, authority, loop)
authority.hosted_room_service = service
- from gateway.session_hosted_transport import install_hosted_transport
- install_hosted_transport(runner.session_control_server, authority, asyncio.get_running_loop(),
- attest=service.attest)
+ if not getattr(service, '_transport_installed', False):
+ from gateway.session_hosted_transport import install_hosted_transport
+ install_hosted_transport(runner.session_control_server, authority, asyncio.get_running_loop(),
+ attest=service.attest)
+ service._transport_installed = True
await asyncio.to_thread(service.start)
return service
diff --git a/gateway/session_hosted_transport.py b/gateway/session_hosted_transport.py
index 0b7b1bc9719..0fb98fff74a 100644
--- a/gateway/session_hosted_transport.py
+++ b/gateway/session_hosted_transport.py
@@ -65,8 +65,13 @@ def owner_request(home, verb, params, *, timeout=30):
def _attest(binding, operation, params):
- result = owner_request(binding['source_home'], 'hosted-attest', {
- 'selector': binding['selector'], 'operation': operation, 'params': params})
+ try:
+ result = owner_request(binding['source_home'], 'hosted-attest', {
+ 'selector': binding['selector'], 'operation': operation, 'params': params})
+ except RuntimeStoreError:
+ raise
+ except (OSError, ValueError) as exc:
+ raise RuntimeStoreError('runtime_draining') from exc
if not isinstance(result, dict) or not isinstance(result.get('owner'), str) or not result['owner']:
raise RuntimeStoreError('permission_denied')
return result['owner']
diff --git a/tests/gateway/fixtures/hosted_auth_probe.py b/tests/gateway/fixtures/hosted_auth_probe.py
index 8ad3aceab45..8a309bb4bb4 100644
--- a/tests/gateway/fixtures/hosted_auth_probe.py
+++ b/tests/gateway/fixtures/hosted_auth_probe.py
@@ -187,7 +187,7 @@ def probe(tmp_path):
state = await rpc(ws, 'groups.state', room_id=room)
assert state['result']['room']['room_id'] == room, state
sent = await rpc(ws, 'groups.send', room_id=room, event_id='own-input',
- payload={'text': 'BLOCK_' + actor, 'thread_id': 'thread'})
+ payload={'text': '@two BLOCK_' + actor, 'thread_id': 'thread'})
assert sent['result']['accepted'], sent
assert await asyncio.to_thread(model.blocked[actor].wait, 30), state
before = await rpc(ws, 'groups.log', room_id=room)
@@ -222,7 +222,7 @@ def probe(tmp_path):
await asyncio.sleep(.1)
assert len(model.requests) == 2, model.requests
sent = await rpc(alice, 'groups.send', room_id='alice-room', event_id='approval',
- payload={'text': 'APPROVE_HOSTED', 'thread_id': 'approval-thread'})
+ payload={'text': '@two APPROVE_HOSTED', 'thread_id': 'approval-thread'})
assert sent['result']['accepted'], sent
async with asyncio.timeout(30):
while True:
diff --git a/tests/gateway/test_session_group_controls.py b/tests/gateway/test_session_group_controls.py
index dae887a9ac7..708603b3b13 100644
--- a/tests/gateway/test_session_group_controls.py
+++ b/tests/gateway/test_session_group_controls.py
@@ -54,7 +54,7 @@ def test_group_management_on_ordinary_authenticated_socket(tmp_path):
denied = await rpc(ws, 'groups.rename', profile='foreign', room_id='room-fixture', event_id='forbidden', name='Wrong')
assert denied['error']['message'] == 'profile_mismatch', denied
profiles = await rpc(ws, 'profiles.list', include_sessions=False)
- assert [p['path'] for p in profiles['result']['profiles']] == [str(home)], profiles
+ assert [p['path'] for p in profiles['result']['profiles']] == [str(home), str(home / 'profiles' / 'helper')], profiles
disbanded = await rpc(ws, 'groups.disband', room_id='room-fixture')
assert 'result' in disbanded, disbanded
assert (await rpc(ws, 'groups.list'))['result']['rooms'] == []
diff --git a/tests/gateway/test_session_hosted_daemon.py b/tests/gateway/test_session_hosted_daemon.py
index 9d30c3a55bc..e1c0e355e09 100644
--- a/tests/gateway/test_session_hosted_daemon.py
+++ b/tests/gateway/test_session_hosted_daemon.py
@@ -128,7 +128,7 @@ def test_room_unknown_discard_releases_only_its_followers(tmp_path):
reply = await rpc(ws, 'groups.create', room_id=room, name=room, members=members)
assert 'result' in reply, reply
reply = await rpc(ws, 'groups.send', room_id='unknown', event_id='started',
- payload={'text': 'BLOCK_HOSTED', 'thread_id': 'thread'})
+ payload={'text': '@two BLOCK_HOSTED', 'thread_id': 'thread'})
assert reply['result']['accepted'], reply
assert await asyncio.to_thread(model.blocked.wait, 25)
reply = await rpc(ws, 'groups.send', room_id='unknown', event_id='follower',
diff --git a/website/docs/developer-guide/hosted-profile-owners.md b/website/docs/developer-guide/hosted-profile-owners.md
new file mode 100644
index 00000000000..ee5cda327fe
--- /dev/null
+++ b/website/docs/developer-guide/hosted-profile-owners.md
@@ -0,0 +1,42 @@
+# Hosted rooms across local profile owners
+
+Hosted room execution uses the canonical session authority. Each profile runs its
+own ordinary gateway process and owns only its own state database. The source
+room driver contacts destination owners through their private OS-authenticated
+control sockets; it never launches a legacy session worker or opens a destination
+database.
+
+Configure explicit destinations in the source profile's configuration:
+
+```yaml
+hosted_rooms:
+ profiles:
+ helper: /absolute/path/to/profiles/helper
+```
+
+The name must match the destination profile name. Start that profile's gateway
+separately. Directory existence alone does not authorize execution. Configuration
+entries are exposed as roster metadata without reading the destination config or
+sessions. `gateway.multiplex_profiles` remains unsupported by the canonical owner;
+this is separate-process topology, not shared database multiplexing.
+
+The destination reverse-checks current room ownership, membership, exact durable
+task identity, hosted generation and frozen prompt with the source at submit and
+again before dequeue. It retains a source-namespaced binding in its own database.
+An unavailable source or destination fails closed; retained work is not silently
+rerouted. This private producer interface is not available to public WebSocket
+clients. Local same-OS-user trust applies to the control sockets.
+
+Startup publishes adapters before hosted recovery. Canonical supervision replaces
+the legacy room driver, avoiding competing leases. Completed retries recover the
+same receipt without new inference. Started work after an owner crash is unknown
+and pauses followers. Retry cannot replay unknown work. The owning user must use
+Discard with the exact room, member, task and hosted generation; canonical unknown
+resolution commits before the source driver's cancellation receipt. Repeating that
+exact discard recovers a lost acknowledgement.
+
+Desktop discovers canonical groups and sends controls to the captured connection,
+profile and room. Unknown work offers confirmed Discard, never Retry. Existing
+renderer-only groups require explicit new canonical-room creation; history is not
+automatically replayed as new work. The canonical workspace currently handles text
+and execution controls; attachment publication remains a separate room capability.