From a0f3ef104bfe34c3dc76520d200cd439d249b4c5 Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Fri, 16 Jan 2026 16:39:33 +0100 Subject: [PATCH] refactor(workspace, cli): decouple ephemeral conversation cleanup Move the cleanup of ephemeral conversations from the `persist` method in `Workspace` to a dedicated `remove_ephemeral_conversations` method. This new method is then explicitly called within the CLI after a task execution finishes. This change ensures that ephemeral conversations are not prematurely deleted during intermediate state persistence calls, providing better control over their lifecycle within the workspace. Signed-off-by: Jean Mertz --- crates/jp_cli/src/lib.rs | 3 +++ crates/jp_workspace/src/lib.rs | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/jp_cli/src/lib.rs b/crates/jp_cli/src/lib.rs index d168e13..893c0cf 100644 --- a/crates/jp_cli/src/lib.rs +++ b/crates/jp_cli/src/lib.rs @@ -303,6 +303,9 @@ fn run_inner(cli: Cli) -> Result { ) .map_err(Error::Task)?; + // Remove ephemeral conversations that are no longer needed. + ctx.workspace.remove_ephemeral_conversations(); + output.map_err(Into::into) } } diff --git a/crates/jp_workspace/src/lib.rs b/crates/jp_workspace/src/lib.rs index 0cd7a00..f151fc0 100644 --- a/crates/jp_workspace/src/lib.rs +++ b/crates/jp_workspace/src/lib.rs @@ -245,7 +245,6 @@ impl Workspace { trace!("Persisting state."); - let active_id = self.active_conversation_id(); let Some(storage) = self.storage.as_mut() else { return Ok(()); }; @@ -261,7 +260,6 @@ impl Workspace { .active_conversation_id, &self.state.local.active_conversation, )?; - storage.remove_ephemeral_conversations(&[active_id]); info!(path = %self.root.display(), "Persisted state."); Ok(()) @@ -294,6 +292,19 @@ impl Workspace { Ok(()) } + pub fn remove_ephemeral_conversations(&mut self) { + if self.disable_persistence { + return; + } + + let active_id = self.active_conversation_id(); + let Some(storage) = self.storage.as_mut() else { + return; + }; + + storage.remove_ephemeral_conversations(&[active_id]); + } + /// Gets the ID of the active conversation. #[must_use] pub fn active_conversation_id(&self) -> ConversationId {