Skip to content

Commit 89b59da

Browse files
committed
tui/core: persist transcript-form user messages in rollout for resume; keep rollout unredacted; avoid leaking prompt text in logs; show verbatim /prompt in transcript
Signed-off-by: Roman Aleynikov <[email protected]>
1 parent e4a3bd2 commit 89b59da

File tree

7 files changed

+34
-12
lines changed

7 files changed

+34
-12
lines changed

codex-rs/core/src/codex.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ use crate::protocol::ExecCommandBeginEvent;
9393
use crate::protocol::ExecCommandEndEvent;
9494
use crate::protocol::FileChange;
9595
use crate::protocol::InputItem;
96+
use crate::protocol::InputMessageKind;
9697
use crate::protocol::ListCustomPromptsResponseEvent;
9798
use crate::protocol::Op;
9899
use crate::protocol::PatchApplyBeginEvent;
@@ -107,6 +108,7 @@ use crate::protocol::TaskCompleteEvent;
107108
use crate::protocol::TokenUsage;
108109
use crate::protocol::TokenUsageInfo;
109110
use crate::protocol::TurnDiffEvent;
111+
use crate::protocol::UserMessageEvent;
110112
use crate::protocol::WebSearchBeginEvent;
111113
use crate::rollout::RolloutRecorder;
112114
use crate::rollout::RolloutRecorderParams;
@@ -1184,7 +1186,8 @@ async fn submission_loop(
11841186
let mut turn_context = Arc::new(turn_context);
11851187
// To break out of this loop, send Op::Shutdown.
11861188
while let Ok(sub) = rx_sub.recv().await {
1187-
debug!(?sub, "Submission");
1189+
// Avoid logging full submission payloads to prevent leaking prompt or template text.
1190+
debug!("Submission received: id={}", sub.id);
11881191
match sub.op {
11891192
Op::Interrupt => {
11901193
sess.interrupt_task();
@@ -1370,12 +1373,23 @@ async fn submission_loop(
13701373
Op::AddToHistory { text } => {
13711374
let id = sess.conversation_id;
13721375
let config = config.clone();
1376+
let text_for_history = text.clone();
13731377
tokio::spawn(async move {
1374-
if let Err(e) = crate::message_history::append_entry(&text, &id, &config).await
1378+
if let Err(e) =
1379+
crate::message_history::append_entry(&text_for_history, &id, &config).await
13751380
{
13761381
warn!("failed to append to message history: {e}");
13771382
}
13781383
});
1384+
1385+
// Persist a transcript-only user message in rollout so resume displays
1386+
// exactly what the user saw in the transcript. Do not send to UI to avoid duplicates.
1387+
let rollout_item = RolloutItem::EventMsg(EventMsg::UserMessage(UserMessageEvent {
1388+
message: text,
1389+
kind: Some(InputMessageKind::Plain),
1390+
images: None,
1391+
}));
1392+
sess.persist_rollout_items(&[rollout_item]).await;
13791393
}
13801394

13811395
Op::GetHistoryEntryRequest { offset, log_id } => {

codex-rs/core/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ model_verbosity = "high"
16221622
include_view_image_tool: true,
16231623
active_profile: Some("o3".to_string()),
16241624
disable_paste_burst: false,
1625+
redact_saved_prompt_body: true,
16251626
},
16261627
o3_profile_config
16271628
);

codex-rs/core/src/rollout/recorder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ impl RolloutRecorder {
293293
}
294294
}
295295

296+
// Note: rollout files are used for resume; do not redact or truncate persisted items here.
297+
296298
struct LogFileInfo {
297299
/// Opened file handle to the rollout file.
298300
file: File,

codex-rs/exec/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
162162
include_view_image_tool: None,
163163
show_raw_agent_reasoning: oss.then_some(true),
164164
tools_web_search_request: None,
165+
redact_saved_prompt_body: None,
165166
};
166167
// Parse `-c` overrides.
167168
let cli_kv_overrides = match config_overrides.parse_overrides() {

codex-rs/mcp-server/src/codex_message_processor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ fn derive_config_from_params(
12701270
include_view_image_tool: None,
12711271
show_raw_agent_reasoning: None,
12721272
tools_web_search_request: None,
1273+
redact_saved_prompt_body: None,
12731274
};
12741275

12751276
let cli_overrides = cli_overrides

codex-rs/mcp-server/src/codex_tool_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl CodexToolCallParam {
165165
include_view_image_tool: None,
166166
show_raw_agent_reasoning: None,
167167
tools_web_search_request: None,
168+
redact_saved_prompt_body: None,
168169
};
169170

170171
let cli_overrides = cli_overrides

codex-rs/tui/src/chatwidget.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,22 +1039,24 @@ impl ChatWidget {
10391039
tracing::error!("failed to send message: {e}");
10401040
});
10411041

1042-
// Persist the text to cross-session message history.
1043-
if !text.is_empty() {
1044-
self.codex_op_tx
1045-
.send(Op::AddToHistory { text: text.clone() })
1046-
.unwrap_or_else(|e| {
1047-
tracing::error!("failed to send AddHistory op: {e}");
1048-
});
1049-
}
1050-
1051-
// Only show the text portion in conversation history.
10521042
if !text.is_empty() {
1043+
// Compute what we show to the user in transcript.
10531044
let shown = if self.config.redact_saved_prompt_body {
10541045
display_text.unwrap_or_else(|| text.clone())
10551046
} else {
10561047
pretty_unredacted.unwrap_or_else(|| text.clone())
10571048
};
1049+
1050+
// Persist the display text to cross-session message history (and rollout via core)
1051+
self.codex_op_tx
1052+
.send(Op::AddToHistory {
1053+
text: shown.clone(),
1054+
})
1055+
.unwrap_or_else(|e| {
1056+
tracing::error!("failed to send AddHistory op: {e}");
1057+
});
1058+
1059+
// Show in conversation history now.
10581060
self.add_to_history(history_cell::new_user_prompt(shown));
10591061
}
10601062
}

0 commit comments

Comments
 (0)