@@ -4529,6 +4529,85 @@ async fn auto_compact_counts_encrypted_reasoning_before_last_user() {
45294529 ) ;
45304530}
45314531
4532+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
4533+ async fn auto_compact_preserves_reasoning_header_for_next_pre_turn_check ( ) {
4534+ skip_if_no_network ! ( ) ;
4535+
4536+ let server = start_mock_server ( ) . await ;
4537+
4538+ let pre_last_reasoning_content = "a" . repeat ( 2_400 ) ;
4539+ let post_last_reasoning_content = "b" . repeat ( 4_000 ) ;
4540+
4541+ let first_turn = sse ( vec ! [
4542+ ev_reasoning_item( "pre-reasoning" , & [ "pre" ] , & [ & pre_last_reasoning_content] ) ,
4543+ ev_completed_with_tokens( "r1" , /*total_tokens*/ 10 ) ,
4544+ ] ) ;
4545+ let second_turn = sse ( vec ! [
4546+ ev_reasoning_item( "post-reasoning" , & [ "post" ] , & [ & post_last_reasoning_content] ) ,
4547+ ev_completed_with_tokens( "r2" , /*total_tokens*/ 80 ) ,
4548+ ] ) ;
4549+ let third_turn = sse ( vec ! [
4550+ ev_assistant_message( "m4" , FINAL_REPLY ) ,
4551+ ev_completed_with_tokens( "r4" , /*total_tokens*/ 1 ) ,
4552+ ] ) ;
4553+
4554+ let responses = vec ! [
4555+ sse_response( first_turn) . insert_header( "X-Reasoning-Included" , "true" ) ,
4556+ sse_response( second_turn) . insert_header( "X-Reasoning-Included" , "true" ) ,
4557+ sse_response( third_turn) . insert_header( "X-Reasoning-Included" , "true" ) ,
4558+ ] ;
4559+ mount_response_sequence ( & server, responses) . await ;
4560+
4561+ let compact_mock = mount_compact_json_once (
4562+ & server,
4563+ serde_json:: json!( {
4564+ "output" : [ {
4565+ "type" : "compaction" ,
4566+ "encrypted_content" : "UNEXPECTED_COMPACTION" ,
4567+ } ] ,
4568+ } ) ,
4569+ )
4570+ . await ;
4571+
4572+ let codex = test_codex ( )
4573+ . with_auth ( CodexAuth :: create_dummy_chatgpt_auth_for_testing ( ) )
4574+ . with_config ( |config| {
4575+ set_test_compact_prompt ( config) ;
4576+ config. model_auto_compact_token_limit = Some ( 300 ) ;
4577+ let _ = config. features . disable ( Feature :: RemoteCompactionV2 ) ;
4578+ } )
4579+ . build ( & server)
4580+ . await
4581+ . expect ( "build codex" )
4582+ . codex ;
4583+
4584+ for user in [
4585+ "SERVER_INCLUDED_FIRST" ,
4586+ "SERVER_INCLUDED_SECOND" ,
4587+ "SERVER_INCLUDED_THIRD" ,
4588+ ] {
4589+ codex
4590+ . submit ( Op :: UserInput {
4591+ items : vec ! [ UserInput :: Text {
4592+ text: user. into( ) ,
4593+ text_elements: Vec :: new( ) ,
4594+ } ] ,
4595+ final_output_json_schema : None ,
4596+ responsesapi_client_metadata : None ,
4597+ additional_context : Default :: default ( ) ,
4598+ thread_settings : Default :: default ( ) ,
4599+ } )
4600+ . await
4601+ . unwrap ( ) ;
4602+ wait_for_event ( & codex, |ev| matches ! ( ev, EventMsg :: TurnComplete ( _) ) ) . await ;
4603+ }
4604+
4605+ assert ! (
4606+ compact_mock. requests( ) . is_empty( ) ,
4607+ "pre-turn accounting should retain the previous response's reasoning-included signal"
4608+ ) ;
4609+ }
4610+
45324611#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
45334612async fn auto_compact_runs_when_reasoning_header_clears_between_turns ( ) {
45344613 skip_if_no_network ! ( ) ;
0 commit comments