Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions crates/acp-client/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use agent_client_protocol::{
Agent, ClientSideConnection, ContentBlock as AcpContentBlock, ImageContent, Implementation,
InitializeRequest, LoadSessionRequest, McpServer, NewSessionRequest, PermissionOptionId,
PromptRequest, ProtocolVersion, RequestPermissionOutcome, RequestPermissionRequest,
RequestPermissionResponse, SelectedPermissionOutcome, SessionNotification, SessionUpdate,
TextContent,
RequestPermissionResponse, SelectedPermissionOutcome, SessionConfigOption, SessionInfoUpdate,
SessionModelState, SessionNotification, SessionUpdate, TextContent,
};
use async_trait::async_trait;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
Expand Down Expand Up @@ -58,6 +58,22 @@ pub trait MessageWriter: Send + Sync {

/// Record the result/output of a tool call.
async fn record_tool_result(&self, content: &str);

/// Called when session info is updated (title, timestamps, etc.).
///
/// Delivered via `SessionUpdate::SessionInfoUpdate` notifications during a
/// session, or extracted from setup responses.
async fn on_session_info_update(&self, _info: &SessionInfoUpdate) {}

/// Called when model state is received from session setup responses.
///
/// `SessionModelState` is only delivered in `NewSessionResponse` and
/// `LoadSessionResponse`. Mid-session model changes are surfaced through
/// `on_config_option_update` via `ConfigOptionUpdate` with category `Model`.
async fn on_model_state_update(&self, _state: &SessionModelState) {}

/// Called when session configuration options change.
async fn on_config_option_update(&self, _options: &[SessionConfigOption]) {}
}

/// Storage interface for persisting agent session data.
Expand Down Expand Up @@ -834,6 +850,21 @@ impl agent_client_protocol::Client for AcpNotificationHandler {
&self,
notification: SessionNotification,
) -> agent_client_protocol::Result<()> {
// Session metadata events are forwarded regardless of phase.
match &notification.update {
SessionUpdate::SessionInfoUpdate(info) => {
self.writer.on_session_info_update(info).await;
return Ok(());
Comment on lines +853 to +857
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve replay bookkeeping for metadata notifications

Avoid returning before phase handling for SessionInfoUpdate/ConfigOptionUpdate during resume. In Replaying, the bookkeeping that marks received_any and refreshes last_notification_at now never runs for these updates, so run_acp_protocol cannot satisfy is_replay_idle and falls back to the 10s absolute timeout when the replay stream contains only metadata events. That adds a deterministic startup delay on resumed sessions for agents that replay title/config updates without message/tool chunks.

Useful? React with 👍 / 👎.

}
SessionUpdate::ConfigOptionUpdate(update) => {
self.writer
.on_config_option_update(&update.config_options)
.await;
return Ok(());
}
_ => {}
}

// Determine the action to take under the lock, then drop the lock
// before calling into the writer to avoid holding it across await points.
enum LiveAction {
Expand Down Expand Up @@ -1032,6 +1063,7 @@ async fn run_acp_protocol(
connection,
working_dir,
store,
&handler.writer,
our_session_id,
acp_session_id,
mcp_servers,
Expand Down Expand Up @@ -1092,6 +1124,7 @@ async fn setup_acp_session(
connection: &ClientSideConnection,
working_dir: &Path,
store: &Arc<dyn Store>,
writer: &Arc<dyn MessageWriter>,
our_session_id: &str,
acp_session_id: Option<&str>,
mcp_servers: &[McpServer],
Expand Down Expand Up @@ -1136,14 +1169,21 @@ async fn setup_acp_session(
"Resuming ACP session {existing_id} via load_session for session {our_session_id}"
);

connection
let load_response = connection
.load_session(
LoadSessionRequest::new(existing_id.to_string(), working_dir.to_path_buf())
.mcp_servers(mcp_servers.to_vec()),
)
.await
.map_err(|e| format!("Failed to load ACP session: {e:?}"))?;

if let Some(ref models) = load_response.models {
writer.on_model_state_update(models).await;
}
if let Some(ref options) = load_response.config_options {
writer.on_config_option_update(options).await;
}

Ok(existing_id.to_string())
}
None => {
Expand All @@ -1158,6 +1198,14 @@ async fn setup_acp_session(
store
.set_agent_session_id(our_session_id, &new_id)
.map_err(|e| format!("Failed to save agent session ID: {e}"))?;

if let Some(ref models) = session_response.models {
writer.on_model_state_update(models).await;
}
if let Some(ref options) = session_response.config_options {
writer.on_config_option_update(options).await;
}

Ok(new_id)
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/acp-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ mod simple;
mod types;

// Re-export the main API
pub use agent_client_protocol::{McpServer, McpServerHttp, McpServerSse};
pub use agent_client_protocol::{
ConfigOptionUpdate, McpServer, McpServerHttp, McpServerSse, ModelInfo, SessionConfigOption,
SessionConfigOptionCategory, SessionInfoUpdate, SessionModelState,
};
pub use driver::{
strip_code_fences, AcpDriver, AgentDriver, BasicMessageWriter, MessageWriter, Store,
};
Expand Down