A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
keep shutdown and replaced close errors visible (#3339)
kt19808d092e28
diff --git a/crates/pa-cli/tests/interactive_daemon_e2e.rs b/crates/pa-cli/tests/interactive_daemon_e2e.rsindex 496d29c7a0..147191d547 100644--- a/crates/pa-cli/tests/interactive_daemon_e2e.rs+++ b/crates/pa-cli/tests/interactive_daemon_e2e.rs@@ -5507,3 +5507,156 @@ async fn tui_accepted_then_killed_turn_renders_closed_error() {);drop(supervisor);}++/// Both terminal close reasons remain visible after a later, replaceable turn status.+#[tokio::test]+async fn tui_close_reason_rows_survive_late_turn_status() {+ for (reason, explanation) in [+ ("shutdown", "The Prime Agent daemon shut down while this window was attached. The session transcript remains saved; restart Prime Agent and reopen it from Agents View."),+ ("replaced", "The daemon replaced this agent session with another session. Reopen the current session from Agents View."),+ ] {+ assert_close_reason_survives_late_turn_status(reason, explanation).await;+ }+}++async fn assert_close_reason_survives_late_turn_status(reason: &str, explanation: &str) {+ let dir = tempfile::TempDir::new().expect("temp dir");+ let session_dir = dir.path().join("agent/sessions");+ std::fs::create_dir_all(&session_dir).expect("session dir");+ let supervisor = spawn_supervisor(dir.path());+ let script = serde_json::json!({ "responses": [+ { "text": "reply must not arrive", "delayMs": 60_000 },+ ] });+ let script_path = dir.path().join("script.json");+ let session_id = create_session_via_daemon(+ &supervisor.socket,+ &script_path,+ &script,+ dir.path(),+ &session_dir,+ )+ .await;+ let kill_socket = supervisor.socket.clone();+ let reason_owned = reason.to_string();+ let kill_session_id = session_id.clone();+ let kill_task = tokio::spawn(async move {+ let (client, _events) = pa_tui::daemon_client::DaemonClient::connect(&kill_socket)+ .await+ .expect("connect supervisor for kill");+ let deadline = Instant::now() + Duration::from_secs(20);+ loop {+ let state = client+ .request_ok(DaemonCommand::GetConnectionState {+ id: None,+ active_session_id: kill_session_id.clone(),+ rest: serde_json::Map::default(),+ })+ .await+ .expect("get worker connection state");+ if state["isStreaming"] == true {+ break;+ }+ assert!(+ Instant::now() < deadline,+ "worker never began the accepted turn: {state}"+ );+ tokio::time::sleep(Duration::from_millis(25)).await;+ }+ client+ .request_ok(DaemonCommand::Kill {+ id: None,+ active_session_id: kill_session_id,+ rest: serde_json::Map::from_iter([(+ "rlmCloseReason".to_string(),+ serde_json::Value::String(reason_owned),+ )]),+ })+ .await+ .expect("kill admitted session");+ client.close();+ });+ let options = pa_tui::interactive::InteractiveOptions {+ models: None,+ socket_path: supervisor.socket.clone(),+ cwd: dir.path().to_path_buf(),+ session_dir: Some(session_dir),+ script_path: Some(script_path),+ model_selection: pa_tui::interactive::ModelSelection::default(),+ model_catalog: Vec::new(),+ model_configured_providers: std::collections::HashSet::default(),+ model_recent_models: Vec::new(),+ default_thinking_level: None,+ no_session: false,+ session: pa_tui::interactive::SessionSelection::Attach(session_id),+ show_images: true,+ fullscreen_mouse: true,+ initial_message: None,+ theme: "prime".to_string(),+ code_block_indent: " ".to_string(),+ tree_filter_mode: String::new(),+ branch_summary_skip_prompt: false,+ version: "0.0.0".to_string(),+ onboarding: None,+ telemetry_disabled: None,+ client_auth: None,+ traces: None,+ provider_auth: None,+ update_commands: None,+ telemetry: None,+ keybindings: pa_tui::keybindings::KeybindingsManager::new(),+ session_rlm_depth: None,+ prompt_stash: std::sync::Arc::default(),+ session_has_children: false,+ restore_dock_focus: false,+ client_settings: None,+ };+ let error_row = format!("⚠ Error: {explanation}");+ let plan = pa_tui::interactive::HeadlessPlan {+ steps: vec![+ pa_tui::interactive::HeadlessStep::Submit("held accepted prompt".to_string()),+ // The cancellation status is a later, replaceable note. Require+ // it first so the error assertion covers the end state after+ // the status that used to overwrite `session closed (killed)`.+ pa_tui::interactive::HeadlessStep::WaitRender {+ needle: "turn failed: prompt cancelled".to_string(),+ timeout_ms: 30_000,+ },+ pa_tui::interactive::HeadlessStep::WaitRender {+ needle: error_row.clone(),+ timeout_ms: 30_000,+ },+ ],+ width: 180,+ height: 30,+ };+ let outcome = run_headless_bounded(options, plan)+ .await+ .expect("interactive run");+ kill_task.await.expect("the kill task");+ let rendered = outcome.frames.join("\n");+ assert!(+ rendered.contains(&error_row),+ "{reason} turn had {} frames without the TS error row; old_info={}; final={}",+ outcome.frames.len(),+ rendered.contains(&format!("session closed ({reason})")),+ outcome.frames.last().expect("final frame")+ );+ assert!(+ !rendered.contains("reply must not arrive"),+ "held response leaked:\n{rendered}"+ );+ let last = outcome.frames.last().expect("final frame");+ assert!(+ last.contains("turn failed: prompt cancelled"),+ "the post-close cancellation must reach the frame:\n{last}"+ );+ assert!(+ last.contains(&error_row),+ "close error row must persist after cancellation:\n{last}"+ );+ assert!(+ !last.contains(&format!("session closed ({reason})")),+ "info downgrade remains:\n{last}"+ );+ drop(supervisor);+}diff --git a/crates/pa-tui/src/session_ui/apply.rs b/crates/pa-tui/src/session_ui/apply.rsindex 265e0f141e..ba828af16a 100644--- a/crates/pa-tui/src/session_ui/apply.rs+++ b/crates/pa-tui/src/session_ui/apply.rs@@ -268,13 +268,20 @@ impl SessionUi {if active_session_id == self.active_session_id {self.turn_active = false;view.working = None;- if reason == "killed" {- self.error_row(+ match reason.as_str() {+ "shutdown" => self.error_row(+ "The Prime Agent daemon shut down while this window was attached. The session transcript remains saved; restart Prime Agent and reopen it from Agents View.",+ view,+ ),+ "replaced" => self.error_row(+ "The daemon replaced this agent session with another session. Reopen the current session from Agents View.",+ view,+ ),+ "killed" => self.error_row("The daemon stopped this agent session. Its transcript remains saved and can be reopened from Agents View.",view,- );- } else {- self.note(&format!("session closed ({reason})"), view);+ ),+ _ => self.note(&format!("session closed ({reason})"), view),}}}