Skip to content

The agent that grows with you

fix(gateway): resolve short local resume hints

KoNit-K6ed2993a6801
diff --git a/gateway/session_controls.py b/gateway/session_controls.py
index ea3cdba48eb..c437a5e7b34 100644
--- a/gateway/session_controls.py
+++ b/gateway/session_controls.py
@@ -510,6 +510,14 @@ class AuthorityConnection:
from gateway.session_local_title import resolve_titled_session
ref = resolve_titled_session(self.authority, self.actor, params['title'])
else:
+ # The TUI exit hint abbreviates canonical local IDs to ``local-`` plus 16 hex
+ # characters. Resolve only that family before authorization so a unique hint reaches
+ # the same durable local route as its full ID; ambiguous and missing prefixes retain
+ # the normal not_found result.
+ if re.fullmatch(r'local-[0-9a-f]{16}', ref.session_id):
+ resolved_id = self.authority.db.resolve_session_id(ref.session_id)
+ if resolved_id is not None:
+ ref = SessionRef(ref.profile_id, resolved_id)
from gateway.session_local_migration import resolve_local_target
from gateway.session_policy_refresh import refresh_settled
from hermes_state_local_migration import LEGACY_LOCAL_SOURCES
diff --git a/tests/gateway/test_session_local_reopen_on_turn.py b/tests/gateway/test_session_local_reopen_on_turn.py
index 4d59f3a82f0..a90d17925fa 100644
--- a/tests/gateway/test_session_local_reopen_on_turn.py
+++ b/tests/gateway/test_session_local_reopen_on_turn.py
@@ -42,6 +42,38 @@ async def test_resuming_a_finalized_local_session_leaves_it_ended(tmp_path, monk
authority.db.close()
+async def test_resume_accepts_the_unique_22_character_local_hint(tmp_path, monkeypatch):
+ authority, connection, ref = await _ended_local_session(tmp_path, monkeypatch)
+ try:
+ hint = ref.session_id[:22]
+ assert hint.startswith('local-') and len(hint) == 22
+
+ reply = await connection.dispatch({'id': 1, 'method': 'session.resume',
+ 'params': {'session_id': hint}})
+
+ assert reply['result']['session_id'] == ref.session_id
+ finally:
+ await connection.close()
+ authority.db.close()
+
+
+async def test_resume_rejects_ambiguous_or_missing_local_hints(tmp_path, monkeypatch):
+ authority, connection, ref = await _ended_local_session(tmp_path, monkeypatch)
+ try:
+ hint = ref.session_id[:22]
+ authority.db.create_session(ref.session_id[:-1] + ('0' if ref.session_id[-1] != '0' else '1'), 'local')
+
+ for candidate in (hint, 'local-', 'local-' + 'f' * 16):
+ reply = await connection.dispatch({'id': candidate, 'method': 'session.resume',
+ 'params': {'session_id': candidate}})
+ assert reply['error']['data']['reason'] == 'not_found'
+ finally:
+ await connection.close()
+ authority.db.close()
+
+
@pytest.mark.asyncio
async def test_first_admitted_turn_reopens_a_finalized_local_session_before_execution(tmp_path, monkeypatch):
authority, connection, ref = await _ended_local_session(tmp_path, monkeypatch)