77from hashlib import sha256
88from typing import Any
99
10+ from ...hosts .capabilities import get_builtin_host_capabilities
1011from ..agent_context import envelope_agent_context
1112from ..effect_program import SettlementIdentity
1213from ..effect_runtime import EffectRuntimeRejected
@@ -454,7 +455,10 @@ def resolve_turn_session_scope(
454455 expected_replan_obligation_id : str | None = None ,
455456) -> str :
456457 """Select conversation session scope shared between planning and launch recheck."""
457- if host in {"codex-cli" , "codex-app-server" }:
458+ capabilities = get_builtin_host_capabilities (host ) if host in SUPPORTED_HOSTS else None
459+ if capabilities is None or not capabilities .supports ("session_identity_binding" ):
460+ return SessionBindingScope .TODO .value
461+ if capabilities .supports ("managed_thread_resume" ):
458462 if delegated_request :
459463 return SessionBindingScope .AGENT .value
460464 if not codex_operation_tools :
@@ -465,8 +469,7 @@ def resolve_turn_session_scope(
465469 )
466470 return SessionBindingScope .TODO .value
467471 if (
468- host == "dsh"
469- and not dsh_operation_module
472+ not dsh_operation_module
470473 and not dsh_runner
471474 and requested_session_scope != SessionBindingScope .TODO .value
472475 and decision is not None
@@ -480,9 +483,9 @@ def resolve_turn_session_scope(
480483 return SessionBindingScope .TODO .value
481484
482485
483- def _validate_dsh_agent_session_scope (
486+ def _validate_agent_session_scope (
484487 * ,
485- host : str ,
488+ native_thread_resume : bool ,
486489 session_scope : str ,
487490 current : bool ,
488491 projection : Mapping [str , Any ],
@@ -492,7 +495,7 @@ def _validate_dsh_agent_session_scope(
492495 settlement_identity : SettlementIdentity | None ,
493496 envelope : Mapping [str , Any ],
494497) -> None :
495- if host != "dsh" or session_scope == "todo" :
498+ if native_thread_resume or session_scope == "todo" :
496499 return
497500 raw_route = LoopXTurnRoute (projection ["route" ]) if contract_error is None else LoopXTurnRoute .CONTRACT_ERROR
498501 if not (
@@ -539,10 +542,13 @@ def build_loopx_turn_plan(
539542 raise ValueError (
540543 "iteration context policy must be fresh or resume"
541544 )
545+ capabilities = get_builtin_host_capabilities (host )
546+ flags = capabilities .supported_capabilities if capabilities is not None else ()
547+ native_thread_resume = "managed_thread_resume" in flags
542548 if session_scope is None :
543- session_scope = "agent" if host in { "codex-cli" , "codex-app-server" } else "todo"
549+ session_scope = "agent" if native_thread_resume else "todo"
544550 session_identity_fields (session_scope )
545- if session_scope != "todo" and host not in { "codex-cli" , "codex-app-server" , "dsh" } :
551+ if session_scope != "todo" and "session_identity_binding" not in flags :
546552 raise ValueError ("agent session scope requires a Codex conversation host" )
547553
548554 execution_context = scheduler_execution_context_for_turn (
@@ -615,8 +621,8 @@ def build_loopx_turn_plan(
615621 settlement_identity .request_subject is not None and iteration_context_policy == "fresh"
616622 )):
617623 route = LoopXTurnRoute .BLOCKED
618- _validate_dsh_agent_session_scope (
619- host = host ,
624+ _validate_agent_session_scope (
625+ native_thread_resume = native_thread_resume ,
620626 session_scope = session_scope ,
621627 current = current ,
622628 projection = projection ,
0 commit comments