The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(api): adopt legacy declared session keys
KoNit-K9e82766ad862
diff --git a/gateway/session_api.py b/gateway/session_api.pyindex dacaace49d1..5f945f1ff15 100644--- a/gateway/session_api.py+++ b/gateway/session_api.py@@ -160,7 +160,9 @@ def bind_api_steps(authority, session_id, *, hosted_dispatch=None, declared_key=raise RuntimeStoreError('admission_conflict')if conn.execute('SELECT 1 FROM sessions WHERE title=? AND id!=?', (title, session_id)).fetchone():raise RuntimeStoreError('admission_conflict')- if row is not None and row['session_key'] not in (None, '', route):+ # Earlier API releases stored the caller-declared key directly on the session row.+ # The declared-key registry above proves that this caller still owns that legacy value.+ if row is not None and row['session_key'] not in (None, '', route, declared_key):raise RuntimeStoreError('admission_conflict')existing = conn.execute("SELECT entry_json FROM gateway_routing WHERE scope='' AND session_key=?",(route,)).fetchone()diff --git a/tests/gateway/test_api_source_binding.py b/tests/gateway/test_api_source_binding.pyindex 4ac8b10853d..9fb52f02738 100644--- a/tests/gateway/test_api_source_binding.py+++ b/tests/gateway/test_api_source_binding.py@@ -26,6 +26,24 @@ def test_private_api_binding_restores_exact_route(owner):assert 'foreign-native' not in owner.sessions+def test_private_api_binding_adopts_matching_legacy_declared_key(owner):+ """Regression for #139835: a pre-binding API row stores the caller's declared key."""+ from gateway.session_api import bind_api_session, declared_api_session++ session_id = 'legacy-api-session'+ declared_key = 'webui:legacy-api-session'+ owner.db.create_session(session_id, source='api_server')+ owner.db.record_gateway_session_peer(session_id, source='api_server', session_key=declared_key)++ ref = bind_api_session(owner, session_id, declared_key=declared_key)++ row = owner.db.get_session(session_id)+ assert row['session_key'] == owner.sessions[ref.session_id].route+ assert declared_api_session(owner.db, declared_key) == session_id+ with pytest.raises(RuntimeStoreError, match='admission_conflict'):+ bind_api_session(owner, 'other-api-session', declared_key=declared_key)++@pytest.mark.asyncioasync def test_private_api_binding_is_not_public_submission_authority(owner):from gateway.session_api import bind_api_session