1818from ..control_plane .quota .error_codes import QuotaCommandValidationError , QuotaDecisionTransportError
1919from ..control_plane .turn_driver .decision_capture import (
2020 validate_handoff_socket , CONTEXT_CAPTURE_READ_GUIDANCE , CONTEXT_CAPTURE_PAGE_GUIDANCE , context_capture_read_command ,
21- NATIVE_CONTEXT_PAGE_BYTES , NATIVE_CONTEXT_PAGE_OUTPUT_BYTES ,
21+ NATIVE_CONTEXT_PAGE_OUTPUT_BYTES ,
22+ native_context_page_budget ,
2223 read_context_capture_file as _read_capture ,
2324)
2425
@@ -35,7 +36,8 @@ def native_context_activation(args: argparse.Namespace) -> dict[str, Any]:
3536def _capture_page (path : Path , raw : bytes , digest : str , * , offset : int , size : int ,
3637 output_limit : int | None , instruction : bool ,
3738 presentation : dict [str , Any ] | None = None ,
38- next_page_bytes : int | None = None ) -> dict [str , Any ]:
39+ next_page_bytes : int | None = None ,
40+ next_page_output_bytes : int | None = None ) -> dict [str , Any ]:
3941 end = min (offset + size , len (raw ))
4042 while end < len (raw ) and raw [end ] & 0xC0 == 0x80 :
4143 end -= 1
@@ -50,7 +52,7 @@ def page(text: str) -> dict[str, Any]:
5052 result ["read_instruction" ] = CONTEXT_CAPTURE_PAGE_GUIDANCE
5153 if cursor < len (raw ):
5254 result ["next_command" ] = context_capture_read_command (path , digest , offset = cursor , page_bytes = next_page_bytes or size ,
53- max_page_output_bytes = output_limit )
55+ max_page_output_bytes = next_page_output_bytes or output_limit )
5456 return result
5557
5658 def fits (result : dict [str , Any ]) -> bool :
@@ -78,7 +80,8 @@ def fits(result: dict[str, Any]) -> bool:
7880
7981
8082def read_context_capture (args : argparse .Namespace , * , presentation : dict [str , Any ] | None = None ,
81- next_page_bytes : int | None = None ) -> dict [str , Any ]:
83+ next_page_bytes : int | None = None ,
84+ next_page_output_bytes : int | None = None ) -> dict [str , Any ]:
8285 """Bounded local IO over immutable JSON, not a new context/authority owner.
8386
8487 Verify the complete byte digest on every page. The cursor addresses bytes
@@ -120,7 +123,8 @@ def read_context_capture(args: argparse.Namespace, *, presentation: dict[str, An
120123 raise ValueError ("capture offset is outside the file or not a UTF-8 boundary; use the returned next offset" )
121124 return _capture_page (path , raw , digest , offset = offset , size = size ,
122125 output_limit = output_limit , instruction = bool (context_dir ),
123- presentation = presentation , next_page_bytes = next_page_bytes )
126+ presentation = presentation , next_page_bytes = next_page_bytes ,
127+ next_page_output_bytes = next_page_output_bytes )
124128 except (OSError , ValueError , RecursionError ) as exc :
125129 # Recovery is presentation-only: keep failures separate from quota's
126130 # collection error path and retain the existing receipt/capture.
@@ -147,8 +151,9 @@ def native_context_capture_view(projected: dict[str, Any], directory: Path, *,
147151 mode , target = projected ["mode" ], projected ["target" ]
148152 if mode == "full" :
149153 reference = {key : projected ["recovery" ][key ] for key in ("path" , "sha256" )}
154+ page_bytes , output_bytes = native_context_page_budget ()
150155 reference ["command" ] = context_capture_read_command (Path (reference ["path" ]), reference ["sha256" ],
151- page_bytes = NATIVE_CONTEXT_PAGE_BYTES , max_page_output_bytes = NATIVE_CONTEXT_PAGE_OUTPUT_BYTES )
156+ page_bytes = page_bytes , max_page_output_bytes = output_bytes )
152157 result = {"ok" : True , ** (metadata or {}), "mode" : mode , ** reference ,
153158 ** ({"target" : target } if target else {})}
154159 # The codec puts native continuity semantics before its change tree. Keep
@@ -167,7 +172,7 @@ def native_context_capture_view(projected: dict[str, Any], directory: Path, *,
167172 page = read_context_capture (argparse .Namespace (capture_file = reference ["path" ],
168173 capture_sha256 = reference ["sha256" ], offset = 0 , page_bytes = 3072 ,
169174 format = "json" , max_page_output_bytes = NATIVE_CONTEXT_PAGE_OUTPUT_BYTES ),
170- presentation = result , next_page_bytes = NATIVE_CONTEXT_PAGE_BYTES )
175+ presentation = result , next_page_bytes = page_bytes , next_page_output_bytes = output_bytes )
171176 if page ["ok" ]:
172177 result = page
173178 from ..control_plane .turn_driver .codex_context import register_native_context_view
@@ -482,7 +487,7 @@ def handle_native_context_command(args: argparse.Namespace, *, print_payload: Ca
482487 cli_argv = cli_argv , scenario = activation ["scenario" ], session_root = bool (getattr (args , "codex_context_root" , None )),
483488 inherit_machine = bool (machine_runtime ))
484489 payload = {"ok" : True , "context_delivery" : activation , "native_config" : config ,
485- "activation" : "Merge hooks and append developer_instructions to the existing native configuration; "
490+ "activation" : "Apply config_overrides, merge hooks and append developer_instructions to the existing native configuration; "
486491 "review and trust only these exact hooks in Codex. "
487492 "Existing loaded threads may retain their original hook configuration; enabled/trusted "
488493 "discovery is not session initialization or live adoption. Start/resume through the host "
@@ -492,7 +497,9 @@ def handle_native_context_command(args: argparse.Namespace, *, print_payload: Ca
492497 "Pass --context-delivery on with the same declared host mode, context location and a decision-output-root to heartbeat-prompt/should-run. " )
493498 +
494499 "Normal completed full reads establish an explicit continuity assumption; no input diagnostics or provider change is required. "
495- "Known invalidation or incomplete reads keep full recovery. Set --context-delivery off and remove context options to restore ordinary output. "
500+ "The generated output profile uses 64000-byte continuations and a 20000-token native history limit; "
501+ "unknown budgets retain small pages. Known invalidation or incomplete reads keep full recovery. "
502+ "Set --context-delivery off and remove the generated context configuration, including its output overrides, to restore ordinary output. "
496503 "This command installs nothing and grants no execution authority." }
497504 except (OSError , ValueError , TypeError ) as exc :
498505 payload = {"ok" : False , "reason" : str (exc )}
0 commit comments