@@ -68,14 +68,10 @@ impl CodeModeService {
6868 }
6969 }
7070
71- pub async fn stored_values ( & self ) -> HashMap < String , JsonValue > {
71+ async fn stored_values ( & self ) -> HashMap < String , JsonValue > {
7272 self . inner . stored_values . lock ( ) . await . clone ( )
7373 }
7474
75- pub async fn replace_stored_values ( & self , values : HashMap < String , JsonValue > ) {
76- * self . inner . stored_values . lock ( ) . await = values;
77- }
78-
7975 /// Reserves the runtime cell id for a future `execute` request.
8076 ///
8177 /// The runtime can issue nested tool calls before the first `execute`
@@ -94,14 +90,16 @@ impl CodeModeService {
9490 let initial_yield_time_ms = request. yield_time_ms . unwrap_or ( DEFAULT_EXEC_YIELD_TIME_MS ) ;
9591 let ( event_tx, event_rx) = mpsc:: unbounded_channel ( ) ;
9692 let ( control_tx, control_rx) = mpsc:: unbounded_channel ( ) ;
93+ let stored_values = self . stored_values ( ) . await ;
9794 let ( response_tx, response_rx) = oneshot:: channel ( ) ;
9895 let ( runtime_tx, runtime_terminate_handle) = {
9996 let mut sessions = self . inner . sessions . lock ( ) . await ;
10097 if sessions. contains_key ( & cell_id) {
10198 return Err ( format ! ( "exec cell {cell_id} already exists" ) ) ;
10299 }
103100
104- let ( runtime_tx, runtime_terminate_handle) = spawn_runtime ( request, event_tx) ?;
101+ let ( runtime_tx, runtime_terminate_handle) =
102+ spawn_runtime ( stored_values, request, event_tx) ?;
105103
106104 // Keep the session registry locked through insertion so a
107105 // caller-owned cell id cannot race with another execute and replace
@@ -262,7 +260,6 @@ enum SessionControlCommand {
262260
263261struct PendingResult {
264262 content_items : Vec < FunctionCallOutputContentItem > ,
265- stored_values : HashMap < String , JsonValue > ,
266263 error_text : Option < String > ,
267264}
268265
@@ -277,15 +274,13 @@ fn missing_cell_response(cell_id: String) -> RuntimeResponse {
277274 error_text : Some ( format ! ( "exec cell {cell_id} not found" ) ) ,
278275 cell_id,
279276 content_items : Vec :: new ( ) ,
280- stored_values : HashMap :: new ( ) ,
281277 }
282278}
283279
284280fn pending_result_response ( cell_id : & str , result : PendingResult ) -> RuntimeResponse {
285281 RuntimeResponse :: Result {
286282 cell_id : cell_id. to_string ( ) ,
287283 content_items : result. content_items ,
288- stored_values : result. stored_values ,
289284 error_text : result. error_text ,
290285 }
291286}
@@ -348,7 +343,6 @@ async fn run_session_control(
348343 if pending_result. is_none( ) {
349344 let result = PendingResult {
350345 content_items: std:: mem:: take( & mut content_items) ,
351- stored_values: HashMap :: new( ) ,
352346 error_text: Some ( "exec runtime ended unexpectedly" . to_string( ) ) ,
353347 } ;
354348 if send_or_buffer_result(
@@ -398,7 +392,7 @@ async fn run_session_control(
398392 . await ;
399393 }
400394 RuntimeEvent :: Result {
401- stored_values ,
395+ stored_value_writes ,
402396 error_text,
403397 } => {
404398 yield_timer = None ;
@@ -411,9 +405,13 @@ async fn run_session_control(
411405 }
412406 break ;
413407 }
408+ inner
409+ . stored_values
410+ . lock( )
411+ . await
412+ . extend( stored_value_writes) ;
414413 let result = PendingResult {
415414 content_items: std:: mem:: take( & mut content_items) ,
416- stored_values,
417415 error_text,
418416 } ;
419417 if send_or_buffer_result(
@@ -522,7 +520,6 @@ mod tests {
522520 tool_call_id : "call_1" . to_string ( ) ,
523521 enabled_tools : Vec :: new ( ) ,
524522 source : source. to_string ( ) ,
525- stored_values : HashMap :: new ( ) ,
526523 yield_time_ms : Some ( 1 ) ,
527524 max_output_tokens : None ,
528525 }
@@ -559,7 +556,6 @@ mod tests {
559556 content_items: vec![ FunctionCallOutputContentItem :: InputText {
560557 text: "before" . to_string( ) ,
561558 } ] ,
562- stored_values: HashMap :: new( ) ,
563559 error_text: None ,
564560 }
565561 ) ;
@@ -585,7 +581,6 @@ mod tests {
585581 content_items: vec![ FunctionCallOutputContentItem :: InputText {
586582 text: "false" . to_string( ) ,
587583 } ] ,
588- stored_values: HashMap :: new( ) ,
589584 error_text: None ,
590585 }
591586 ) ;
@@ -625,7 +620,6 @@ text(value);
625620 content_items: vec![ FunctionCallOutputContentItem :: InputText {
626621 text: "jeudi 2 janvier \u{e0} 03:04:05" . to_string( ) ,
627622 } ] ,
628- stored_values: HashMap :: new( ) ,
629623 error_text: None ,
630624 }
631625 ) ;
@@ -664,7 +658,6 @@ text(formatter.format(new Date("2025-01-02T03:04:05Z")));
664658 content_items: vec![ FunctionCallOutputContentItem :: InputText {
665659 text: "jeudi 2 janvier \u{e0} 03:04:05" . to_string( ) ,
666660 } ] ,
667- stored_values: HashMap :: new( ) ,
668661 error_text: None ,
669662 }
670663 ) ;
@@ -707,7 +700,6 @@ text(JSON.stringify(returnsUndefined));
707700 text: "[true,true,true]" . to_string( ) ,
708701 } ,
709702 ] ,
710- stored_values: HashMap :: new( ) ,
711703 error_text: None ,
712704 }
713705 ) ;
@@ -742,7 +734,6 @@ image({
742734 image_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==" . to_string( ) ,
743735 detail: Some ( crate :: ImageDetail :: Original ) ,
744736 } ] ,
745- stored_values: HashMap :: new( ) ,
746737 error_text: None ,
747738 }
748739 ) ;
@@ -778,7 +769,6 @@ image(
778769 image_url: "https://example.com/image.jpg" . to_string( ) ,
779770 detail: Some ( crate :: ImageDetail :: Original ) ,
780771 } ] ,
781- stored_values: HashMap :: new( ) ,
782772 error_text: None ,
783773 }
784774 ) ;
@@ -816,7 +806,6 @@ image(
816806 image_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==" . to_string( ) ,
817807 detail: Some ( crate :: ImageDetail :: Low ) ,
818808 } ] ,
819- stored_values: HashMap :: new( ) ,
820809 error_text: None ,
821810 }
822811 ) ;
@@ -853,7 +842,6 @@ image({
853842 RuntimeResponse :: Result {
854843 cell_id: "1" . to_string( ) ,
855844 content_items: Vec :: new( ) ,
856- stored_values: HashMap :: new( ) ,
857845 error_text: Some (
858846 "image expects a non-empty image URL string, an object with image_url and optional detail, or a raw MCP image block" . to_string( ) ,
859847 ) ,
@@ -879,7 +867,6 @@ image({
879867 WaitOutcome :: MissingCell ( RuntimeResponse :: Result {
880868 cell_id: "missing" . to_string( ) ,
881869 content_items: Vec :: new( ) ,
882- stored_values: HashMap :: new( ) ,
883870 error_text: Some ( "exec cell missing not found" . to_string( ) ) ,
884871 } )
885872 ) ;
@@ -893,6 +880,7 @@ image({
893880 let ( initial_response_tx, initial_response_rx) = oneshot:: channel ( ) ;
894881 let ( runtime_event_tx, _runtime_event_rx) = mpsc:: unbounded_channel ( ) ;
895882 let ( runtime_tx, runtime_terminate_handle) = spawn_runtime (
883+ HashMap :: new ( ) ,
896884 ExecuteRequest {
897885 source : "await new Promise(() => {})" . to_string ( ) ,
898886 yield_time_ms : None ,
0 commit comments