fix(runtime): isolate agent state by project (#101)

This commit is contained in:
2026-07-25 22:14:02 +02:00
parent 6a87c4635f
commit 6e98fd89f7
52 changed files with 1894 additions and 805 deletions

View File

@ -25,7 +25,8 @@ use domain::{
BackgroundTaskResult, BackgroundTaskState, BackgroundTaskWakePolicy, ConversationId,
ConversationLog, ConversationTurn, Handoff, HandoffStore, InputMediator, InputSource,
ManifestEntry, MarkdownDoc, NodeId, ProfileId, Project, ProjectId, ProjectPath, PtySize,
RemoteRef, SessionId, SessionKind, TaskId, TerminalSession, TicketId, TurnId, TurnRole,
RemoteRef, RuntimeAgentKey, SessionId, SessionKind, TaskId, TerminalSession, TicketId, TurnId,
TurnRole,
};
use uuid::Uuid;
@ -129,21 +130,21 @@ impl FakeInput {
}
impl InputMediator for FakeInput {
fn enqueue(&self, _agent: AgentId, _ticket: Ticket) -> PendingReply {
fn enqueue(&self, _agent: RuntimeAgentKey, _ticket: Ticket) -> PendingReply {
let fut: Pin<Box<dyn Future<Output = Result<TurnResolution, MailboxError>> + Send>> =
Box::pin(async { Err(MailboxError::Cancelled) });
PendingReply::new(fut)
}
fn preempt(&self, _agent: AgentId) {}
fn preempt(&self, _agent: RuntimeAgentKey) {}
fn mark_idle(&self, _agent: AgentId) {}
fn mark_idle(&self, _agent: RuntimeAgentKey) {}
fn busy_state(&self, agent: AgentId) -> AgentBusyState {
fn busy_state(&self, agent: RuntimeAgentKey) -> AgentBusyState {
self.busy
.lock()
.unwrap()
.get(&agent)
.get(&agent.agent_id)
.copied()
.unwrap_or(AgentBusyState::Idle)
}
@ -261,11 +262,11 @@ impl FakeQueue {
}
impl AgentQueueSnapshot for FakeQueue {
fn queue_for(&self, agent: AgentId) -> Vec<QueuedTicketSnapshot> {
fn queue_for(&self, agent: RuntimeAgentKey) -> Vec<QueuedTicketSnapshot> {
self.queues
.lock()
.unwrap()
.get(&agent)
.get(&agent.agent_id)
.cloned()
.unwrap_or_default()
}
@ -446,7 +447,8 @@ fn insert_pty(
agent_id: AgentId,
node_id: NodeId,
) {
sessions.insert(
sessions.insert_in_project(
project().id,
PtyHandle { session_id },
TerminalSession::starting(
session_id,
@ -685,7 +687,8 @@ async fn workstate_attaches_live_pty_session_to_manifest_agent() {
async fn workstate_attaches_live_structured_session_to_manifest_agent() {
let a = agent(10, "alpha");
let f = fixture(std::slice::from_ref(&a));
f.structured.insert(fake_session(sid(2)), a.id, nid(200));
f.structured
.insert_in_project(f.project.id, fake_session(sid(2)), a.id, nid(200));
let out = f
.usecase