The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(state): adopt a remote-backend desktop row stamped with a login label
liuhao102487d8f6889ef9
diff --git a/hermes_state_local_migration.py b/hermes_state_local_migration.pyindex beb42b989b3..8bbcfd7c1b8 100644--- a/hermes_state_local_migration.py+++ b/hermes_state_local_migration.py@@ -18,10 +18,23 @@ LEGACY_CREATION_SOURCES = {'desktop': 'gui'}def legacy_account_label(row):- # main's Desktop stamped the signed-in Nous account on its chats. That is a label, not a route or- # an authenticated owner, so it does not block adoption of an otherwise unrouted Desktop row.+ # main's Desktop stamped the signed-in Nous account on its chats, and a served remote backend+ # stamps the WS-upgrade login the same way ("<provider>:<user id>"; tui_gateway/session_transports).+ # Either is a creation-time label, not a route or an authenticated owner, so neither blocks+ # adoption of an otherwise unrouted Desktop row. A prefix naming a messaging platform is+ # different: it is that platform's real foreign identity, so only that stays an owner.user_id = row.get('user_id')- return row['source'] == 'desktop' and isinstance(user_id, str) and user_id.startswith('nous:')+ if row['source'] != 'desktop' or not isinstance(user_id, str) or ':' not in user_id:+ return False+ provider, _ = user_id.split(':', 1)+ if provider == 'nous':+ return True+ from gateway.config import Platform+ try:+ platform = Platform(provider)+ except ValueError:+ return True # a login provider (basic auth, OIDC, ...) labels its user; no platform identity+ return platform in (Platform.LOCAL, Platform.API_SERVER)def validate_legacy_row(db, row):diff --git a/tests/gateway/test_legacy_desktop_source.py b/tests/gateway/test_legacy_desktop_source.pyindex 44e21e72c80..3ae2aac259a 100644--- a/tests/gateway/test_legacy_desktop_source.py+++ b/tests/gateway/test_legacy_desktop_source.py@@ -1,8 +1,9 @@"""Every old local row the native resume adopts also takes a sidebar edit (#106742).-The resume adopts main's ``desktop`` chats (including those stamped with the signed-in Nous account)-and ``oneshot``/``tool`` CLI runs, but ``authorize_history`` (pin/archive/hide/rename) only knew-``cli``/``tui``/``gui``, so the same rows answered ``permission_denied`` on every sidebar edit.+The resume adopts main's ``desktop`` chats (including those stamped with the signed-in Nous+account or with a served remote backend's login label) and ``oneshot``/``tool`` CLI runs, but+``authorize_history`` (pin/archive/hide/rename) only knew ``cli``/``tui``/``gui``, so the same+rows answered ``permission_denied`` on every sidebar edit."""from gateway.session_contract import Principalfrom hermes_state import SessionDB@@ -15,12 +16,15 @@ def test_rows_the_resume_adopts_take_sidebar_edits(tmp_path):try:for sid, source, user_id in (('old-desktop', 'desktop', None), ('old-oneshot', 'oneshot', None),('old-desktop-nous', 'desktop', 'nous:account'),+ ('old-desktop-remote', 'desktop', 'basic:hermes'),+ ('old-desktop-oidc', 'desktop', 'oidc:alice'),('old-desktop-foreign', 'desktop', 'telegram:42'),('old-cli-nous', 'cli', 'nous:account'), ('api-row', 'api_server', None)):db.create_session(sid, source=source, user_id=user_id)actor = Principal('uid:1', str(tmp_path), frozenset({'session:read', 'session:create'}), 'native-http:x')with db._read_ctx() as conn:- for sid in ('old-desktop', 'old-oneshot', 'old-desktop-nous'):+ for sid in ('old-desktop', 'old-oneshot', 'old-desktop-nous', 'old-desktop-remote',+ 'old-desktop-oidc'):validate_legacy_row(db, db.get_session(sid)) # the resume adopts it ...assert authorize_history(conn, actor, sid) is True, sid # ... so it takes an edit.assert same_history_owner(conn, 'old-desktop', 'old-desktop-nous') is Truediff --git a/tests/gateway/test_legacy_session_migration.py b/tests/gateway/test_legacy_session_migration.pyindex 0bdc0098fa8..75c12727388 100644--- a/tests/gateway/test_legacy_session_migration.py+++ b/tests/gateway/test_legacy_session_migration.py@@ -180,7 +180,8 @@ async def test_upgraded_oneshot_and_tool_history_resumes_by_id_and_title_but_staasync 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 owneradopts them by id like ``gui`` history, including the ones stamped with the signed-in Nous- account. Any other identity still needs its own authority."""+ account or with a served remote backend's login label (``hermes serve`` basic auth). Any other+ identity still needs its own authority."""from gateway import runfrom gateway.config import GatewayConfigfrom gateway.session import SessionStore@@ -191,7 +192,8 @@ async def test_upgraded_desktop_history_resumes_by_id(tmp_path, monkeypatch):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')):+ for sid, user_id in (('old-desktop', None), ('old-desktop-account', 'nous:account'),+ ('old-desktop-remote', 'basic:hermes')):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')@@ -209,6 +211,11 @@ async def test_upgraded_desktop_history_resumes_by_id(tmp_path, monkeypatch):stamped = await native.dispatch({'id': 2, 'method': 'session.resume', 'params': {'session_id': 'old-desktop-account'}})assert stamped.get('result', {}).get('session_id') == 'old-desktop-account', stampedassert [m['content'] for m in stamped['result']['messages']] == ['OLD-DESKTOP-ACCOUNT']+ # A served remote backend stamped its basic-auth principal on the row at creation; that login+ # is a label, so the local native owner adopts the row once its hosting serve is gone (#139818).+ remote = await native.dispatch({'id': 4, 'method': 'session.resume', 'params': {'session_id': 'old-desktop-remote'}})+ assert remote.get('result', {}).get('session_id') == 'old-desktop-remote', remote+ assert [m['content'] for m in remote['result']['messages']] == ['OLD-DESKTOP-REMOTE']# Any other identity, or a Nous stamp on a non-Desktop row, still needs its own authority.for sid, source, user_id in (('old-desktop-foreign', 'desktop', 'telegram:42'),('old-cli-account', 'cli', 'nous:account')):