From 444d4e9e233f55368713443dc2ee0225af9320a2 Mon Sep 17 00:00:00 2001 From: Chris Busillo Date: Mon, 1 Jun 2026 16:45:02 -0400 Subject: [PATCH] fix(tui): cache metadata-free auto review terminals --- code-rs/tui/src/chatwidget.rs | 67 ++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/code-rs/tui/src/chatwidget.rs b/code-rs/tui/src/chatwidget.rs index 6e6946b4afe..cc6ac2ab0ef 100644 --- a/code-rs/tui/src/chatwidget.rs +++ b/code-rs/tui/src/chatwidget.rs @@ -34572,7 +34572,7 @@ use code_core::protocol::OrderMeta; .expect("metadata-free completion should not clear current review"); assert_eq!(state.agent_id.as_deref(), Some("agent-current")); assert_eq!(state.snapshot.as_deref(), Some("snap-current")); - assert!(!chat.processed_auto_review_agents.contains("agent-current")); + assert!(chat.processed_auto_review_agents.contains("agent-current")); assert!(!history_contains_text(chat, "Auto Review: 1 issue(s) found")); assert_no_code_ops_pending(&mut code_op_rx); } @@ -34608,7 +34608,7 @@ use code_core::protocol::OrderMeta; .expect("pre-start completion without session proof should not clear review"); assert!(state.agent_id.is_none()); assert!(state.snapshot.is_none()); - assert!(!chat.processed_auto_review_agents.contains("agent-early")); + assert!(chat.processed_auto_review_agents.contains("agent-early")); assert!(!history_contains_text(chat, "Auto Review: 1 issue(s) found")); assert_no_code_ops_pending(&mut code_op_rx); } @@ -34643,8 +34643,8 @@ use code_core::protocol::OrderMeta; "metadata-free pre-start status should not clear the active review" ); assert!( - !chat.processed_auto_review_agents.contains("agent-current"), - "missing metadata is not enough proof to permanently discard the agent" + chat.processed_auto_review_agents.contains("agent-current"), + "missing metadata is cached so it cannot resurface if the active review clears" ); assert!(!history_contains_text(chat, "Auto Review: 1 issue(s) found")); assert_no_code_ops_pending(&mut code_op_rx); @@ -34674,6 +34674,46 @@ use code_core::protocol::OrderMeta; assert!(note.contains("Background auto-review completed and reported 1 issue(s)")); } + #[test] + fn cached_metadata_free_terminal_status_does_not_resurface_after_review_clears() { + let mut harness = ChatWidgetHarness::new(); + let chat = harness.chat(); + let mut code_op_rx = replace_code_op_channel(chat); + let session_id = uuid::Uuid::new_v4(); + chat.session_id = Some(session_id); + chat.config.tui.auto_review_enabled = true; + chat.background_review = Some(BackgroundReviewState { + worktree_path: PathBuf::new(), + branch: String::new(), + agent_id: None, + snapshot: None, + owner_session_id: Some(session_id), + base: None, + last_seen: Instant::now(), + }); + + chat.observe_auto_review_status(&[completed_auto_review_agent( + "agent-stale", + "auto-review-stale", + None, + None, + )]); + assert!(chat.processed_auto_review_agents.contains("agent-stale")); + assert!(!history_contains_text(chat, "Auto Review: 1 issue(s) found")); + assert_no_code_ops_pending(&mut code_op_rx); + + chat.background_review = None; + chat.observe_auto_review_status(&[completed_auto_review_agent( + "agent-stale", + "auto-review-stale", + None, + None, + )]); + + assert!(!history_contains_text(chat, "Auto Review: 1 issue(s) found")); + assert_no_code_ops_pending(&mut code_op_rx); + } + #[test] fn background_review_start_event_with_wrong_run_id_does_not_replace_current_run() { let mut harness = ChatWidgetHarness::new(); @@ -34829,7 +34869,7 @@ use code_core::protocol::OrderMeta; .expect("metadata-free completion should not clear current review"); assert_eq!(state.agent_id.as_deref(), Some("agent-current")); assert_eq!(state.snapshot.as_deref(), Some("snap-current")); - assert!(!chat.processed_auto_review_agents.contains("agent-current")); + assert!(chat.processed_auto_review_agents.contains("agent-current")); assert!(!history_contains_text(chat, "Auto Review: 1 issue(s) found")); assert_no_code_ops_pending(&mut code_op_rx); } @@ -39879,9 +39919,7 @@ impl ChatWidget<'_> { "ignoring stale or cross-session auto-review agent status" ); if is_terminal { - if auto_review_identity_mismatch_is_final(reason) { - self.remember_processed_auto_review_agent(&agent.id); - } + self.remember_processed_auto_review_agent(&agent.id); } continue; } @@ -39932,7 +39970,11 @@ impl ChatWidget<'_> { } if is_terminal && self.processed_auto_review_agents.contains(&agent.id) { - continue; + if self.background_review.is_some() { + self.forget_processed_auto_review_agent(&agent.id); + } else { + continue; + } } if !is_terminal { continue; @@ -40466,6 +40508,13 @@ impl ChatWidget<'_> { } } + fn forget_processed_auto_review_agent(&mut self, agent_id: &str) { + if self.processed_auto_review_agents.remove(agent_id) { + self.processed_auto_review_agent_order + .retain(|stored| stored != agent_id); + } + } + fn prune_agent_runtime_cache(&mut self, current_agents: &[code_core::protocol::AgentInfo]) { if self.agent_runtime.len() <= MAX_AGENT_RUNTIME_ENTRIES { return;