Skip to content

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

Rust

refactor(store): type atomic handoff acceptance

AkitaOnRails29cd30d356d9
diff --git a/crates/ai-memory-core/src/handoff.rs b/crates/ai-memory-core/src/handoff.rs
index 0dafb72b..29ee4b13 100644
--- a/crates/ai-memory-core/src/handoff.rs
+++ b/crates/ai-memory-core/src/handoff.rs
@@ -11,7 +11,10 @@ use std::path::PathBuf;
use jiff::Timestamp;
use serde::{Deserialize, Serialize};
-use crate::ids::{AgentKind, HandoffId, ProjectId, SessionId, WorkspaceId};
+use crate::{
+ OwnerFilter,
+ ids::{AgentKind, HandoffId, ProjectId, SessionId, WorkspaceId},
+};
/// State machine of a single handoff row.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
@@ -84,6 +87,29 @@ pub struct NewHandoff {
pub owner_user: Option<String>,
}
+/// Scope, ownership, and receiver metadata for an atomic handoff claim.
+#[derive(Debug, Clone)]
+pub struct HandoffAcceptance {
+ /// Handoff being claimed.
+ pub handoff_id: HandoffId,
+ /// Workspace the caller resolved before the claim.
+ pub workspace_id: WorkspaceId,
+ /// Project the caller resolved before the claim.
+ pub project_id: ProjectId,
+ /// Agent CLI accepting the handoff.
+ pub accepting_agent: AgentKind,
+ /// Session accepting the handoff, when known.
+ pub accepting_session: Option<SessionId>,
+ /// Operator accepting the handoff, in [`crate::IdentityKey::storage_key`]
+ /// form.
+ pub accepting_user: Option<String>,
+ /// Ownership boundary the caller is authorized to claim through.
+ pub owner_filter: OwnerFilter,
+ /// Working directory of the receiving session, used to bound automatic
+ /// handoff supersession.
+ pub receiving_cwd: Option<String>,
+}
+
/// Materialised view of a handoff row.
#[derive(Debug, Clone, Serialize)]
pub struct Handoff {
diff --git a/crates/ai-memory-core/src/lib.rs b/crates/ai-memory-core/src/lib.rs
index 346c74cd..0ef64a1a 100644
--- a/crates/ai-memory-core/src/lib.rs
+++ b/crates/ai-memory-core/src/lib.rs
@@ -42,7 +42,7 @@ pub use actor::{
SKIP_ADMISSION_CHAIN_HEADER, owner_stamp, parse_skip_admission_chain, skip_admission_chain_for,
};
pub use error::{MemoryError, MemoryResult};
-pub use handoff::{Handoff, HandoffState, NewHandoff};
+pub use handoff::{Handoff, HandoffAcceptance, HandoffState, NewHandoff};
pub use ids::{
AgentKind, AutoImproveProposalId, AutoImproveRunId, EntityId, HandoffId, ManagedRunId,
ObservationId, PageFeedbackId, PageId, PagePath, ProjectId, SessionId, UserId, WorkspaceId,
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index 4662e89e..12828435 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -1285,15 +1285,19 @@ async fn fetch_and_accept_handoff(
state
.writer
.accept_startup_context(
- handoff.as_ref().map(|handoff| handoff.id),
- ws,
- proj,
- agent,
- None,
- actor.as_ref().map(IdentityKey::storage_key),
- owner_filter,
+ handoff
+ .as_ref()
+ .map(|handoff| ai_memory_core::HandoffAcceptance {
+ handoff_id: handoff.id,
+ workspace_id: ws,
+ project_id: proj,
+ accepting_agent: agent,
+ accepting_session: None,
+ accepting_user: actor.as_ref().map(IdentityKey::storage_key),
+ owner_filter,
+ receiving_cwd: query.cwd.clone(),
+ }),
managed.as_ref().map(|managed| managed.run_id),
- query.cwd.clone(),
)
.await?
} else {
diff --git a/crates/ai-memory-mcp/src/server.rs b/crates/ai-memory-mcp/src/server.rs
index c5088ce3..38743002 100644
--- a/crates/ai-memory-mcp/src/server.rs
+++ b/crates/ai-memory-mcp/src/server.rs
@@ -2907,16 +2907,16 @@ impl AiMemoryServer {
// to two agents.
let claimed = self
.writer
- .accept_handoff(
- h.id,
- ws,
- proj,
- AgentKind::Other,
- None,
- actor_user.clone(),
+ .accept_handoff(ai_memory_core::HandoffAcceptance {
+ handoff_id: h.id,
+ workspace_id: ws,
+ project_id: proj,
+ accepting_agent: AgentKind::Other,
+ accepting_session: None,
+ accepting_user: actor_user.clone(),
owner_filter,
receiving_cwd,
- )
+ })
.await
.map_err(|e| McpError::internal_error(e.to_string(), None))?;
if claimed {
diff --git a/crates/ai-memory-store/src/lib.rs b/crates/ai-memory-store/src/lib.rs
index d0c85685..6b0ceadc 100644
--- a/crates/ai-memory-store/src/lib.rs
+++ b/crates/ai-memory-store/src/lib.rs
@@ -127,10 +127,10 @@ impl Store {
mod tests {
use super::*;
use ai_memory_core::{
- ActorContext, AgentKind, HandoffId, HandoffState, LinkTarget, ManagedRunId, NewHandoff,
- NewObservation, NewPage, NewSession, NewWorkstreamEvent, ObservationId, ObservationKind,
- PageId, PagePath, ProjectId, Sanitized, Sanitizer, SessionId, Tier, UserId, WorkspaceId,
- WorkstreamEventKind,
+ ActorContext, AgentKind, HandoffAcceptance, HandoffId, HandoffState, LinkTarget,
+ ManagedRunId, NewHandoff, NewObservation, NewPage, NewSession, NewWorkstreamEvent,
+ ObservationId, ObservationKind, PageId, PagePath, ProjectId, Sanitized, Sanitizer,
+ SessionId, Tier, UserId, WorkspaceId, WorkstreamEventKind,
};
use rusqlite::{Connection, params};
use sha2::{Digest, Sha256};
@@ -4977,21 +4977,21 @@ mod tests {
files_touched: Vec::new(),
owner_user: None,
};
+ let acceptance = |handoff_id, receiving_cwd| HandoffAcceptance {
+ handoff_id,
+ workspace_id: ws,
+ project_id: proj,
+ accepting_agent: AgentKind::Codex,
+ accepting_session: None,
+ accepting_user: None,
+ owner_filter: ai_memory_core::OwnerFilter::Any,
+ receiving_cwd,
+ };
let first_handoff = store.writer.insert_handoff(insert_handoff()).await.unwrap();
let accepted = store
.writer
- .accept_startup_context(
- Some(first_handoff),
- ws,
- proj,
- AgentKind::Codex,
- None,
- None,
- ai_memory_core::OwnerFilter::Any,
- Some(run.run_id),
- None,
- )
+ .accept_startup_context(Some(acceptance(first_handoff, None)), Some(run.run_id))
.await
.unwrap();
assert_eq!(
@@ -5013,17 +5013,7 @@ mod tests {
let second_handoff = store.writer.insert_handoff(insert_handoff()).await.unwrap();
let rejected = store
.writer
- .accept_startup_context(
- Some(second_handoff),
- ws,
- proj,
- AgentKind::Codex,
- None,
- None,
- ai_memory_core::OwnerFilter::Any,
- Some(run.run_id),
- None,
- )
+ .accept_startup_context(Some(acceptance(second_handoff, None)), Some(run.run_id))
.await
.unwrap();
assert_eq!(
@@ -5086,15 +5076,8 @@ mod tests {
let rejected_auto = store
.writer
.accept_startup_context(
- Some(selected_auto),
- ws,
- proj,
- AgentKind::Codex,
- None,
- None,
- ai_memory_core::OwnerFilter::Any,
+ Some(acceptance(selected_auto, Some("/repo/api/src".into()))),
Some(run.run_id),
- Some("/repo/api/src".into()),
)
.await
.unwrap();
diff --git a/crates/ai-memory-store/src/ops.rs b/crates/ai-memory-store/src/ops.rs
index 58ff8419..1f35b423 100644
--- a/crates/ai-memory-store/src/ops.rs
+++ b/crates/ai-memory-store/src/ops.rs
@@ -7,9 +7,9 @@
use std::collections::BTreeSet;
use ai_memory_core::{
- AgentKind, EntityId, HandoffId, IdentityKey, LinkTarget, NewHandoff, NewObservation, NewPage,
- NewSession, ObservationId, ObservationKind, OwnerFilter, PageId, PagePath, ProjectId,
- SessionId, WorkspaceId,
+ AgentKind, EntityId, HandoffAcceptance, HandoffId, IdentityKey, LinkTarget, NewHandoff,
+ NewObservation, NewPage, NewSession, ObservationId, ObservationKind, OwnerFilter, PageId,
+ PagePath, ProjectId, SessionId, WorkspaceId,
};
/// Summary returned by [`reorg_sessions`] and exposed via
@@ -1529,20 +1529,18 @@ fn insert_handoff_row(conn: &Transaction<'_>, h: &NewHandoff) -> StoreResult<Han
/// `receiving_cwd` is where the *claiming* session is starting, not where the
/// claimed handoff came from; it bounds the post-claim sweep of stale automatic
/// handoffs.
-pub fn accept_handoff(
- conn: &mut Connection,
- handoff_id: &HandoffId,
- workspace_id: &WorkspaceId,
- project_id: &ProjectId,
- accepting_agent: AgentKind,
- accepting_session: Option<&SessionId>,
- accepting_user: Option<&str>,
- owner_filter: &OwnerFilter,
- receiving_cwd: Option<&str>,
-) -> StoreResult<bool> {
+pub fn accept_handoff(conn: &mut Connection, acceptance: &HandoffAcceptance) -> StoreResult<bool> {
let tx = conn.transaction()?;
- let claimed = accept_handoff_in_transaction(
- &tx,
+ let claimed = accept_handoff_in_transaction(&tx, acceptance)?;
+ tx.commit()?;
+ Ok(claimed)
+}
+
+pub(crate) fn accept_handoff_in_transaction(
+ tx: &Transaction<'_>,
+ acceptance: &HandoffAcceptance,
+) -> StoreResult<bool> {
+ let HandoffAcceptance {
handoff_id,
workspace_id,
project_id,
@@ -1551,22 +1549,8 @@ pub fn accept_handoff(
accepting_user,
owner_filter,
receiving_cwd,
- )?;
- tx.commit()?;
- Ok(claimed)
-}
-
-pub(crate) fn accept_handoff_in_transaction(
- tx: &Transaction<'_>,
- handoff_id: &HandoffId,
- workspace_id: &WorkspaceId,
- project_id: &ProjectId,
- accepting_agent: AgentKind,
- accepting_session: Option<&SessionId>,
- accepting_user: Option<&str>,
- owner_filter: &OwnerFilter,
- receiving_cwd: Option<&str>,
-) -> StoreResult<bool> {
+ } = acceptance;
+ let accepting_user = accepting_user.as_deref();
validate_identity_storage_key(accepting_user, "accepting handoff operator")?;
match (owner_filter, accepting_user) {
(OwnerFilter::User(expected), Some(actual)) if expected != actual => {
@@ -1588,7 +1572,7 @@ pub(crate) fn accept_handoff_in_transaction(
}
let now = Timestamp::now().as_microsecond();
let agent = accepting_agent.as_str();
- let session: Option<&[u8]> = accepting_session.map(|s| &s.as_bytes()[..]);
+ let session: Option<&[u8]> = accepting_session.as_ref().map(|s| &s.as_bytes()[..]);
let metadata = tx
.query_row(
"SELECT from_session_id IS NOT NULL, cwd, created_at, owner_user \
@@ -1678,7 +1662,7 @@ pub(crate) fn accept_handoff_in_transaction(
project_id.as_bytes(),
cwd.as_deref(),
created_at,
- receiving_cwd,
+ receiving_cwd.as_deref(),
owner_user.as_deref(),
)?;
if expired > 0 {
@@ -2556,6 +2540,23 @@ pub(crate) mod tests {
String::from_utf8(logs.0.lock().unwrap().clone()).unwrap()
}
+ fn handoff_acceptance(
+ handoff_id: HandoffId,
+ workspace_id: WorkspaceId,
+ project_id: ProjectId,
+ ) -> HandoffAcceptance {
+ HandoffAcceptance {
+ handoff_id,
+ workspace_id,
+ project_id,
+ accepting_agent: AgentKind::Codex,
+ accepting_session: None,
+ accepting_user: None,
+ owner_filter: OwnerFilter::Any,
+ receiving_cwd: None,
+ }
+ }
+
/// Open a fresh DB with migrations applied + a default workspace
/// and "scratch" project pre-created. Tuple-return keeps the
/// tempdir alive for the duration of the test.
@@ -3357,18 +3358,7 @@ pub(crate) mod tests {
assert_eq!(state, "open");
assert!(accepted_by.is_none());
- accept_handoff(
- &mut conn,
- &id,
- &ws,
- &proj,
- AgentKind::Codex,
- None,
- None,
- &OwnerFilter::Any,
- None,
- )
- .unwrap();
+ accept_handoff(&mut conn, &handoff_acceptance(id, ws, proj)).unwrap();
let (state, accepted_by): (String, Option<String>) = conn
.query_row(
"SELECT state, accepted_by FROM handoffs WHERE id = ?1",
@@ -3383,17 +3373,7 @@ pub(crate) mod tests {
// either succeed silently or fail clearly, never corrupt
// the row. (Current impl is a no-op UPDATE with a state
// guard.)
- let second = accept_handoff(
- &mut conn,
- &id,
- &ws,
- &proj,
- AgentKind::Codex,
- None,
- None,
- &OwnerFilter::Any,
- None,
- );
+ let second = accept_handoff(&mut conn, &handoff_acceptance(id, ws, proj));
assert!(second.is_ok(), "double-accept must not error");
}
@@ -3469,18 +3449,7 @@ pub(crate) mod tests {
owner_user: None,
};
let id = insert_handoff(&mut conn, &new()).unwrap();
- accept_handoff(
- &mut conn,
- &id,
- &ws,
- &proj,
- AgentKind::Codex,
- None,
- None,
- &OwnerFilter::Any,
- None,
- )
- .unwrap();
+ accept_handoff(&mut conn, &handoff_acceptance(id, ws, proj)).unwrap();
let id2 = insert_handoff(&mut conn, &new()).unwrap();
assert!(cancel_handoff(&mut conn, &id2, &ws, &proj, &OwnerFilter::Any).unwrap());
@@ -3496,18 +3465,7 @@ pub(crate) mod tests {
);
// Idempotent misses stay out of the trail: a double-accept and a
// cancel of an already-accepted handoff change no row, audit nothing.
- accept_handoff(
- &mut conn,
- &id,
- &ws,
- &proj,
- AgentKind::Codex,
- None,
- None,
- &OwnerFilter::Any,
- None,
- )
- .unwrap();
+ accept_handoff(&mut conn, &handoff_acceptance(id, ws, proj)).unwrap();
assert!(!cancel_handoff(&mut conn, &id, &ws, &proj, &OwnerFilter::Any).unwrap());
assert_eq!(
audit_row_for(&conn, "accept_handoff").0,
diff --git a/crates/ai-memory-store/src/reader.rs b/crates/ai-memory-store/src/reader.rs
index 91d1852a..68b1f7e9 100644
--- a/crates/ai-memory-store/src/reader.rs
+++ b/crates/ai-memory-store/src/reader.rs
@@ -6900,16 +6900,16 @@ mod tests {
.unwrap();
store
.writer
- .accept_handoff(
- selected.id,
- ws,
- proj,
- AgentKind::Codex,
- None,
- None,
- ai_memory_core::OwnerFilter::Any,
- Some("/repo/api/src".into()),
- )
+ .accept_handoff(ai_memory_core::HandoffAcceptance {
+ handoff_id: selected.id,
+ workspace_id: ws,
+ project_id: proj,
+ accepting_agent: AgentKind::Codex,
+ accepting_session: None,
+ accepting_user: None,
+ owner_filter: ai_memory_core::OwnerFilter::Any,
+ receiving_cwd: Some("/repo/api/src".into()),
+ })
.await
.unwrap();
diff --git a/crates/ai-memory-store/src/writer.rs b/crates/ai-memory-store/src/writer.rs
index dd11896e..b45361fb 100644
--- a/crates/ai-memory-store/src/writer.rs
+++ b/crates/ai-memory-store/src/writer.rs
@@ -11,9 +11,9 @@ use std::sync::{Arc, Mutex};
use std::thread::{self, JoinHandle};
use ai_memory_core::{
- AgentKind, HandoffId, ManagedRunId, NewHandoff, NewObservation, NewPage, NewSession, NewUser,
- ObservationId, OwnerFilter, PageId, PagePath, ProjectId, Sanitized, SessionId, UserId,
- WorkspaceId,
+ AgentKind, HandoffAcceptance, HandoffId, ManagedRunId, NewHandoff, NewObservation, NewPage,
+ NewSession, NewUser, ObservationId, OwnerFilter, PageId, PagePath, ProjectId, Sanitized,
+ SessionId, UserId, WorkspaceId,
};
use rusqlite::Connection;
use tokio::sync::{mpsc, oneshot};
@@ -163,14 +163,7 @@ pub(crate) enum WriteCmd {
reply: oneshot::Sender<StoreResult<HandoffId>>,
},
AcceptHandoff {
- handoff_id: HandoffId,
- workspace_id: WorkspaceId,
- project_id: ProjectId,
- accepting_agent: AgentKind,
- accepting_session: Option<SessionId>,
- accepting_user: Option<String>,
- owner_filter: OwnerFilter,
- receiving_cwd: Option<String>,
+ acceptance: HandoffAcceptance,
reply: oneshot::Sender<StoreResult<bool>>,
},
CancelHandoff {
@@ -371,15 +364,8 @@ pub(crate) enum WriteCmd {
reply: oneshot::Sender<StoreResult<bool>>,
},
AcceptStartupContext {
- handoff_id: Option<HandoffId>,
- workspace_id: WorkspaceId,
- project_id: ProjectId,
- accepting_agent: AgentKind,
- accepting_session: Option<SessionId>,
- accepting_user: Option<String>,
- owner_filter: OwnerFilter,
+ handoff: Option<HandoffAcceptance>,
managed_run_id: Option<ManagedRunId>,
- receiving_cwd: Option<String>,
reply: oneshot::Sender<StoreResult<StartupContextAcceptance>>,
},
FinishWorkstreamRun {
@@ -771,27 +757,10 @@ impl WriterHandle {
///
/// # Errors
/// Returns [`StoreError::WriterClosed`] or propagates SQL errors.
- pub async fn accept_handoff(
- &self,
- handoff_id: HandoffId,
- workspace_id: WorkspaceId,
- project_id: ProjectId,
- accepting_agent: AgentKind,
- accepting_session: Option<SessionId>,
- accepting_user: Option<String>,
- owner_filter: OwnerFilter,
- receiving_cwd: Option<String>,
- ) -> StoreResult<bool> {
+ pub async fn accept_handoff(&self, acceptance: HandoffAcceptance) -> StoreResult<bool> {
let (tx, rx) = oneshot::channel();
self.send(WriteCmd::AcceptHandoff {
- handoff_id,
- workspace_id,
- project_id,
- accepting_agent,
- accepting_session,
- accepting_user,
- owner_filter,
- receiving_cwd,
+ acceptance,
reply: tx,
})
.await?;
@@ -1476,30 +1445,15 @@ impl WriterHandle {
///
/// When a managed run was requested but is no longer claimable, the
/// handoff remains open and both result fields are false.
- #[allow(clippy::too_many_arguments)]
pub async fn accept_startup_context(
&self,
- handoff_id: Option<HandoffId>,
- workspace_id: WorkspaceId,
- project_id: ProjectId,
- accepting_agent: AgentKind,
- accepting_session: Option<SessionId>,
- accepting_user: Option<String>,
- owner_filter: OwnerFilter,
+ handoff: Option<HandoffAcceptance>,
managed_run_id: Option<ManagedRunId>,
- receiving_cwd: Option<String>,
) -> StoreResult<StartupContextAcceptance> {
let (tx, rx) = oneshot::channel();
self.send(WriteCmd::AcceptStartupContext {
- handoff_id,
- workspace_id,
- project_id,
- accepting_agent,
- accepting_session,
- accepting_user,
- owner_filter,
+ handoff,
managed_run_id,
- receiving_cwd,
reply: tx,
})
.await?;
@@ -1744,28 +1698,8 @@ fn worker_loop(mut conn: Connection, mut rx: mpsc::Receiver<WriteCmd>) {
let result = ops::insert_handoff(&mut conn, &handoff);
send_or_warn(reply, result, "insert_handoff");
}
- WriteCmd::AcceptHandoff {
- handoff_id,
- workspace_id,
- project_id,
- accepting_agent,
- accepting_session,
- accepting_user,
- owner_filter,
- receiving_cwd,
- reply,
- } => {
- let result = ops::accept_handoff(
- &mut conn,
- &handoff_id,
- &workspace_id,
- &project_id,
- accepting_agent,
- accepting_session.as_ref(),
- accepting_user.as_deref(),
- &owner_filter,
- receiving_cwd.as_deref(),
- );
+ WriteCmd::AcceptHandoff { acceptance, reply } => {
+ let result = ops::accept_handoff(&mut conn, &acceptance);
send_or_warn(reply, result, "accept_handoff");
}
WriteCmd::CancelHandoff {
@@ -2059,15 +1993,8 @@ fn worker_loop(mut conn: Connection, mut rx: mpsc::Receiver<WriteCmd>) {
send_or_warn(reply, result, "accept_managed_run_context");
}
WriteCmd::AcceptStartupContext {
- handoff_id,
- workspace_id,
- project_id,
- accepting_agent,
- accepting_session,
- accepting_user,
- owner_filter,
+ handoff,
managed_run_id,
- receiving_cwd,
reply,
} => {
let result = (|| {
@@ -2081,18 +2008,8 @@ fn worker_loop(mut conn: Connection, mut rx: mpsc::Receiver<WriteCmd>) {
if managed_run_id.is_some() && !managed_context_accepted {
return Ok(StartupContextAcceptance::default());
}
- let handoff_accepted = match handoff_id {
- Some(handoff_id) => ops::accept_handoff_in_transaction(
- &tx,
- &handoff_id,
- &workspace_id,
- &project_id,
- accepting_agent,
- accepting_session.as_ref(),
- accepting_user.as_deref(),
- &owner_filter,
- receiving_cwd.as_deref(),
- )?,
+ let handoff_accepted = match handoff {
+ Some(acceptance) => ops::accept_handoff_in_transaction(&tx, &acceptance)?,
None => false,
};
tx.commit()?;
diff --git a/crates/ai-memory-store/tests/handoff_ownership.rs b/crates/ai-memory-store/tests/handoff_ownership.rs
index 522d48a9..2345d8c5 100644
--- a/crates/ai-memory-store/tests/handoff_ownership.rs
+++ b/crates/ai-memory-store/tests/handoff_ownership.rs
@@ -14,8 +14,8 @@
//! string that could drift from it.
use ai_memory_core::{
- ActorContext, AgentKind, IdentityKey, NewHandoff, OwnerFilter, ProjectId, WorkspaceId,
- owner_stamp,
+ ActorContext, AgentKind, HandoffAcceptance, HandoffId, IdentityKey, NewHandoff, OwnerFilter,
+ ProjectId, WorkspaceId, owner_stamp,
};
use ai_memory_store::Store;
@@ -33,6 +33,26 @@ fn filter_for(name: &str) -> OwnerFilter {
})
}
+fn acceptance(
+ handoff_id: HandoffId,
+ workspace_id: WorkspaceId,
+ project_id: ProjectId,
+ accepting_user: Option<String>,
+ owner_filter: OwnerFilter,
+ receiving_cwd: Option<String>,
+) -> HandoffAcceptance {
+ HandoffAcceptance {
+ handoff_id,
+ workspace_id,
+ project_id,
+ accepting_agent: AgentKind::ClaudeCode,
+ accepting_session: None,
+ accepting_user,
+ owner_filter,
+ receiving_cwd,
+ }
+}
+
/// Build an open handoff, optionally owned by the named operator.
fn handoff(
workspace_id: WorkspaceId,
@@ -188,32 +208,28 @@ async fn ownership_writes_reject_malformed_identity_keys() {
assert!(
store
.writer
- .accept_handoff(
+ .accept_handoff(acceptance(
id,
ws,
proj,
- AgentKind::ClaudeCode,
- None,
Some("alice".into()),
filter_for("alice"),
None,
- )
+ ))
.await
.is_err()
);
assert!(
store
.writer
- .accept_handoff(
+ .accept_handoff(acceptance(
id,
ws,
proj,
- AgentKind::ClaudeCode,
- None,
Some(operator("bob")),
filter_for("alice"),
None,
- )
+ ))
.await
.is_err(),
"the accepting identity and owner filter must not disagree"
@@ -331,16 +347,14 @@ async fn another_operator_cannot_claim_the_handoff() {
let stolen = store
.writer
- .accept_handoff(
+ .accept_handoff(acceptance(
id,
ws,
proj,
- AgentKind::ClaudeCode,
- None,
Some(operator("bob")),
filter_for("bob"),
None,
- )
+ ))
.await
.unwrap();
assert!(!stolen, "Bob must not be able to claim Alice's handoff");
@@ -348,32 +362,28 @@ async fn another_operator_cannot_claim_the_handoff() {
// Still open for its owner, and now claimable by her exactly once.
let claimed = store
.writer
- .accept_handoff(
+ .accept_handoff(acceptance(
id,
ws,
proj,
- AgentKind::ClaudeCode,
- None,
Some(operator("alice")),
filter_for("alice"),
None,
- )
+ ))
.await
.unwrap();
assert!(claimed, "the owner claims her own handoff");
let twice = store
.writer
- .accept_handoff(
+ .accept_handoff(acceptance(
id,
ws,
proj,
- AgentKind::ClaudeCode,
- None,
Some(operator("alice")),
filter_for("alice"),
None,
- )
+ ))
.await
.unwrap();
assert!(!twice, "a handoff is single-use even for its owner");
@@ -482,16 +492,14 @@ async fn destructive_handoff_updates_recheck_scope_atomically() {
assert!(
!store
.writer
- .accept_handoff(
+ .accept_handoff(acceptance(
id,
ws,
other_proj,
- AgentKind::ClaudeCode,
- None,
Some(operator("alice")),
OwnerFilter::Any,
None,
- )
+ ))
.await
.unwrap(),
"even a root recovery claim must not cross its resolved project"
@@ -511,16 +519,14 @@ async fn destructive_handoff_updates_recheck_scope_atomically() {
assert!(
store
.writer
- .accept_handoff(
+ .accept_handoff(acceptance(
id,
ws,
proj,
- AgentKind::ClaudeCode,
- None,
Some(operator("alice")),
OwnerFilter::Any,
None,
- )
+ ))
.await
.unwrap(),
"the exact project can still claim the handoff"
@@ -609,16 +615,14 @@ async fn handoff_listing_is_owner_scoped_and_covers_every_state() {
// Consume Alice's, then find it again by state — the recovery path.
store
.writer
- .accept_handoff(
+ .accept_handoff(acceptance(
alice,
ws,
proj,
- AgentKind::ClaudeCode,
- None,
Some(operator("alice")),
filter_for("alice"),
None,
- )
+ ))
.await
.unwrap();
let open = summaries(filter_for("alice"), Some(HandoffState::Open)).await;
@@ -806,16 +810,14 @@ async fn automatic_supersession_does_not_reach_across_operators() {
// and ranks below hers.
let claimed = store
.writer
- .accept_handoff(
+ .accept_handoff(acceptance(
alice_newest,
ws,
proj,
- AgentKind::ClaudeCode,
- None,
Some(operator("alice")),
filter_for("alice"),
Some("/repo".into()),
- )
+ ))
.await
.unwrap();
assert!(claimed, "Alice claims her own handoff");