The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): the stored picker feed lists messaging and cron sessions again
yoniebans4dc14f5c6ca6
diff --git a/gateway/session_listing.py b/gateway/session_listing.pyindex 231252f608f..9601c5ae951 100644--- a/gateway/session_listing.py+++ b/gateway/session_listing.py@@ -3,6 +3,22 @@ from hermes_state_local_migration import validate_legacy_rowfrom hermes_state_mutation_binding import authorize_historyfrom hermes_state_runtime import RuntimeStoreError+from gateway.session_route_recovery import _messaging_platform, mountable++# Local labels (a cron run is a canonical local session whose last viewer is its own fire).+_LOCAL_SOURCES = ('cli', 'tui', 'gui', 'desktop', 'local', 'cron')+++def _messaging_sources():+ from gateway.config import Platform+ return [p.value for p in Platform if _messaging_platform(p.value) is not None]+++def _picker_row(row, tip, sid):+ return {'id': row['id'], 'session_id': sid, 'resolved_id': sid, 'title': row.get('title') or '',+ 'source': tip['source'], 'started_at': row.get('started_at'),+ 'message_count': row.get('message_count', 0), 'model': tip.get('model'), 'running': False}+def stored_picker_sessions(authority, actor, *, limit, include_hidden=False):"""Offer legacy local rows only to the same native transport that may resume them.@@ -16,15 +32,26 @@ def stored_picker_sessions(authority, actor, *, limit, include_hidden=False):or not {'session:read', 'session:create'} <= actor.capabilities):return {'sessions': [], 'scope': 'stored'}db = authority.db+ own_profile = db._own_profile_name() or 'default'sessions, offset, seen = [], 0, set()while len(sessions) < limit:- rows = db.list_sessions_rich(sources=['cli', 'tui', 'gui', 'desktop', 'local'], limit=200, offset=offset,+ rows = db.list_sessions_rich(sources=[*_LOCAL_SOURCES, *_messaging_sources()], limit=200, offset=offset,order_by_last_active=True, compact_rows=True, include_hidden=include_hidden)for row in rows:sid = db.get_compression_tip(row['id']) or row['id']tip = db.get_session(sid)if tip is None:continue+ if row['source'] not in _LOCAL_SOURCES:+ # A messaging conversation: listed when the cold mount would open it (this profile's,+ # its lineage root); a row its lane moved past opens read-only.+ if (row.get('profile_name') in (None, '', own_profile) and mountable(authority, row['id'])+ and row['id'] not in seen):+ seen.add(row['id'])+ sessions.append(_picker_row(row, tip, row['id']))+ if len(sessions) == limit:+ break+ continueclosed = _closed_local_session(authority, actor, row, tip)if closed is not None:if closed['id'] not in seen:@@ -42,10 +69,7 @@ def stored_picker_sessions(authority, actor, *, limit, include_hidden=False):if exc.reason not in {'not_found', 'permission_denied'}:raisecontinue- sessions.append({'id': row['id'], 'session_id': sid, 'resolved_id': sid,- 'title': row.get('title') or '', 'source': tip['source'],- 'started_at': row.get('started_at'), 'message_count': row.get('message_count', 0),- 'model': tip.get('model'), 'running': False})+ sessions.append(_picker_row(row, tip, sid))if len(sessions) == limit:breakif len(rows) < 200:diff --git a/gateway/session_route_recovery.py b/gateway/session_route_recovery.pyindex d565e02f1a4..3eaaa8d0fc4 100644--- a/gateway/session_route_recovery.py+++ b/gateway/session_route_recovery.py@@ -89,11 +89,9 @@ def _row_entry(row, platform, route, profile):transport_profile=row.get('transport_profile'))-def restore_routed_session(authority, sid):- """Publish *sid* as its lane would after a restart; None when this row is not one a route or a- messaging-platform row can stand for."""- from gateway.session_authority import LiveSession- from gateway.session_contract import SessionRef+def _mount_plan(authority, sid):+ """``(route, entry, routed)`` for a row a route or a messaging-platform row can stand for, else+ None. Reads only: ``restore_routed_session`` mounts it, the stored picker lists it."""row = authority.db.get_session(sid)route = row.get('session_key') if row is not None else Noneplatform = _messaging_platform(row['source']) if route else None@@ -106,8 +104,18 @@ def restore_routed_session(authority, sid):return Nonerouted = _routed_entry(authority, sid, route)entry = routed or _row_entry(row, platform, route, profile)- if entry is None:+ return None if entry is None else (route, entry, routed)+++def restore_routed_session(authority, sid):+ """Publish *sid* as its lane would after a restart; None when this row is not one a route or a+ messaging-platform row can stand for."""+ from gateway.session_authority import LiveSession+ from gateway.session_contract import SessionRef+ plan = _mount_plan(authority, sid)+ if plan is None:return None+ route, entry, routed = plansuperseded = routed is None and _names_another_conversation(authority, sid, route)authority._require_admission_open()# Re-pin the persisted receiving bot so delivery after a restart goes through it or nowhere,@@ -117,6 +125,11 @@ def restore_routed_session(authority, sid):return SessionRef(authority.profile_id, sid)+def mountable(authority, sid):+ """``restore_routed_session`` would mount *sid* (this profile's messaging lineage root)."""+ return _mount_plan(authority, sid) is not None++def messaging_owner_ref(authority, ref):"""The mount a messaging row resumes on: its compression lineage root, where the lane's turnspublish their events (``logical_owner``). Any other row keeps *ref*."""