Skip to content

The agent that grows with you

fix(gateway): canonical session info carries the reasoning effort and tier

Teknium53bf78841ef3
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index 02110f5c85d..575de0600ea 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -4511,6 +4511,10 @@ export interface CanonicalSessionInfo {
profile_name: string
cwd?: string | null
launch_request?: Record<string, unknown> | null
+ reasoning_effort?: string | null
+ reasoning_effort_wire?: string | null
+ service_tier?: string | null
+ fast?: boolean | null
[key: string]: unknown
}
export interface SessionDetachParams {
@@ -4769,6 +4773,10 @@ export interface CanonicalSnapshotInfo {
profile_name?: string | null
cwd?: string | null
launch_request?: Record<string, unknown> | null
+ reasoning_effort?: string | null
+ reasoning_effort_wire?: string | null
+ service_tier?: string | null
+ fast?: boolean | null
}
export interface CanonicalResumeParams {
profile?: string | null
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index 6b43d9062a1..b4474a5c5cd 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -9688,6 +9688,54 @@
],
"default": null,
"title": "Launch Request"
+ },
+ "reasoning_effort": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Reasoning Effort"
+ },
+ "reasoning_effort_wire": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Reasoning Effort Wire"
+ },
+ "service_tier": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Service Tier"
+ },
+ "fast": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Fast"
}
},
"required": [
@@ -10025,6 +10073,54 @@
],
"default": null,
"title": "Launch Request"
+ },
+ "reasoning_effort": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Reasoning Effort"
+ },
+ "reasoning_effort_wire": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Reasoning Effort Wire"
+ },
+ "service_tier": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Service Tier"
+ },
+ "fast": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Fast"
}
},
"required": [
diff --git a/gateway/session_local.py b/gateway/session_local.py
index f41d3aadf75..16a0d3f5e49 100644
--- a/gateway/session_local.py
+++ b/gateway/session_local.py
@@ -231,6 +231,36 @@ def _lazy_model(authority, policy):
return GUEST_MODEL if free_tier_route() else model
+def _reasoning_fields(agent, policy, model):
+ """Main's session-info effort/tier fields, from the built agent or (lazy) the frozen policy: a
+ resumed Desktop slice holds its reasoning pill pending until ``reasoning_effort`` arrives."""
+ from agent.fast_mode import STATIC_TIERS, parse_service_tier
+ from agent.reasoning_effort import clamp_effort, route_supported_efforts
+ from agent.voice_turn_route import session_runtime_view
+ from hermes_cli.models import resolve_fast_mode_overrides
+ if agent is None and policy is None:
+ return {}
+ view = session_runtime_view(agent) if agent is not None else None
+ config = getattr(view, 'reasoning_config', None) if view is not None else policy.reasoning_config
+ tier = (getattr(view, 'service_tier', None) if view is not None
+ else parse_service_tier((policy.config().get('agent') or {}).get('service_tier'))) or ''
+ provider = getattr(view, 'provider', None) if view is not None else policy.provider
+ base_url = getattr(view, 'base_url', None) if view is not None else policy.base_url
+ effort = ''
+ if isinstance(config, dict):
+ effort = 'none' if config.get('enabled') is False else str(config.get('effort') or '')
+ wire = ''
+ if effort and effort != 'none':
+ wire = str(clamp_effort(effort, route_supported_efforts(
+ provider, model, getattr(view, 'api_mode', None))) or '')
+ try:
+ fast = tier in STATIC_TIERS and resolve_fast_mode_overrides(
+ model, provider=provider or None, base_url=base_url or None, tier=tier) is not None
+ except Exception: # health: allow BLE001 -- main's _fast_tier_applies gate: unknown means not Fast
+ fast = False
+ return {'reasoning_effort': effort, 'reasoning_effort_wire': wire, 'service_tier': tier, 'fast': fast}
+
+
def local_session_info(authority, ref):
live = authority.sessions[ref.session_id]
agent = authority.agent(ref)
@@ -245,6 +275,7 @@ def local_session_info(authority, ref):
# Main's TUI labels a named profile's composer (``alpha ❯``) from this field.
'profile_name': served_profile_name(authority.profile_id),
**({'cwd': policy.cwd} if policy else {})}
+ info.update(_reasoning_fields(agent, policy, info['model']))
if policy:
# The creation request the route was frozen with (secrets already extracted), so a
# resuming client can tell "same flags again" from a real override attempt.
diff --git a/tests/gateway/test_canonical_resume_reasoning_snapshot.py b/tests/gateway/test_canonical_resume_reasoning_snapshot.py
new file mode 100644
index 00000000000..6e12ce36c3a
--- /dev/null
+++ b/tests/gateway/test_canonical_resume_reasoning_snapshot.py
@@ -0,0 +1,48 @@
+"""B22 / C-hx-3: a cold Desktop resume settles the reasoning pill from the canonical snapshot.
+
+Desktop marks a resumed slice's effort pending and clears it only on a string
+``info.reasoning_effort`` (main's session info always carried it with
+``reasoning_effort_wire`` / ``service_tier`` / ``fast``); a lazy canonical session must report the
+level its frozen policy will run, or the pill spins forever."""
+from types import SimpleNamespace
+
+import pytest
+
+
+async def test_lazy_session_info_reports_frozen_reasoning_and_tier(tmp_path, monkeypatch):
+ from gateway import run
+ from gateway.config import GatewayConfig
+ from gateway.session import SessionStore
+ from gateway.session_authority import initialize_session_authority
+ from gateway.session_controls import AuthorityConnection
+
+ home = tmp_path / 'home'
+ home.mkdir()
+ (home / 'config.yaml').write_text(
+ 'model: {default: gpt-5.4, provider: custom, base_url: "http://127.0.0.1:9/v1"}\n'
+ 'agent: {reasoning_effort: high, service_tier: fast}\nplatform_toolsets: {cli: []}\n')
+ monkeypatch.setenv('HERMES_HOME', str(home))
+ monkeypatch.setattr(run, '_hermes_home', home)
+ store = SessionStore(tmp_path / 'sessions', GatewayConfig())
+ runner = SimpleNamespace(session_store=store, _session_db=store._db, adapters={}, _draining=False,
+ _cached_agent_for=lambda route: None)
+ runner._adapter_for_source = lambda source: runner.adapters.get(source.platform)
+ authority = await initialize_session_authority(runner, profile_id=str(home), instance_id='first')
+ connection = AuthorityConnection(authority, object(), {'user_id': 'human'})
+
+ async def call(method, **params):
+ reply = await connection.dispatch({'id': 1, 'method': method, 'params': params})
+ assert 'result' in reply, reply
+ return reply['result']
+
+ created = await call('session.create', request_id='cold', source='gui', cwd=str(tmp_path))
+ sid = created['session_id']
+ for info in (created['info'], await call('session.info', session_id=sid),
+ (await call('session.resume', session_id=sid))['info']):
+ assert info['lazy'] is True
+ assert (info['reasoning_effort'], info['reasoning_effort_wire']) == ('high', 'high'), info
+ # A priority tier never reaches a custom endpoint, so the session must not claim Fast there.
+ assert (info['service_tier'], info['fast']) == ('priority', False), info
+ off = await call('session.create', request_id='off', source='gui', cwd=str(tmp_path), reasoning='none')
+ assert (off['info']['reasoning_effort'], off['info']['reasoning_effort_wire']) == ('none', '')
diff --git a/tui_gateway/contracts/canonical.py b/tui_gateway/contracts/canonical.py
index 1241a4bd47e..0c784ef3018 100644
--- a/tui_gateway/contracts/canonical.py
+++ b/tui_gateway/contracts/canonical.py
@@ -138,6 +138,10 @@ class CanonicalSessionInfo(OpenModel):
profile_name: str
cwd: str | None = None
launch_request: dict[str, JsonValue] | None = None
+ reasoning_effort: str | None = None
+ reasoning_effort_wire: str | None = None
+ service_tier: str | None = None
+ fast: bool | None = None
canonical_method("session.info", params=CanonicalSessionInfoParams, result=CanonicalSessionInfo,
diff --git a/tui_gateway/contracts/canonical_sessions.py b/tui_gateway/contracts/canonical_sessions.py
index 569195cf8a7..fd417f610a1 100644
--- a/tui_gateway/contracts/canonical_sessions.py
+++ b/tui_gateway/contracts/canonical_sessions.py
@@ -90,6 +90,10 @@ class CanonicalSnapshotInfo(Result):
profile_name: str | None = None
cwd: str | None = None
launch_request: dict[str, JsonValue] | None = None
+ reasoning_effort: str | None = None
+ reasoning_effort_wire: str | None = None
+ service_tier: str | None = None
+ fast: bool | None = None
class CanonicalSnapshot(Result):