Skip to content

Commit 700ddbf

Browse files
committed
Restore the current standalone Codex conversation after a thread switch
1 parent 1104a86 commit 700ddbf

10 files changed

Lines changed: 321 additions & 119 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ macOS, Linux, and Android downloads are Preview builds.
2929
- Fixed a reply from a worker’s previous turn being returned for a newly delegated task.
3030
- Fixed WSL worker replies failing to reach the pane that delegated the task.
3131
- Fixed SSH panes retaining the Codex identity after exit when the remote Bash prompt displayed a changing clock.
32+
- Fixed restoring the previous conversation after `/new` in a standalone Codex client. When the pane holds both threads, Pebrel matches the full thread ID beneath the empty prompt. If it cannot identify the current thread, it offers the Codex picker on restart.
3233

3334
### 中文
3435

@@ -41,6 +42,7 @@ macOS、Linux 和 Android 下载为预览版。
4142
- 修复新任务刚被委派时,调用方可能收到上一轮答复的问题。
4243
- 修复 WSL 中的 Agent 完成任务后,发起委派的窗格收不到答复的问题。
4344
- 修复远端 Bash 提示符的时钟变化后,退出 Codex 的 SSH 窗格仍显示 Codex 身份的问题。
45+
- 修复独立运行的 Codex 在 `/new` 后恢复旧对话的问题。窗格同时持有新旧两份记录时,Pebrel 会核对空输入框下方显示的完整对话 ID。无法确认时,重启后可在 Codex 中选择对话。
4446

4547
### Contributors
4648

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Checkpointing Codex after an in-pane thread switch
2+
3+
## Status
4+
5+
Implemented for pane-owned native rollout probes.
6+
7+
## Context
8+
9+
Codex can change conversations without restarting its terminal client. A
10+
confirmed tab or pane identifier stays valid throughout that change.
11+
12+
## Evidence
13+
14+
On Linux, packaged Pebrel 2.6.1 and Codex 0.160.0 with a standalone client
15+
saved the first thread correctly. After `/new` the same client held two open
16+
main/user rollouts. The new thread accepted two messages while the checkpoint
17+
kept the old ID. After process termination, a new message went into the old
18+
thread. On Windows x64 and ARM64, Codex 0.167.0 likewise changed the native ID
19+
while the checkpoint retained the old one for 30 seconds. The neighboring
20+
pane kept its own ID. The Windows TUI displayed an agent-navigation hint
21+
before the shortcuts hint on the line below the native ID.
22+
[Windows reproduction](https://github.com/Kuddev/pebrel/actions/runs/44707360005) · [Captured footer](https://github.com/Kuddev/pebrel/actions/runs/44713190737)
23+
24+
## Decision
25+
26+
Return distinct verified rollouts to the foreground pane. A single candidate
27+
uses the existing attribution rules. For multiple candidates, the pane can
28+
select a unique matching native ID displayed in the Codex status line under
29+
its empty composer. With no match, discard an earlier probe-derived live
30+
target and keep the Codex source for the resume picker. A failed lookup leaves
31+
the prior checkpoint alone. Generation checks and pending cold-resume
32+
confirmation still govern asynchronous results.
33+
34+
## Rejected alternatives
35+
36+
The last open descriptor, newest file and working directory cannot distinguish
37+
a resumed older conversation from another open thread. An ID printed in
38+
ordinary terminal output does not establish the active native thread.
39+
40+
## Consequences
41+
42+
Exact selection among several open rollouts requires the supported status-line
43+
layout. A detached shared daemon still needs an independent pane binding.
44+
45+
## Validation
46+
47+
The native parser tests cover duplicate and ambiguous rollouts, a selected ID
48+
and a foreign ID. The terminal regression switches the live checkpoint, falls
49+
back to a source-only target on ambiguity and preserves a pending cold target.
50+
51+
## Supersedes
52+
53+
Extends the [pane ownership decision](2026-11-12-detached-codex-session-ownership.md).
54+
55+
## Revisit when
56+
57+
Codex exposes an explicit client-side notification that identifies the active
58+
conversation to the terminal.

‎docs/release-notes/v2.6.2.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ macOS, Linux, and Android downloads are Preview builds.
1111
- Fixed a reply from a worker’s previous turn being returned for a newly delegated task.
1212
- Fixed WSL worker replies failing to reach the pane that delegated the task.
1313
- Fixed SSH panes retaining the Codex identity after exit when the remote Bash prompt displayed a changing clock.
14+
- Fixed restoring the previous conversation after `/new` in a standalone Codex client. When the pane holds both threads, Pebrel matches the full thread ID beneath the empty prompt. If it cannot identify the current thread, it offers the Codex picker on restart.
1415

1516
## 中文
1617

@@ -23,6 +24,7 @@ macOS、Linux 和 Android 下载为预览版。
2324
- 修复新任务刚被委派时,调用方可能收到上一轮答复的问题。
2425
- 修复 WSL 中的 Agent 完成任务后,发起委派的窗格收不到答复的问题。
2526
- 修复远端 Bash 提示符的时钟变化后,退出 Codex 的 SSH 窗格仍显示 Codex 身份的问题。
27+
- 修复独立运行的 Codex 在 `/new` 后恢复旧对话的问题。窗格同时持有新旧两份记录时,Pebrel 会核对空输入框下方显示的完整对话 ID。无法确认时,重启后可在 Codex 中选择对话。
2628

2729
## Contributors
2830

‎nebula_app/src/gpui_shell/terminal/view/runtime.rs‎

Lines changed: 2 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! GPUI 终端对 Runtime API 暴露的读取、输入与任务状态边界。
22
3+
mod codex_checkpoint;
4+
35
use gpui::{Context, EventEmitter as _, SharedString, Window, px};
46
use nebula_terminal::grid::Dimensions as _;
57
use nebula_terminal::index::{Column, Line, Point as TermPoint};
@@ -898,101 +900,6 @@ impl TerminalView {
898900
crate::ai_agents::AgentKind::parse(&identity.source)?.fork_command(&identity.session_id)
899901
}
900902

901-
pub(crate) fn prepare_ai_session_save(&mut self, cx: &mut Context<Self>) {
902-
// A refresh may fail or time out. Keep the last confirmed native ID.
903-
self.last_ai_session_probe = None;
904-
self.probe_missing_codex_session(cx);
905-
}
906-
907-
pub(crate) fn ai_session_save_pending(&self) -> bool {
908-
// A failed refresh cannot erase an already durable identity. Pi/Codex
909-
// without any native target must finish identifying before safe exit.
910-
self.ai_session_probe_pending
911-
|| self.session_agent().is_some_and(|agent| {
912-
matches!(agent.source.as_str(), "pi" | "codex")
913-
&& agent.session_id.as_deref().is_none_or(str::is_empty)
914-
})
915-
}
916-
917-
/// Read the active conversation metadata when its hook has not reported an ID.
918-
/// File and process operations run on the background executor. Only results
919-
/// for the same foreground command and unchanged identity are applied.
920-
pub(super) fn probe_missing_codex_session(&mut self, cx: &mut Context<Self>) {
921-
if self.exited.is_some()
922-
|| self.ai_session_probe_pending
923-
|| self.ssh_destination.is_some()
924-
|| !self
925-
.running_program
926-
.as_deref()
927-
.and_then(crate::ai_agents::AgentKind::parse)
928-
.is_some_and(|agent| agent == crate::ai_agents::AgentKind::Codex)
929-
{
930-
return;
931-
}
932-
if self.last_ai_session_probe.is_some_and(|at| {
933-
at.elapsed()
934-
< std::time::Duration::from_secs(if self.ai_session.is_some() { 10 } else { 2 })
935-
}) {
936-
return;
937-
}
938-
let Some(exec_context) = self.exec_context.clone() else { return };
939-
let epoch = self.ai_session_probe_epoch;
940-
let pane_id = self.pane_id;
941-
let shell_pid = self.session.as_ref().map(|session| session.shell_pid);
942-
let previous_target = self.session_agent();
943-
self.ai_session_probe_pending = true;
944-
self.last_ai_session_probe = Some(std::time::Instant::now());
945-
let work = cx.background_executor().spawn(async move {
946-
crate::platform::ai_session_identity::probe_codex_session(
947-
pane_id,
948-
Some(&exec_context),
949-
shell_pid,
950-
)
951-
});
952-
cx.spawn(async move |this, cx| {
953-
let session_id = work.await;
954-
let _ = this.update(cx, |view, cx| {
955-
if view.ai_session_probe_epoch == epoch {
956-
view.ai_session_probe_pending = false;
957-
}
958-
if !probe_result_is_current(
959-
view.ai_session_probe_epoch,
960-
epoch,
961-
view.session_agent() != previous_target,
962-
view.running_program.as_deref(),
963-
) {
964-
return;
965-
}
966-
if let Some(session) = session_id {
967-
log::debug!("agent session identity from active rollout: pane={pane_id}");
968-
let target = crate::session::AgentSession {
969-
source: "codex".to_owned(),
970-
session_id: Some(session.session_id.clone()),
971-
session_file: Some(session.session_file),
972-
};
973-
let previous = view.recovery.target.clone();
974-
if !view.recovery.confirm(target) {
975-
return;
976-
}
977-
if previous != view.recovery.target {
978-
cx.emit(TerminalViewEvent::SessionIdentityChanged);
979-
}
980-
view.ai_session = Some(crate::display::AiSessionIdentity {
981-
source: "codex".to_owned(),
982-
session_id: session.session_id,
983-
});
984-
if let Some(cwd) = session.cwd {
985-
view.process_event(nebula_terminal::event::Event::CwdReport(cwd), cx);
986-
}
987-
view.ai_session_from_probe = true;
988-
cx.emit(TerminalViewEvent::TitleChanged);
989-
cx.notify();
990-
}
991-
});
992-
})
993-
.detach();
994-
}
995-
996903
pub(super) fn sync_native_prompt(&mut self) {
997904
if !self.suggest.suggest_env.is_this_machine() {
998905
return;

0 commit comments

Comments
 (0)