Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(agent): restore canonical tool names during history replay (#8289)
Eric Hayes8f8efd1c74c4
diff --git a/crates/agent_inmem/AGENTS.md b/crates/agent_inmem/AGENTS.mdindex 6c1594c800..f4bfd54c40 100644--- a/crates/agent_inmem/AGENTS.md+++ b/crates/agent_inmem/AGENTS.md@@ -44,6 +44,11 @@ milliseconds instead of waiting on container provisioning.- `cargo test -p agent_inmem` (`SQLX_OFFLINE` unset).+## Gotchas++- Replay tool calls using `_meta.macro.toolName`; ACP titles may be human-readable+ MCP labels, so only use the title for older frames without tool-name metadata.+## Related- Rules: `.agents/rules/rust/architecture.md`diff --git a/crates/agent_inmem/src/domain/replay.rs b/crates/agent_inmem/src/domain/replay.rsindex 16030d10c5..68809120d8 100644--- a/crates/agent_inmem/src/domain/replay.rs+++ b/crates/agent_inmem/src/domain/replay.rs@@ -10,10 +10,10 @@//!//! Replay is deliberately lenient: a frame it does not recognize contributes//! nothing rather than failing the attach, because a partially-rebuilt-//! context is strictly better than none. Two shapes are intentionally lossy:-//! thought chunks are skipped (past reasoning is not replayed to the model),-//! and a tool call is rebuilt under the display title it was streamed with,-//! which for the Macro product toolset is the tool name itself.+//! context is strictly better than none. Thought chunks are skipped (past+//! reasoning is not replayed to the model). Tool calls use their canonical+//! name from `_meta.macro.toolName`; only older frames without that metadata+//! fall back to the display title.use agent::ReasoningEffort;use agent::types::AssistantMessagePart;@@ -29,7 +29,7 @@ use agent_session::domain::model::Message;use futures::future::BoxFuture;use std::collections::HashSet;-use crate::domain::agent::close_dangling_tool_calls;+use crate::domain::agent::{META_NAMESPACE, close_dangling_tool_calls};use crate::domain::model_options::REASONING_EFFORT_CONFIG_ID;use crate::domain::session::{HistoryEntry, UserPrompt, end_of_turn, splice_summary};use agent_runtime_protocol::domain::context::ContextSummaryNotification;@@ -244,7 +244,14 @@ fn apply_update(parts: &mut Vec<AssistantMessagePart>, update: SessionUpdate) {}SessionUpdate::ToolCall(call) => {parts.push(AssistantMessagePart::ToolCall {- name: call.title.clone(),+ name: call+ .meta+ .as_ref()+ .and_then(|meta| meta.get(META_NAMESPACE))+ .and_then(|meta| meta.get("toolName"))+ .and_then(serde_json::Value::as_str)+ .unwrap_or(&call.title)+ .to_owned(),json: call.raw_input.clone().unwrap_or(serde_json::Value::Null),id: call.tool_call_id.0.to_string(),});diff --git a/crates/agent_inmem/src/domain/replay/test.rs b/crates/agent_inmem/src/domain/replay/test.rsindex 8bb24638d9..0407e847f3 100644--- a/crates/agent_inmem/src/domain/replay/test.rs+++ b/crates/agent_inmem/src/domain/replay/test.rs@@ -250,6 +250,50 @@ fn a_logged_turn_replays_as_the_history_the_live_agent_recorded() {}}+#[test]+fn mcp_calls_replay_their_canonical_names_instead_of_display_titles() {+ let input = serde_json::json!({"query": "standup"});+ let output = serde_json::json!({"hits": 1});+ let history = replay_history(vec![+ prompt_frame("search Slack"),+ update_frame(SessionUpdate::ToolCall(+ AcpToolCall::new("call-1", "Search Slack")+ .status(ToolCallStatus::InProgress)+ .raw_input(input.clone())+ .meta(serde_json::Map::from_iter([(+ "macro".to_owned(),+ serde_json::json!({"toolName": "mcp__slack__search"}),+ )])),+ )),+ update_frame(SessionUpdate::ToolCallUpdate(ToolCallUpdate::new(+ "call-1",+ ToolCallUpdateFields::new()+ .status(ToolCallStatus::Completed)+ .raw_output(output.clone()),+ ))),+ answer("search Slack", "end_turn"),+ ]);++ let [HistoryEntry::User { .. }, HistoryEntry::Assistant(parts)] = history.as_slice() else {+ panic!("one tool turn should replay, got {history:#?}");+ };+ assert_eq!(+ parts,+ &[+ AssistantMessagePart::ToolCall {+ name: "mcp__slack__search".to_owned(),+ json: input,+ id: "call-1".to_owned(),+ },+ AssistantMessagePart::ToolCallResponseJson {+ name: "mcp__slack__search".to_owned(),+ json: output,+ id: "call-1".to_owned(),+ },+ ]+ );+}+#[test]fn a_compact_that_cleared_the_context_before_summaries_still_clears_it() {let history = replay_history(vec![