fix(runtime): isolate agent state by project (#101)
This commit is contained in:
@ -1458,6 +1458,7 @@ async fn execute_launch_agent_for_ws(
|
||||
request: LaunchAgentRequestDto,
|
||||
) -> Result<application::LaunchAgentOutput, ErrorDto> {
|
||||
let project = resolve_project_readonly(&request.project_id, &state.app).await?;
|
||||
let project_id = project.id;
|
||||
let agent_id = parse_agent_id(&request.agent_id)?;
|
||||
let node_id = request.node_id.as_deref().map(parse_node_id).transpose()?;
|
||||
let mcp_runtime = backend::mcp_endpoint::idea_exe_path().map(|exe| McpRuntime {
|
||||
@ -1492,7 +1493,7 @@ async fn execute_launch_agent_for_ws(
|
||||
|
||||
if let Ok(mut contexts) = state.app.resume_contexts.lock() {
|
||||
contexts.insert(
|
||||
agent_id,
|
||||
domain::RuntimeAgentKey::new(project_id, agent_id),
|
||||
backend::ResumeContext {
|
||||
project: resume_project,
|
||||
rows: request.rows,
|
||||
@ -1503,6 +1504,7 @@ async fn execute_launch_agent_for_ws(
|
||||
|
||||
if let Some(profile) = output.profile.as_ref() {
|
||||
state.app.arm_turn_watch(
|
||||
project_id,
|
||||
&watch_root,
|
||||
agent_id,
|
||||
profile,
|
||||
@ -6067,8 +6069,13 @@ mod tests {
|
||||
scrollback
|
||||
);
|
||||
let aid = parse_agent_id(&agent_id).unwrap();
|
||||
let pid = parse_project_id(&project_id).unwrap();
|
||||
assert_eq!(
|
||||
state.app.terminal_sessions.sessions_for_agent(&aid).len(),
|
||||
state
|
||||
.app
|
||||
.terminal_sessions
|
||||
.sessions_for_agent_in_project(pid, &aid)
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
|
||||
@ -6122,8 +6129,13 @@ mod tests {
|
||||
assert_eq!(second.kind, "terminal.attached");
|
||||
assert_eq!(attached_session_id(&second), first_session);
|
||||
let aid = parse_agent_id(&agent_id).unwrap();
|
||||
let pid = parse_project_id(&project_id).unwrap();
|
||||
assert_eq!(
|
||||
state.app.terminal_sessions.sessions_for_agent(&aid).len(),
|
||||
state
|
||||
.app
|
||||
.terminal_sessions
|
||||
.sessions_for_agent_in_project(pid, &aid)
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
|
||||
@ -6174,8 +6186,13 @@ mod tests {
|
||||
assert_eq!(error.reply_to.as_deref(), Some("agent-launch-other-cell"));
|
||||
assert_eq!(error.payload["code"], "AGENT_ALREADY_RUNNING");
|
||||
let aid = parse_agent_id(&agent_id).unwrap();
|
||||
let pid = parse_project_id(&project_id).unwrap();
|
||||
assert_eq!(
|
||||
state.app.terminal_sessions.sessions_for_agent(&aid).len(),
|
||||
state
|
||||
.app
|
||||
.terminal_sessions
|
||||
.sessions_for_agent_in_project(pid, &aid)
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user