Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(hooks): stop tool-family labels leaking into handoffs and titles, fix file-activity warning (#895)

AkitaOnRails67574ecd27dd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 39186f2d..ace4f915 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
query before falling back. (#873)
### Fixed
+- Tool-family labels no longer leak into automatic handoffs and session-page
+ titles, and the file-activity handoff warning fires again. Every closed-tool
+ agent stores a call's title as `tool file` / `tool non-file` / … (a partition
+ of the calls, not a tool name); these were surfacing verbatim as `Tools used:
+ tool file, tool non-file` in handoffs and, for a session whose only non-prompt
+ observation was such a call, as the page title. The same spelling meant the
+ "session ended without a normal stop while working with files" heuristic —
+ which only matched the bare `file` spelling of the minority reserved-protocol
+ path — never fired for a real session. A shared recognizer now maps both
+ spellings, drops the labels from the handoff tool list and the title fallback,
+ and drives the file-activity warning from either. (#895)
- `ai-memory run`'s auto-wire no longer overwrites an installed session-aware
Claude Code MCP bridge with the static HTTP registration. The auto-wire
sentinel is keyed by client version, so the MCP step re-ran on every upgrade
diff --git a/crates/ai-memory-hooks/src/payload.rs b/crates/ai-memory-hooks/src/payload.rs
index 571d4e91..275acc04 100644
--- a/crates/ai-memory-hooks/src/payload.rs
+++ b/crates/ai-memory-hooks/src/payload.rs
@@ -660,6 +660,23 @@ pub(crate) fn is_safe_tool_title(title: &str) -> bool {
})
}
+/// Map a stored observation title back to the [`ToolFamily`] it was derived
+/// from, recognising **both** spellings this crate emits for a family label:
+/// the bare `canonical_tool_name` form the reserved-protocol path writes
+/// ("file" / "search-list" / "non-file" / "unknown") and the `"tool "`-prefixed
+/// [`safe_tool_title`] form every closed-tool agent writes ("tool file", …).
+///
+/// Returns `None` for a harness's own raw tool name ("edit", "bash", "Read"),
+/// which is never one of these labels. That distinction is load-bearing: it is
+/// what keeps the family labels out of handoffs, titles, and the file-activity
+/// heuristic while a real tool name still flows through. Shares the serde
+/// representation with [`safe_tool_title`] and [`is_safe_tool_title`], so a new
+/// `ToolFamily` variant is recognised here without a second edit.
+pub(crate) fn tool_family_from_title(title: &str) -> Option<ToolFamily> {
+ let family = title.strip_prefix("tool ").unwrap_or(title);
+ serde_json::from_value::<ToolFamily>(serde_json::Value::String(family.to_owned())).ok()
+}
+
fn safe_tool_body(
event: HookEvent,
metadata: Option<&ToolObservationMetadata>,
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index 10ef6106..ad7517cb 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -3136,7 +3136,14 @@ fn build_auto_handoff(
prompts.push(text.to_string());
}
}
- ObservationKind::PostToolUse | ObservationKind::PreToolUse if !obs.title.is_empty() => {
+ // Skip `tool <family>` / bare-`<family>` labels: a family is a
+ // partition of the calls, not a name for a tool, so "Tools used:
+ // tool file, tool non-file" tells the receiver nothing. Only a
+ // harness's own tool name is worth listing.
+ ObservationKind::PostToolUse | ObservationKind::PreToolUse
+ if !obs.title.is_empty()
+ && crate::payload::tool_family_from_title(&obs.title).is_none() =>
+ {
tools.insert(obs.title.as_str());
}
_ => {}
@@ -3222,10 +3229,12 @@ fn derive_open_questions(
// abnormally while working in the tree.
//
// The signal is the tool *family*, not the tool name. A PostToolUse
- // observation's title is `canonical_tool_name(tool_family)`, which is
- // only ever "file" / "search-list" / "non-file" / "unknown" — the
- // reserved protocol deliberately carries no raw tool names. Matching
- // "edit"/"write"/"patch" against that title can never succeed.
+ // observation's title carries the family in one of two spellings: the
+ // majority path (every closed-tool agent) writes `safe_tool_title`'s
+ // `"tool file"` / `"tool non-file"` / …, while the reserved-protocol
+ // path writes the bare `canonical_tool_name` form `"file"` / …. Both
+ // must match here, and `tool_family_from_title` recognises both; a raw
+ // tool name ("edit"/"write"/"patch") is neither and correctly does not.
//
// That same closed schema means read and write are indistinguishable:
// `ToolFamily::File` covers both, and `ToolOutcome` is only
@@ -3233,7 +3242,8 @@ fn derive_open_questions(
// made — only that the session touched files and then ended without a
// normal Stop, which is worth telling the receiver either way.
if let Some(tool) = last_tool {
- let touched_files = tool.title == canonical_tool_name(ToolFamily::File);
+ let touched_files =
+ crate::payload::tool_family_from_title(&tool.title) == Some(ToolFamily::File);
if touched_files && last_stop.is_none() {
return vec![
"Session ended without a normal stop while working with files".into(),
@@ -12949,6 +12959,29 @@ mod tests {
assert!(q[1].contains("working tree"), "got: {q:?}");
}
+ /// The same file-activity heuristic, but for the *majority* spelling: every
+ /// closed-tool agent stores `safe_tool_title`'s `"tool file"`, not the bare
+ /// `canonical_tool_name` `"file"` of the reserved-protocol path. Before
+ /// #895 this spelling never matched, so the heuristic was dead for almost
+ /// every real session.
+ #[test]
+ fn open_questions_detects_abnormal_exit_after_prefixed_file_activity() {
+ let obs = vec![
+ mk_obs(ObservationKind::UserPrompt, "fix bug", "fix the bug"),
+ mk_obs(
+ ObservationKind::PostToolUse,
+ "tool file",
+ "tool_family: file\noutcome: unknown",
+ ),
+ // No Stop observation — session ended mid-task.
+ ];
+ let last = Some("fix the bug".to_string());
+ let q = derive_open_questions(&obs, &last);
+ assert_eq!(q.len(), 2, "got: {q:?}");
+ assert!(q[0].contains("without a normal stop"), "got: {q:?}");
+ assert!(q[1].contains("working tree"), "got: {q:?}");
+ }
+
/// Guard against the regression this heuristic already had once: only
/// titles the ingest path can actually produce may drive it, so a raw
/// tool name must NOT trigger the file branch.
@@ -12968,6 +13001,66 @@ mod tests {
}
}
+ /// An automatic handoff built only from closed-tool observations (whose
+ /// titles are `safe_tool_title`'s `"tool file"` / `"tool non-file"` family
+ /// labels) must NOT emit a `Tools used:` line: a family is a partition of
+ /// the calls, not a name for a tool, so the label leaks nothing useful into
+ /// the handoff. A real tool name still produces the line (#895).
+ #[test]
+ fn auto_handoff_omits_tool_family_labels_from_tools_used() {
+ use ai_memory_core::{ProjectId, WorkspaceId};
+ let observations = vec![
+ mk_obs(ObservationKind::UserPrompt, "fix bug", "fix the bug"),
+ mk_obs(
+ ObservationKind::PostToolUse,
+ "tool file",
+ "tool_family: file\noutcome: unknown",
+ ),
+ mk_obs(
+ ObservationKind::PostToolUse,
+ "tool non-file",
+ "tool_family: non-file\noutcome: success",
+ ),
+ ];
+ let handoff = build_auto_handoff(
+ WorkspaceId::new(),
+ ProjectId::new(),
+ AgentKind::ClaudeCode,
+ SessionId::new(),
+ None,
+ &observations,
+ None,
+ );
+ assert!(
+ handoff
+ .next_steps
+ .iter()
+ .all(|s| !s.starts_with("Tools used:")),
+ "family labels must not surface as a Tools used line; got: {:?}",
+ handoff.next_steps
+ );
+
+ // Control: a real harness tool name still produces the line.
+ let with_real_tool = vec![
+ mk_obs(ObservationKind::UserPrompt, "fix bug", "fix the bug"),
+ mk_obs(ObservationKind::PostToolUse, "Edit", "edited main.rs"),
+ ];
+ let handoff = build_auto_handoff(
+ WorkspaceId::new(),
+ ProjectId::new(),
+ AgentKind::ClaudeCode,
+ SessionId::new(),
+ None,
+ &with_real_tool,
+ None,
+ );
+ assert!(
+ handoff.next_steps.iter().any(|s| s == "Tools used: Edit"),
+ "a real tool name must still be listed; got: {:?}",
+ handoff.next_steps
+ );
+ }
+
/// A search/list tool is file-adjacent but not file activity; it must
/// fall through to the prompt-based heuristics.
#[test]
diff --git a/crates/ai-memory-hooks/src/synth.rs b/crates/ai-memory-hooks/src/synth.rs
index cfef27a8..82746c5f 100644
--- a/crates/ai-memory-hooks/src/synth.rs
+++ b/crates/ai-memory-hooks/src/synth.rs
@@ -133,7 +133,14 @@ fn derive_title(observations: &[Observation], session_id: SessionId) -> String {
if obs.kind == ObservationKind::SessionStart {
continue;
}
- if !obs.title.is_empty() && !looks_like_title_scaffolding(&obs.title) {
+ // A `tool <family>` label is a partition of the calls, not a title:
+ // `looks_like_scaffolding` does not catch it, so reject it here or a
+ // session whose only non-prompt observation is a closed-tool call
+ // ("tool non-file") would take the label as its page title.
+ if !obs.title.is_empty()
+ && !looks_like_title_scaffolding(&obs.title)
+ && !is_safe_tool_title(&obs.title)
+ {
return obs.title.clone();
}
}
@@ -749,15 +756,24 @@ mod tests {
/// loop reached the `SessionStart` and the harness's model id became the
/// page title. The prompt was never scaffolding — it was absent, which is
/// why no filter on the string could have caught this.
+ ///
+ /// A `tool <family>` label (`safe_tool_title`) is not a title either: it
+ /// is a partition of the calls, so the fallback loop must skip it and fall
+ /// through to the session's own identity, never surface "tool non-file" as
+ /// the page title (#895).
#[test]
fn a_model_id_on_session_start_never_becomes_the_title() {
let sid = test_session_id();
- let with_a_later_title = vec![
+ let with_only_a_tool_family_label = vec![
obs(ObservationKind::SessionStart, "claude-opus-5[1m]"),
obs(ObservationKind::UserPrompt, ""),
obs(ObservationKind::PostToolUse, "tool non-file"),
];
- assert_eq!(derive_title(&with_a_later_title, sid), "tool non-file");
+ assert_eq!(
+ derive_title(&with_only_a_tool_family_label, sid),
+ format!("Session {sid}"),
+ "a tool-family label is not a page title"
+ );
let nothing_else = vec![
obs(ObservationKind::SessionStart, "claude-opus-5[1m]"),