@@ -5,6 +5,9 @@ use crate::config::RolloutConfig;
55use chrono:: TimeZone ;
66use codex_protocol:: ThreadId ;
77use codex_protocol:: config_types:: ReasoningSummary as ReasoningSummaryConfig ;
8+ use codex_protocol:: models:: FunctionCallOutputBody ;
9+ use codex_protocol:: models:: FunctionCallOutputContentItem ;
10+ use codex_protocol:: models:: FunctionCallOutputPayload ;
811use codex_protocol:: models:: ResponseItem ;
912use codex_protocol:: protocol:: AgentMessageEvent ;
1013use codex_protocol:: protocol:: AskForApproval ;
@@ -69,6 +72,80 @@ fn write_session_file(root: &Path, ts: &str, uuid: Uuid) -> std::io::Result<Path
6972 Ok ( path)
7073}
7174
75+ #[ test]
76+ fn sanitize_rollout_item_truncates_large_function_call_output ( ) {
77+ let large_output = format ! ( "{}{}{}" , "a" . repeat( 80_000 ) , "middle" , "z" . repeat( 80_000 ) ) ;
78+ let item = RolloutItem :: ResponseItem ( ResponseItem :: FunctionCallOutput {
79+ call_id : "call_1" . to_string ( ) ,
80+ output : FunctionCallOutputPayload :: from_text ( large_output. clone ( ) ) ,
81+ } ) ;
82+
83+ let sanitized = sanitize_rollout_item_for_persistence ( item, EventPersistenceMode :: Limited ) ;
84+
85+ let RolloutItem :: ResponseItem ( ResponseItem :: FunctionCallOutput { output, .. } ) = sanitized
86+ else {
87+ panic ! ( "expected function_call_output" ) ;
88+ } ;
89+ let FunctionCallOutputBody :: Text ( text) = output. body else {
90+ panic ! ( "expected text output" ) ;
91+ } ;
92+ assert ! (
93+ text. len( ) < large_output. len( ) ,
94+ "persisted function output should be truncated"
95+ ) ;
96+ assert ! (
97+ text. contains( "truncated" ) ,
98+ "truncated output should carry an explicit marker"
99+ ) ;
100+ assert ! (
101+ text. starts_with( 'a' ) && text. ends_with( 'z' ) ,
102+ "truncated output should preserve prefix and suffix"
103+ ) ;
104+ }
105+
106+ #[ test]
107+ fn sanitize_rollout_item_truncates_structured_text_function_output ( ) {
108+ let large_text = format ! ( "{}{}" , "prefix " . repeat( 20_000 ) , "suffix" ) ;
109+ let item = RolloutItem :: ResponseItem ( ResponseItem :: CustomToolCallOutput {
110+ call_id : "call_2" . to_string ( ) ,
111+ name : Some ( "custom" . to_string ( ) ) ,
112+ output : FunctionCallOutputPayload :: from_content_items ( vec ! [
113+ FunctionCallOutputContentItem :: InputText {
114+ text: large_text. clone( ) ,
115+ } ,
116+ FunctionCallOutputContentItem :: InputImage {
117+ image_url: "data:image/png;base64,abc" . to_string( ) ,
118+ detail: None ,
119+ } ,
120+ ] ) ,
121+ } ) ;
122+
123+ let sanitized = sanitize_rollout_item_for_persistence ( item, EventPersistenceMode :: Limited ) ;
124+
125+ let RolloutItem :: ResponseItem ( ResponseItem :: CustomToolCallOutput { output, .. } ) = sanitized
126+ else {
127+ panic ! ( "expected custom_tool_call_output" ) ;
128+ } ;
129+ let FunctionCallOutputBody :: ContentItems ( items) = output. body else {
130+ panic ! ( "expected structured output" ) ;
131+ } ;
132+ let FunctionCallOutputContentItem :: InputText { text } = & items[ 0 ] else {
133+ panic ! ( "expected leading text item" ) ;
134+ } ;
135+ assert ! (
136+ text. len( ) < large_text. len( ) ,
137+ "persisted structured text output should be truncated"
138+ ) ;
139+ assert ! (
140+ text. contains( "truncated" ) ,
141+ "truncated structured text should carry an explicit marker"
142+ ) ;
143+ assert ! (
144+ matches!( items[ 1 ] , FunctionCallOutputContentItem :: InputImage { .. } ) ,
145+ "non-text content items should be preserved"
146+ ) ;
147+ }
148+
72149#[ tokio:: test]
73150async fn state_db_init_backfills_before_returning ( ) -> anyhow:: Result < ( ) > {
74151 let home = TempDir :: new ( ) . expect ( "temp dir" ) ;
0 commit comments