Skip to content

Resume conversation from an earlier point in history - #2607

Merged
aibrahim-oai merged 13 commits into
mainfrom
feature/esc-esc-backtrack
Aug 24, 2025
Merged

aibrahim-oai merged 13 commits into
mainfrom
feature/esc-esc-backtrack

Conversation

@aibrahim-oai

Copy link
Copy Markdown
Contributor

Fixing merge conflict of this: #2588

Screen.Recording.2025-08-22.at.10.34.59.AM.mov

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment thread codex-rs/tui/src/app_backtrack.rs Resolved
Comment thread codex-rs/tui/src/app.rs Resolved
@easong-openai

Copy link
Copy Markdown
Contributor
  • There's some weirdness where we're not resetting the esc twice counter and you can get into it only pressing once - for example, pressing esc, typing a character, hitting backspace, then pressing esc again.
  • Pressing esc too many times and you lose your cursor, it should loop back to the first one I think.

Lower confidence thoughts:

  • I'm not 100% sure if esc-esc is the right hotkey here. Is there some ctrl combo that would make sense? If we are going to do it, I think it would make sense to hint to the user on the first esc similar to how we do double tap on ctrl-c
  • We need to tell the user whatever the hotkey is somehow - possibly this should go in a /help slash menu that doesn't exist that documents all the hotkeys
  • You should be able to get into this from transcript mode

@nornagon-openai nornagon-openai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall this seems underbaked and in need of some careful attention to abstractions.

Comment thread codex-rs/tui/src/transcript_app.rs Outdated
Comment on lines +93 to +118
fn rebuild_highlighted_lines(&mut self) {
// Start from base and optionally apply highlight styles to the target range.
let mut out = self.base_transcript_lines.clone();
if let Some((start, end)) = self.highlight_range {
use ratatui::style::Modifier;
let len = out.len();
let start = start.min(len);
let end = end.min(len);
for (idx, line) in out.iter_mut().enumerate().take(end).skip(start) {
// Apply REVERSED to all spans; add BOLD on the first line (header)
let mut spans = Vec::with_capacity(line.spans.len());
for (i, s) in line.spans.iter().enumerate() {
let mut style = s.style;
style.add_modifier |= Modifier::REVERSED;
if idx == start && i == 0 {
style.add_modifier |= Modifier::BOLD;
}
spans.push(ratatui::text::Span {
style,
content: s.content.clone(),
});
}
line.spans = spans;
}
}
self.transcript_lines = out;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we instead apply highlighting at render time? then we can also drop base_transcript_lines.

Comment thread codex-rs/tui/src/app_backtrack.rs Outdated
Comment on lines +79 to +87
}
}
// Forward to overlay if not handled
if !handled && let Some(overlay) = &mut self.transcript_overlay {
overlay.handle_event(tui, event)?;
if overlay.is_done {
self.close_transcript_overlay(tui);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of mut handled, put the forwarding logic in the catchall case of the match

Comment on lines +244 to +247
pub(crate) fn render_transcript_once(&mut self, tui: &mut tui::Tui) {
if !self.transcript_lines.is_empty() {
tui.insert_history_lines(self.transcript_lines.clone());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems bad to duplicate the history this way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what other way you think is better?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one possibility would be to render a separator (e.g. a line across the terminal), then "continuing from:" and then repeat only the most recent turn.

Comment on lines +130 to +201
pub(crate) fn handle_backtrack_esc_key(&mut self, tui: &mut tui::Tui) {
// Only handle backtracking when composer is empty to avoid clobbering edits.
if self.chat_widget.composer_is_empty() {
if !self.esc_backtrack_primed {
// Arm backtracking and record base conversation.
self.esc_backtrack_primed = true;
self.esc_backtrack_count = 0;
self.esc_backtrack_base = self.chat_widget.session_id();
// Show hint in composer to guide Esc-then-Esc flow.
self.chat_widget.show_esc_backtrack_hint();
} else if self.transcript_overlay.is_none() {
// Open transcript overlay in backtrack preview mode and jump to the target message.
self.open_transcript_overlay(tui);
self.transcript_overlay_is_backtrack = true;
// Overlay footer already shows the backtrack guidance unconditionally.
// Composer is hidden by overlay; clear its hint.
self.chat_widget.clear_esc_backtrack_hint();
self.esc_backtrack_count = self.esc_backtrack_count.saturating_add(1);
let nth = backtrack_helpers::normalize_backtrack_n(
&self.transcript_lines,
self.esc_backtrack_count,
);
self.esc_backtrack_count = nth;
let header_idx =
backtrack_helpers::find_nth_last_user_header_index(&self.transcript_lines, nth);
let offset = header_idx.map(|idx| {
backtrack_helpers::wrapped_offset_before(
&self.transcript_lines,
idx,
tui.terminal.viewport_area.width,
)
});
let hl = backtrack_helpers::highlight_range_for_nth_last_user(
&self.transcript_lines,
nth,
);
if let Some(overlay) = &mut self.transcript_overlay {
if let Some(off) = offset {
overlay.scroll_offset = off;
}
overlay.set_highlight_range(hl);
}
} else if self.transcript_overlay_is_backtrack {
// Already previewing: step to the next older message.
self.esc_backtrack_count = self.esc_backtrack_count.saturating_add(1);
let nth = backtrack_helpers::normalize_backtrack_n(
&self.transcript_lines,
self.esc_backtrack_count,
);
self.esc_backtrack_count = nth;
let header_idx =
backtrack_helpers::find_nth_last_user_header_index(&self.transcript_lines, nth);
let offset = header_idx.map(|idx| {
backtrack_helpers::wrapped_offset_before(
&self.transcript_lines,
idx,
tui.terminal.viewport_area.width,
)
});
let hl = backtrack_helpers::highlight_range_for_nth_last_user(
&self.transcript_lines,
nth,
);
if let Some(overlay) = &mut self.transcript_overlay {
if let Some(off) = offset {
overlay.scroll_offset = off;
}
overlay.set_highlight_range(hl);
}
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like really brittle logic. i don't feel this is landable as is, it needs an abstraction in order to be understandable and thus modifiable.

@aibrahim-oai
aibrahim-oai merged commit c6a52d6 into main Aug 24, 2025
@aibrahim-oai
aibrahim-oai deleted the feature/esc-esc-backtrack branch August 24, 2025 06:23
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants