Skip to content

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

Rust

fix(hooks): treat a marked OMP subagent end like an OpenCode child

João Matheus5766c8173c40
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index 1a7c799d..7e04a6d2 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -4778,10 +4778,12 @@ async fn process_authorized(
// read.
let handoff_owner = owner_stamp_for_event(state, session_owner.as_ref()).await;
// An OpenCode child session has its own id and forwards its parent as
- // `agent_id`; its end must not hand the next session a sub-task baton.
- // Other harnesses are not gated: Claude Code also sets `agent_type` on
- // a top-level `--agent` session, which still owns its baton.
- let child_session = env.agent == AgentKind::OpenCode && body_is_subagent(&env.raw);
+ // `agent_id`, and the OMP extension marks a subagent session the same
+ // way; its end must not hand the next session a sub-task baton. Other
+ // harnesses are not gated: Claude Code also sets `agent_type` on a
+ // top-level `--agent` session, which still owns its baton.
+ let child_session =
+ matches!(env.agent, AgentKind::OpenCode | AgentKind::Omp) && body_is_subagent(&env.raw);
// The opt-out covers both automatic batons: a session's end and a
// turn checkpoint, which is OpenCode's only baton since a plugin
// unload no longer ends its sessions, and Antigravity's since it has
@@ -14941,6 +14943,62 @@ pub(crate) mod tests {
);
}
+ /// The OMP extension posts a subagent session's events with `agent_id`
+ /// (OMP runs subagents in the parent's process); that session's end closes
+ /// and summarizes it without a baton. A top-level OMP session in the same
+ /// project still leaves one, so the gate is per session, not per agent.
+ #[tokio::test]
+ async fn omp_subagent_session_end_closes_and_summarizes_without_baton() {
+ let tmp = TempDir::new().unwrap();
+ let state = make_state(&tmp).await;
+ let omp_event = |session: SessionId, event: &str, agent_id: Option<&str>| {
+ let mut body = serde_json::json!({
+ "sessionID": session.to_string(),
+ "prompt": "Find where the config is loaded",
+ });
+ if let Some(agent_id) = agent_id {
+ body["agent_id"] = serde_json::json!(agent_id);
+ }
+ HookEnvelope::from_query_and_body(
+ HookQuery {
+ event: event.into(),
+ agent: Some("omp".into()),
+ ..Default::default()
+ },
+ body,
+ )
+ };
+
+ let subagent = SessionId::new();
+ for event in ["user-prompt", "stop", "session-end"] {
+ let env = omp_event(subagent, event, Some("0-Explore"));
+ process(&state, env, None, Vec::new()).await.unwrap();
+ }
+ assert!(!session_pages(&state).await.is_empty());
+ assert!(
+ !open_handoff_exists(&state).await,
+ "an OMP subagent's end must not leave a baton"
+ );
+ assert_eq!(
+ state
+ .reader
+ .latest_completed_session_for_project(state.workspace_id, state.project_id)
+ .await
+ .unwrap(),
+ Some(subagent)
+ );
+
+ let top_level = SessionId::new();
+ for event in ["user-prompt", "stop", "session-end"] {
+ let env = omp_event(top_level, event, None);
+ process(&state, env, None, Vec::new()).await.unwrap();
+ }
+ assert!(
+ open_handoff_exists(&state).await,
+ "a top-level OMP session still hands over its baton"
+ );
+ }
+
// Claude Code stamps `agent_type` on a top-level `--agent` session, so
// that marker must not cost it its baton; and a captured Stop body is
// surfaced for any agent in the capture table, not only OpenCode.