Skip to content

The agent that grows with you

fix(gateway): resume pre-upgrade Desktop chats by id

unsupportedpastelsf9b5bd24c240
diff --git a/gateway/session_local_migration.py b/gateway/session_local_migration.py
index a0640e15f54..554f7d2fd4f 100644
--- a/gateway/session_local_migration.py
+++ b/gateway/session_local_migration.py
@@ -67,7 +67,7 @@ def adopt_legacy_session(authority, actor, row):
if (getattr(authority, '_native_legacy_transports', {}).get(actor.transport_id) != actor
or not {'session:read', 'session:create'} <= actor.capabilities):
raise RuntimeStoreError('not_found')
- from hermes_state_local_migration import validate_legacy_row
+ from hermes_state_local_migration import LEGACY_CREATION_SOURCES, validate_legacy_row
validate_legacy_row(authority.db, row)
authority._require_admission_open()
from gateway.run import _load_gateway_config, _resolve_gateway_model
@@ -78,7 +78,7 @@ def adopt_legacy_session(authority, actor, row):
request_id = 'legacy:' + row['id']
sid = row['id']
- params = {'source': row['source']}
+ params = {'source': LEGACY_CREATION_SOURCES.get(row['source'], row['source'])}
if row.get('cwd'):
params['cwd'] = row['cwd']
if row.get('model'):
diff --git a/hermes_state_local_migration.py b/hermes_state_local_migration.py
index 4371d75ab86..16f7be62e8e 100644
--- a/hermes_state_local_migration.py
+++ b/hermes_state_local_migration.py
@@ -10,7 +10,10 @@ LEGACY_PREFIX = 'gateway.local_legacy.v1:'
# Sources the pre-authority local CLI/TUI/GUI wrote. ``oneshot`` (finite ``chat -q`` / ``-z``) and ``tool``
# (``chat --source tool``) are CLI runs that printed ``hermes --resume <id>``: adopted for resume like
# ``cli`` and keeping their label, so human pickers still hide them (INTERNAL_LISTING_SOURCES).
-LEGACY_LOCAL_SOURCES = frozenset({'cli', 'tui', 'gui', 'oneshot', 'tool'})
+# ``desktop`` is the label main's Desktop stored; it is adopted as the ``gui`` creation source.
+LEGACY_LOCAL_SOURCES = frozenset({'cli', 'tui', 'gui', 'desktop', 'oneshot', 'tool'})
+# Legacy labels that are not creation sources of their own (session_policy.SURFACES).
+LEGACY_CREATION_SOURCES = {'desktop': 'gui'}
def validate_legacy_row(db, row):
diff --git a/tests/gateway/test_legacy_session_migration.py b/tests/gateway/test_legacy_session_migration.py
index 9b1fc773d3c..39b0624ac10 100644
--- a/tests/gateway/test_legacy_session_migration.py
+++ b/tests/gateway/test_legacy_session_migration.py
@@ -165,3 +165,38 @@ async def test_upgraded_oneshot_and_tool_history_resumes_by_id_and_title_but_sta
assert {db.get_session(s)['source'] for s in ('old-oneshot', 'old-tool')} == {'oneshot', 'tool'}
listed = await native.dispatch({'id': 3, 'method': 'session.list', 'params': {}})
assert listed['result']['sessions'] == [], listed
+
+
+async def test_upgraded_desktop_history_resumes_by_id(tmp_path, monkeypatch):
+ """main's Desktop stored its chats with ``source='desktop'``. After the upgrade the native owner
+ adopts them by id like ``gui`` history. A row that carries an account identity is unchanged:
+ it still needs its own authority."""
+ from gateway import run
+ from gateway.config import GatewayConfig
+ from gateway.session import SessionStore
+ from gateway.session_authority import initialize_session_authority
+ from gateway.session_controls import AuthorityConnection
+
+ monkeypatch.setenv('HERMES_HOME', str(tmp_path))
+ monkeypatch.setattr(run, '_load_gateway_config', lambda: {'platform_toolsets': {'gui': []}})
+ store = SessionStore(tmp_path / 'sessions', GatewayConfig())
+ db = store._db
+ for sid, user_id in (('old-desktop', None), ('old-desktop-account', 'nous:account')):
+ db.create_session(sid, source='desktop', model='old-model', cwd=str(tmp_path), user_id=user_id)
+ db.append_message(sid, role='user', content=sid.upper())
+ db.end_session(sid, 'session_switch')
+ runner = SimpleNamespace(session_store=store, _session_db=db, adapters={}, _draining=False,
+ _cached_agent_for=lambda route: None)
+ runner._adapter_for_source = lambda source: runner.adapters.get(source.platform)
+ authority = await initialize_session_authority(runner, profile_id=str(tmp_path), instance_id='first')
+ native = AuthorityConnection(authority, object(), {'provider': 'local', 'user_id': 'native',
+ 'profile_id': str(tmp_path), 'instance_id': 'first'})
+ resumed = await native.dispatch({'id': 1, 'method': 'session.resume', 'params': {'session_id': 'old-desktop'}})
+ assert resumed.get('result', {}).get('session_id') == 'old-desktop', resumed
+ assert [m['content'] for m in resumed['result']['messages']] == ['OLD-DESKTOP']
+ from gateway.config import Platform
+ assert runner.adapters[Platform.LOCAL].policies['old-desktop'].platform == 'desktop'
+ refused = await native.dispatch({'id': 2, 'method': 'session.resume', 'params': {'session_id': 'old-desktop-account'}})
+ assert 'error' in refused, refused
+ assert db.get_session('old-desktop-account')['user_id'] == 'nous:account'