The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(sessions): pre-fence Desktop writes get a named client_upgrade_required
Teknium3cdcd412d47a
diff --git a/hermes_cli/web_server_sessions.py b/hermes_cli/web_server_sessions.pyindex fd6eddc6d3c..386cbb38322 100644--- a/hermes_cli/web_server_sessions.py+++ b/hermes_cli/web_server_sessions.py@@ -32,6 +32,12 @@ _DESCENDANTS_SQL = f""""""+# Desktop 0.22.2's ``readableError`` keeps the HTTP ``detail`` and shows its "app and backend are+# on different versions" toast (with an Update action) for "out of sync (different versions)".+CLIENT_UPGRADE_REQUIRED = ('client_upgrade_required: this app is out of sync (different versions) '+ 'with the Hermes backend; update the app to edit sessions')++def _session_latest_descendant(session_id: str, db):"""Resolve a session id to the newest child leaf session.@@ -194,6 +200,11 @@ async def _mutate_session_request(request, profile, session_id, *, request_id,_, errors = authority.db._validate_import_payload(payload['sessions'])if errors:raise HTTPException(status_code=400, detail={'errors': errors})+ if request_id is None and expected_revision is None and expected_generation is None:+ # A pre-fence client (Desktop <= 0.22.2) sends none of the identity. The owner never+ # commits an unfenced write, so name the upgrade; the wording is what those builds'+ # toast summariser maps to "different versions, update" (#139742).+ raise HTTPException(status_code=409, detail=CLIENT_UPGRADE_REQUIRED)if request_id is None or expected_revision is None:raise HTTPException(status_code=409, detail='mutation_identity_required')params = dict(session_id=session_id, request_id=request_id, expected_revision=expected_revision,diff --git a/tests/hermes_cli/test_session_mutation_legacy_client.py b/tests/hermes_cli/test_session_mutation_legacy_client.pynew file mode 100644index 00000000000..03064a9c9e6--- /dev/null+++ b/tests/hermes_cli/test_session_mutation_legacy_client.py@@ -0,0 +1,59 @@+"""A pre-fence client (Desktop 0.22.2) gets a named upgrade refusal it can render (#139742).++0.22.2's session PATCH/DELETE carry no ``request_id``/``expected_revision``. The owner never+commits an unfenced write (the revision boundary holds on every transport), so it refuses with+``client_upgrade_required``, worded so 0.22.2's own toast summariser (``readableError`` ->+``rpcOutOfSync``, ``apps/desktop/src/store/notifications.ts`` at v0.22.2) shows "The app and the+backend are on different versions. Update both." with its Update action instead of a raw code.+"""+import re++import httpx+import pytest+from fastapi import FastAPI++from hermes_cli.web_routers.sessions import manage_router+from hermes_state import SessionDB++AUTH = {'Authorization': 'Bearer legacy-token'}+# Verbatim from v0.22.2: notifications.ts ``readableError`` and gateway-rpc.ts ``isOutOfSyncRpcParams``.+_DETAIL_RE = re.compile(r'"detail"\s*:\s*"([^"]+)"')+_OUT_OF_SYNC_RE = re.compile(r'out of sync \(different versions\)', re.IGNORECASE)+++def _app(tmp_path, monkeypatch):+ from hermes_cli import web_server+ monkeypatch.setattr(web_server, '_SESSION_TOKEN', 'legacy-token')+ monkeypatch.setattr('hermes_state._default_db_path', lambda: tmp_path / 'state.db')+ monkeypatch.setenv('HERMES_HOME', str(tmp_path))+ app = FastAPI()+ app.include_router(manage_router)+ return app+++def _renders_as_upgrade(response):+ # Electron's httpStatusError builds ``f"{status}: {body}"``; the renderer reads it back.+ message = f'{response.status_code}: {response.text}'+ detail = _DETAIL_RE.search(message).group(1)+ return detail.startswith('client_upgrade_required') and bool(_OUT_OF_SYNC_RE.search(detail))+++async def test_identityless_legacy_writes_get_a_renderable_upgrade_refusal(tmp_path, monkeypatch):+ app = _app(tmp_path, monkeypatch)+ with SessionDB(db_path=tmp_path / 'state.db') as db:+ db.create_session('old-desktop', source='desktop')+ async with httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url='http://localhost',+ headers=AUTH) as client:+ # The exact 0.22.2 shapes: setSessionArchived / renameSession / deleteSession.+ for response in (await client.patch('/api/sessions/old-desktop', json={'archived': True}),+ await client.patch('/api/sessions/old-desktop', json={'title': 'New'}),+ await client.delete('/api/sessions/old-desktop')):+ assert response.status_code == 409, response.text+ assert _renders_as_upgrade(response), response.text+ # A current client that sent only half the identity is a client bug, not an old app.+ partial = await client.patch('/api/sessions/old-desktop', json={'request_id': 'r', 'title': 'X'})+ assert (partial.status_code, partial.json()['detail']) == (409, 'mutation_identity_required')+ row = db.get_session('old-desktop')+ assert row is not None and row['title'] is None and not row.get('archived')+ assert row['runtime_revision'] == 0diff --git a/website/docs/user-guide/features/web-dashboard.md b/website/docs/user-guide/features/web-dashboard.mdindex 615fe36e5c7..a4dc957b086 100644--- a/website/docs/user-guide/features/web-dashboard.md+++ b/website/docs/user-guide/features/web-dashboard.md@@ -538,8 +538,9 @@ Full-text search across message content. Query parameter: `q`. Returns matchingDeletes a session and its message history. The request must carry the mutation identitythe client read from `GET /api/sessions/{id}/mutation-snapshot` (`request_id`,-`expected_revision`, and `expected_generation`); without it the route answers `409-mutation_identity_required`. The delete is executed by the profile's gateway, so a+`expected_revision`, and `expected_generation`); a partial identity is answered `409+mutation_identity_required`, and a request with none of it (Desktop 0.22.2 and older) `409+client_upgrade_required` — the backend never applies an edit without the revision fence. The delete is executed by the profile's gateway, so asession with a running or queued turn is refused with `409 session_busy` and one whoselast turn was lost across a gateway restart with `409 unknown_execution` — nothing isremoved in either case. Deleting a session that has executed turns leaves small