1313
1414from ...boundary_authority import normalize_checkpointed_boundary_authority_entries
1515from ...file_lock import exclusive_file_lock
16+ from ...hosts .capabilities import NativeSessionFile
1617from ..runtime .private_permissions import protect_private_path
1718from ...runtime import validate_goal_id_path_segment
1819from ..content_digest import BARE_SHA256_PATTERN
3132_ABSENT_EXECUTOR_ADAPTER = object ()
3233
3334
35+ DEFAULT_NATIVE_SESSION_FILE = NativeSessionFile (".json" )
36+
37+
3438def _host_session_schema (host : str ) -> str :
3539 if host == "codex-cli" :
3640 return CODEX_CLI_SESSION_SCHEMA_VERSION
@@ -66,10 +70,8 @@ def _session_path(
6670 lineage : Mapping [str , str ],
6771 session_scope : str = "todo" ,
6872 * ,
69- ordinary_dsh : bool = False ,
73+ session_file : NativeSessionFile = DEFAULT_NATIVE_SESSION_FILE ,
7074) -> Path :
71- if ordinary_dsh and session_scope not in {"todo" , "agent" }:
72- raise ValueError ("ordinary DSH session binding requires Todo or Agent scope" )
7375 fields = session_identity_fields (session_scope )
7476 identity = (
7577 dict (lineage )
@@ -88,8 +90,7 @@ def _session_path(
8890 ).encode ("utf-8" )
8991 ).hexdigest ()
9092 goal_id : str = validate_goal_id_path_segment (lineage ["goal_id" ])
91- suffix = ".dsh-sdk.json" if ordinary_dsh else ".json"
92- return runtime_root / "goals" / goal_id / "turn-sessions" / f"{ digest } { suffix } "
93+ return runtime_root / "goals" / goal_id / "turn-sessions" / f"{ digest } { session_file .suffix } "
9394
9495
9596def _valid_session_id (value : Any ) -> str | None :
@@ -166,9 +167,9 @@ def _read_codex_cli_session_document(
166167 * ,
167168 lineage : Mapping [str , str ],
168169 session_scope : str = "todo" ,
169- ordinary_dsh : bool = False ,
170+ session_file : NativeSessionFile = DEFAULT_NATIVE_SESSION_FILE ,
170171) -> dict [str , Any ] | None :
171- path = _session_path (runtime_root , lineage , session_scope , ordinary_dsh = ordinary_dsh )
172+ path = _session_path (runtime_root , lineage , session_scope , session_file = session_file )
172173 if not path .exists ():
173174 return None
174175 try :
@@ -207,13 +208,18 @@ def codex_cli_session_binding(
207208 if work_contract is not _ABSENT_WORK_CONTRACT :
208209 request ["work_contract" ] = work_contract
209210 lineage = _lineage (request , session_scope = session_scope )
211+ session_file = DEFAULT_NATIVE_SESSION_FILE
212+ if ordinary_dsh :
213+ from ...hosts .dsh_capabilities import DSH_SDK_SESSION_FILE
214+
215+ session_file = DSH_SDK_SESSION_FILE
210216 session = select_codex_cli_session (
211217 runtime_root ,
212218 lineage = lineage ,
213219 session_scope = session_scope ,
214220 goal_admission = goal_admission ,
215221 host = host ,
216- ordinary_dsh = ordinary_dsh ,
222+ session_file = session_file ,
217223 )
218224 if session is None :
219225 return None
@@ -235,31 +241,32 @@ def _store_codex_cli_session(
235241 operation_profile_digest : str | None = None ,
236242 operation_model : str | None = None ,
237243 operation_reasoning_effort : str | None = None ,
238- ordinary_dsh : bool = False ,
244+ session_file : NativeSessionFile = DEFAULT_NATIVE_SESSION_FILE ,
239245 require_absent : bool = False ,
240246 checkpoint_artifact_sha256 : str | None = None ,
241247 checkpoint_artifact_root : str | None = None ,
242248 checkpoint_model_transition : Mapping [str , str ] | None = None ,
243249 expected_document : object = _UNCHECKED_SESSION_DOCUMENT ,
244250) -> None :
245- if ordinary_dsh and (
246- host != "dsh" or operation_profile_digest is not None
251+ session_file .require_host (host )
252+ if session_file .profile_host is not None and (
253+ operation_profile_digest is not None
247254 or not BARE_SHA256_PATTERN .fullmatch (session_profile_digest or "" )
248255 ):
249- raise ValueError ("ordinary DSH binding requires its own session profile" )
256+ raise ValueError ("native binding requires its own session profile" )
250257 if checkpoint_artifact_sha256 is not None and not BARE_SHA256_PATTERN .fullmatch (checkpoint_artifact_sha256 ):
251258 raise ValueError ("checkpoint session source digest is invalid" )
252259 if checkpoint_artifact_root is not None and (
253260 checkpoint_artifact_sha256 is None or not Path (checkpoint_artifact_root ).is_absolute () or
254261 str (Path (checkpoint_artifact_root ).resolve ()) != checkpoint_artifact_root ):
255262 raise ValueError ("checkpoint session source root must be physical and digest-bound" )
256- path = _session_path (runtime_root , lineage , session_scope , ordinary_dsh = ordinary_dsh )
263+ path = _session_path (runtime_root , lineage , session_scope , session_file = session_file )
257264 with exclusive_file_lock (path ):
258265 if require_absent and (path .exists () or path .is_symlink ()):
259266 raise ValueError ("session binding already exists; read back the original admission" )
260267 _host_session_schema (host )
261268 current = _read_codex_cli_session_document (
262- runtime_root , lineage = lineage , session_scope = session_scope , ordinary_dsh = ordinary_dsh ,
269+ runtime_root , lineage = lineage , session_scope = session_scope , session_file = session_file ,
263270 )
264271 if expected_document is not _UNCHECKED_SESSION_DOCUMENT and current != expected_document :
265272 raise ValueError ("session binding changed during native execution" )
@@ -301,7 +308,7 @@ def _store_codex_cli_session(
301308 operation_profile_digest = operation_profile_digest ,
302309 operation_model = operation_model ,
303310 operation_reasoning_effort = operation_reasoning_effort ,
304- ordinary_dsh = ordinary_dsh ,
311+ session_file = session_file ,
305312 checkpoint_artifact_sha256 = checkpoint_artifact_sha256 or retained_source ,
306313 checkpoint_artifact_root = checkpoint_artifact_root or retained_root ,
307314 checkpoint_context_refresh = retained_refresh ,
@@ -436,7 +443,7 @@ def _write_codex_cli_session(
436443 operation_profile_digest : str | None = None ,
437444 operation_model : str | None = None ,
438445 operation_reasoning_effort : str | None = None ,
439- ordinary_dsh : bool = False ,
446+ session_file : NativeSessionFile = DEFAULT_NATIVE_SESSION_FILE ,
440447 checkpoint_artifact_sha256 : str | None = None ,
441448 checkpoint_artifact_root : str | None = None ,
442449 checkpoint_context_refresh : dict [str , Any ] | None = None ,
@@ -451,7 +458,7 @@ def _write_codex_cli_session(
451458 normalized_session_id = _valid_session_id (session_id )
452459 if not normalized_session_id :
453460 raise ValueError ("Codex CLI returned an invalid session id" )
454- path = _session_path (runtime_root , lineage , session_scope , ordinary_dsh = ordinary_dsh )
461+ path = _session_path (runtime_root , lineage , session_scope , session_file = session_file )
455462 path .parent .mkdir (parents = True , exist_ok = True )
456463 protect_private_path (path .parent , directory = True )
457464 descriptor , temporary_name = tempfile .mkstemp (
@@ -532,7 +539,7 @@ def select_codex_cli_session(
532539 session_scope : str = "todo" ,
533540 host : str = "codex-cli" ,
534541 goal_admission : FirstPartyHostGoalAdmission | None = None ,
535- ordinary_dsh : bool = False ,
542+ session_file : NativeSessionFile = DEFAULT_NATIVE_SESSION_FILE ,
536543) -> dict [str , Any ] | None :
537544 """Select through the existing Goal lifetime fence, then validate identity.
538545
@@ -541,7 +548,7 @@ def select_codex_cli_session(
541548 """
542549 _ , binding = _select_codex_cli_session_snapshot (
543550 runtime_root , lineage = lineage , session_scope = session_scope , host = host ,
544- goal_admission = goal_admission , ordinary_dsh = ordinary_dsh ,
551+ goal_admission = goal_admission , session_file = session_file ,
545552 )
546553 return binding
547554
@@ -553,23 +560,22 @@ def _select_codex_cli_session_snapshot(
553560 session_scope : str = "todo" ,
554561 host : str = "codex-cli" ,
555562 goal_admission : FirstPartyHostGoalAdmission | None = None ,
556- ordinary_dsh : bool = False ,
563+ session_file : NativeSessionFile = DEFAULT_NATIVE_SESSION_FILE ,
557564 fresh : bool = False ,
558565) -> tuple [dict [str , Any ] | None , dict [str , Any ] | None ]:
559566 """Return the document read at selection and the binding qualified for reuse."""
560567 session_identity_fields (session_scope )
561568 _host_session_schema (host )
562- if ordinary_dsh and host != "dsh" :
563- raise ValueError ("ordinary DSH session binding requires the DSH host" )
569+ session_file .require_host (host )
564570
565571 def read () -> dict [str , Any ] | None :
566572 value = _read_codex_cli_session_document (
567573 runtime_root ,
568574 lineage = lineage ,
569575 session_scope = session_scope ,
570- ordinary_dsh = ordinary_dsh ,
576+ session_file = session_file ,
571577 )
572- if ordinary_dsh and value is not None :
578+ if session_file . profile_host is not None and value is not None :
573579 digest = value .get ("session_profile_digest" )
574580 if (not isinstance (digest , str ) or not BARE_SHA256_PATTERN .fullmatch (digest )
575581 or "operation_transport" in value ):
0 commit comments