1212if str (REPO_ROOT ) not in sys .path :
1313 sys .path .insert (0 , str (REPO_ROOT ))
1414
15- from loopx .control_plane .quota .turn_envelope import build_turn_envelope # noqa: E402
15+ from loopx .control_plane .quota .turn_envelope import compose_turn_decision # noqa: E402
1616from loopx .control_plane .scheduler .execution_context import ( # noqa: E402
1717 SchedulerRuntimeProfile ,
1818 scheduler_execution_context_for_runtime_profile ,
@@ -357,14 +357,15 @@ def main() -> int:
357357 "coordinator_agent_id"
358358 ] == coordinator , reversed_decision
359359
360+ codex_context = scheduler_execution_context_for_runtime_profile (
361+ SchedulerRuntimeProfile .CODEX_CLI_VISIBLE
362+ )
360363 adaptive_decision = build_quota_should_run (
361364 adaptive_payload (),
362365 goal_id = GOAL_ID ,
363366 agent_id = "codex-alpha" ,
364367 available_capabilities = ["subagent_spawn" , "subagent_resume" ],
365- scheduler_execution_context = scheduler_execution_context_for_runtime_profile (
366- SchedulerRuntimeProfile .CODEX_CLI_VISIBLE
367- ),
368+ scheduler_execution_context = codex_context ,
368369 )
369370 adaptive_contract = adaptive_decision ["task_orchestration_contract" ]
370371 assert adaptive_contract ["schema_version" ] == "task_orchestration_contract_v2"
@@ -387,24 +388,26 @@ def main() -> int:
387388 goal_id = GOAL_ID ,
388389 agent_id = "codex-alpha" ,
389390 available_capabilities = ["subagent_spawn" , "subagent_resume" ],
390- scheduler_execution_context = scheduler_execution_context_for_runtime_profile (
391- SchedulerRuntimeProfile .CODEX_CLI_VISIBLE
392- ),
391+ scheduler_execution_context = codex_context ,
393392 )
394393 unrestricted_contract = unrestricted_decision ["task_orchestration_contract" ]
395394 assert unrestricted_contract ["mode" ] == "adaptive"
396395 assert unrestricted_contract ["eligible_child_lanes" ][0 ]["todo_id" ] == (
397396 "todo_validation"
398397 )
399398
400- turn_envelope = build_turn_envelope (adaptive_decision )
401- assert turn_envelope ["action_signature" ]["matches" ] is True
399+ codex_contract = compose_turn_decision (
400+ adaptive_decision , scheduler_execution_context = codex_context , composed_settlement = True
401+ )
402402 codex_plan = build_loopx_turn_plan (
403- turn_envelope ,
403+ codex_contract ,
404404 host = "codex-cli" ,
405405 execution_mode = "interactive-visible" ,
406406 )
407407 codex_request = build_loopx_turn_host_request (codex_plan )
408+ assert codex_plan ["route" ]["selected_todo" ]["todo_id" ] == "todo_primary"
409+ assert codex_request ["work_contract" ] == codex_contract
410+ assert "turn_envelope" not in codex_plan and "turn_envelope" not in codex_request
408411 assert [
409412 item for item in codex_request ["child_operations" ][0 ]["available_contexts" ]
410413 ] == ["fresh" ]
@@ -415,22 +418,30 @@ def main() -> int:
415418 "requires_session" : False ,
416419 }
417420
421+ claude_context = scheduler_execution_context_for_runtime_profile (
422+ SchedulerRuntimeProfile .CLAUDE_CODE_VISIBLE
423+ )
418424 claude_decision = build_quota_should_run (
419425 adaptive_payload (),
420426 goal_id = GOAL_ID ,
421427 agent_id = "codex-alpha" ,
422428 available_capabilities = ["subagent_spawn" ],
423- scheduler_execution_context = scheduler_execution_context_for_runtime_profile (
424- SchedulerRuntimeProfile .CLAUDE_CODE_VISIBLE
425- ),
429+ scheduler_execution_context = claude_context ,
430+ )
431+ claude_contract = compose_turn_decision (
432+ claude_decision , scheduler_execution_context = claude_context , composed_settlement = True
426433 )
427434 claude_plan = build_loopx_turn_plan (
428- build_turn_envelope ( claude_decision ) ,
435+ claude_contract ,
429436 host = "claude-code" ,
430437 execution_mode = "interactive-visible" ,
431438 )
432- assert claude_plan ["child_operations" ][0 ]["available_contexts" ] == ["fresh" ]
433- assert claude_plan ["child_operations" ][0 ]["host_adapter" ] == {
439+ claude_request = build_loopx_turn_host_request (claude_plan )
440+ assert claude_plan ["route" ]["selected_todo" ]["todo_id" ] == "todo_primary"
441+ assert claude_request ["work_contract" ] == claude_contract
442+ assert "turn_envelope" not in claude_plan and "turn_envelope" not in claude_request
443+ assert claude_request ["child_operations" ][0 ]["available_contexts" ] == ["fresh" ]
444+ assert claude_request ["child_operations" ][0 ]["host_adapter" ] == {
434445 "host" : "claude-code" ,
435446 "native_operation" : "Task" ,
436447 "arguments" : {},
0 commit comments