Skip to content

The agent that grows with you

fix(gateway): an open that adopts a frozen Bot Chat keeps its committed /model

Tekniumfcb3505cfaee
diff --git a/gateway/session_local_migration.py b/gateway/session_local_migration.py
index e97e515b161..484be549e64 100644
--- a/gateway/session_local_migration.py
+++ b/gateway/session_local_migration.py
@@ -152,8 +152,9 @@ def follow_bot_chat(authority, session_id, policy, live, picked=()):
The caller is a client opening the chat (``session.resume``), which adopts it on the same rule
and composer pick as adoption above; *live* is the profile's config the open read. A request
that names ``follow_profile_config`` (``false`` included) is the client's own choice, and a
- bypass launch never reads the profile. The request is not rewritten. A committed ``/reasoning``
- (*picked*, the session's policy edits) stays the session's level, recorded as its session pin.
+ bypass launch never reads the profile. The request is not rewritten. A committed ``/model``
+ (*picked*, the session's policy edits) holds like a composer pick, and a committed ``/reasoning``
+ stays the session's level, recorded as its session pin.
The caller re-binds the private values without the followed sections, so a frozen key never
reaches the profile's route.
"""
@@ -174,8 +175,10 @@ def follow_bot_chat(authority, session_id, policy, live, picked=()):
return policy
live = present_sections(live)
config = json.loads(policy.config_json)
- if composer_pick_holds(owner, live):
+ model = config.get('model') if isinstance(config.get('model'), dict) else {}
+ if composer_pick_holds(owner, live) or ('model' in picked and model.get('selection_profile') is None):
# Recorded the way a create records a pick: it holds until the profile's model or provider moves.
+ # A ``/model`` committed while the chat was frozen is such a pick too (its receipt, in *picked*).
config.setdefault('model', {})['selection_profile'] = list(profile_target(live))
pins = config.get(SESSION_PINS) if isinstance(config.get(SESSION_PINS), dict) else {}
if 'reasoning' in picked and not isinstance(pins.get('reasoning'), bool):
diff --git a/hermes_state_mutation_prepared.py b/hermes_state_mutation_prepared.py
index 3ea0f15554a..68c9352c6a9 100644
--- a/hermes_state_mutation_prepared.py
+++ b/hermes_state_mutation_prepared.py
@@ -93,14 +93,14 @@ _RECEIPTS = "FROM state_meta WHERE key GLOB 'gateway.mutation.v1.*' AND json_val
def picks_on(conn, session_id, before=None):
- """The policy edits (``reasoning``, ``workspace``) a ``session.mutate`` committed for *session_id* (below
+ """The policy edits (``model``, ``reasoning``, ``workspace``) a ``session.mutate`` committed for *session_id* (below
revision *before*): their receipts (kept for exact retries, also past deletion) are the durable record of
the user's pick. A branch copied its parent's policy, picks included, under its own id: its local
receipt's ``picks``; a branch stored before that field has its parent's as they stood at its branch."""
bound = '' if before is None else " AND json_extract(value, '$.result.revision')<?"
picked = {row[0] for row in conn.execute(
"SELECT DISTINCT json_extract(value, '$.result.operation') " + _RECEIPTS +
- "AND json_extract(value, '$.result.operation') IN ('reasoning', 'workspace') "
+ "AND json_extract(value, '$.result.operation') IN ('model', 'reasoning', 'workspace') "
"AND json_extract(value, '$.result.session_id')=?" + bound, (session_id, *(() if before is None else (before,))))}
saved = conn.execute('SELECT value FROM state_meta WHERE key=?', (POLICY_PREFIX + session_id,)).fetchone()
if saved is None:
diff --git a/tests/gateway/test_session_mutation_model_route.py b/tests/gateway/test_session_mutation_model_route.py
index 7b1a7575c91..d1460153ecf 100644
--- a/tests/gateway/test_session_mutation_model_route.py
+++ b/tests/gateway/test_session_mutation_model_route.py
@@ -390,3 +390,28 @@ async def test_a_level_picked_with_the_model_survives_a_profile_edit_and_a_resum
finally:
await owner.close()
store.close_all_db_handles()
+
+
+async def test_a_model_committed_on_a_frozen_bot_chat_holds_when_an_open_adopts_it(home, endpoints):
+ """A ``/model`` the user committed while the Bot Chat was frozen is the session's pick: the open that
+ adopts the chat keeps it (like a composer pick) until the profile itself moves."""
+ from tests.gateway.test_bot_chat_follows_profile import _follows, _frozen_bot_chat, _open
+ (_, url), _ = endpoints
+ _configure(home, 'original', url, 'key-a')
+ store, runner, authority, owner = _owner(home)
+ _bind_resolver(runner)
+ try:
+ ref, _params = _frozen_bot_chat(authority, owner.actor, home)
+ live = authority.sessions[ref.session_id]
+ response = await _pick(owner, authority, ref.session_id, {'model': 'picked', 'provider': 'custom'})
+ assert 'result' in response, response
+ assert not _follows(runner, live) and _route(runner, live)[0] == 'picked'
+ await _open(authority, ref)
+ assert _follows(runner, live)
+ assert _route(runner, live) == ('picked', url, 'key-a')
+ _configure(home, 'current', url, 'key-a') # the profile moves: the pick ends
+ assert _route(runner, live) == ('current', url, 'key-a')
+ finally:
+ await owner.close()
+ store.close_all_db_handles()