@@ -89,7 +89,6 @@ use crate::protocol::ExecCommandBeginEvent;
89
89
use crate :: protocol:: ExecCommandEndEvent ;
90
90
use crate :: protocol:: FileChange ;
91
91
use crate :: protocol:: InputItem ;
92
- use crate :: protocol:: InputMessageKind ;
93
92
use crate :: protocol:: ListCustomPromptsResponseEvent ;
94
93
use crate :: protocol:: Op ;
95
94
use crate :: protocol:: PatchApplyBeginEvent ;
@@ -169,9 +168,7 @@ impl Codex {
169
168
pub async fn spawn (
170
169
config : Config ,
171
170
auth_manager : Arc < AuthManager > ,
172
- conversation_id : Option < ConversationId > ,
173
171
conversation_history : InitialHistory ,
174
- rollout_path : Option < PathBuf > ,
175
172
) -> CodexResult < CodexSpawnOk > {
176
173
let ( tx_sub, rx_sub) = async_channel:: bounded ( SUBMISSION_CHANNEL_CAPACITY ) ;
177
174
let ( tx_event, rx_event) = async_channel:: unbounded ( ) ;
@@ -199,9 +196,7 @@ impl Codex {
199
196
config. clone ( ) ,
200
197
auth_manager. clone ( ) ,
201
198
tx_event. clone ( ) ,
202
- conversation_id,
203
199
conversation_history. clone ( ) ,
204
- rollout_path,
205
200
)
206
201
. await
207
202
. map_err ( |e| {
@@ -365,11 +360,8 @@ impl Session {
365
360
config : Arc < Config > ,
366
361
auth_manager : Arc < AuthManager > ,
367
362
tx_event : Sender < Event > ,
368
- conversation_id : Option < ConversationId > ,
369
363
initial_history : InitialHistory ,
370
- rollout_path : Option < PathBuf > ,
371
364
) -> anyhow:: Result < ( Arc < Self > , TurnContext ) > {
372
- let conversation_id = conversation_id. unwrap_or_else ( ConversationId :: new) ;
373
365
let ConfigureSession {
374
366
provider,
375
367
model,
@@ -387,6 +379,20 @@ impl Session {
387
379
return Err ( anyhow:: anyhow!( "cwd is not absolute: {cwd:?}" ) ) ;
388
380
}
389
381
382
+ let ( conversation_id, rollout_params) = match & initial_history {
383
+ InitialHistory :: New | InitialHistory :: Forked ( _) => {
384
+ let conversation_id = ConversationId :: default ( ) ;
385
+ (
386
+ conversation_id,
387
+ RolloutRecorderParams :: new ( conversation_id, user_instructions. clone ( ) ) ,
388
+ )
389
+ }
390
+ InitialHistory :: Resumed ( resumed_history) => (
391
+ resumed_history. conversation_id ,
392
+ RolloutRecorderParams :: resume ( resumed_history. rollout_path . clone ( ) ) ,
393
+ ) ,
394
+ } ;
395
+
390
396
// Error messages to dispatch after SessionConfigured is sent.
391
397
let mut post_session_configured_error_events = Vec :: < Event > :: new ( ) ;
392
398
@@ -396,10 +402,6 @@ impl Session {
396
402
// - spin up MCP connection manager
397
403
// - perform default shell discovery
398
404
// - load history metadata
399
- let rollout_params = match rollout_path {
400
- Some ( path) => RolloutRecorderParams :: resume ( path) ,
401
- None => RolloutRecorderParams :: new ( conversation_id, user_instructions. clone ( ) ) ,
402
- } ;
403
405
let rollout_fut = RolloutRecorder :: new ( & config, rollout_params) ;
404
406
405
407
let mcp_fut = McpConnectionManager :: new ( config. mcp_servers . clone ( ) ) ;
@@ -492,7 +494,10 @@ impl Session {
492
494
// If resuming, include converted initial messages in the payload so UIs can render them immediately.
493
495
let initial_messages = match & initial_history {
494
496
InitialHistory :: New => None ,
495
- InitialHistory :: Resumed ( items) => Some ( sess. build_initial_messages ( items) ) ,
497
+ InitialHistory :: Forked ( items) => Some ( sess. build_initial_messages ( items) ) ,
498
+ InitialHistory :: Resumed ( resumed_history) => {
499
+ Some ( sess. build_initial_messages ( & resumed_history. history ) )
500
+ }
496
501
} ;
497
502
498
503
let events = std:: iter:: once ( Event {
@@ -541,8 +546,12 @@ impl Session {
541
546
InitialHistory :: New => {
542
547
self . record_initial_history_new ( turn_context) . await ;
543
548
}
544
- InitialHistory :: Resumed ( items) => {
545
- self . record_initial_history_resumed ( items) . await ;
549
+ InitialHistory :: Forked ( items) => {
550
+ self . record_initial_history_from_items ( items) . await ;
551
+ }
552
+ InitialHistory :: Resumed ( resumed_history) => {
553
+ self . record_initial_history_from_items ( resumed_history. history )
554
+ . await ;
546
555
}
547
556
}
548
557
}
@@ -564,8 +573,8 @@ impl Session {
564
573
self . record_conversation_items ( & conversation_items) . await ;
565
574
}
566
575
567
- async fn record_initial_history_resumed ( & self , items : Vec < ResponseItem > ) {
568
- self . record_conversation_items ( & items) . await ;
576
+ async fn record_initial_history_from_items ( & self , items : Vec < ResponseItem > ) {
577
+ self . record_conversation_items_internal ( & items, false ) . await ;
569
578
}
570
579
571
580
/// build the initial messages vector for SessionConfigured by converting
@@ -576,12 +585,6 @@ impl Session {
576
585
. flat_map ( |item| {
577
586
map_response_item_to_event_messages ( item, self . show_raw_agent_reasoning )
578
587
} )
579
- . filter ( |event| {
580
- if let EventMsg :: UserMessage ( user_message) = event {
581
- return matches ! ( user_message. kind, Some ( InputMessageKind :: Plain ) ) ;
582
- }
583
- true
584
- } )
585
588
. collect ( )
586
589
}
587
590
@@ -680,8 +683,14 @@ impl Session {
680
683
/// Records items to both the rollout and the chat completions/ZDR
681
684
/// transcript, if enabled.
682
685
async fn record_conversation_items ( & self , items : & [ ResponseItem ] ) {
686
+ self . record_conversation_items_internal ( items, true ) . await ;
687
+ }
688
+
689
+ async fn record_conversation_items_internal ( & self , items : & [ ResponseItem ] , persist : bool ) {
683
690
debug ! ( "Recording items for conversation: {items:?}" ) ;
684
- self . record_state_snapshot ( items) . await ;
691
+ if persist {
692
+ self . record_state_snapshot ( items) . await ;
693
+ }
685
694
686
695
self . state . lock_unchecked ( ) . history . record_items ( items) ;
687
696
}
@@ -1267,7 +1276,7 @@ async fn submission_loop(
1267
1276
log_id,
1268
1277
entry : entry_opt. map ( |e| {
1269
1278
codex_protocol:: message_history:: HistoryEntry {
1270
- conversation_id : e. conversation_id ,
1279
+ conversation_id : e. session_id ,
1271
1280
ts : e. ts ,
1272
1281
text : e. text ,
1273
1282
}
0 commit comments