Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions apps/staged/src-tauri/src/branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,6 @@ pub async fn create_remote_branch(
#[tauri::command(rename_all = "camelCase")]
pub async fn start_workspace(
store: tauri::State<'_, Mutex<Option<Arc<Store>>>>,
app_handle: AppHandle,
branch_id: String,
) -> Result<(), String> {
let store = get_store(&store)?;
Expand All @@ -1535,12 +1534,6 @@ pub async fn start_workspace(
.map_err(|e| e.to_string())?
.ok_or_else(|| format!("Branch not found: {branch_id}"))?;

// Track whether this is the first workspace start (Starting → Running)
// vs a restart (Stopped → Running). We only trigger auto-review on the
// first start so that existing branches don't get a spurious review
// every time the workspace restarts.
let is_first_start = branch.workspace_status == Some(store::WorkspaceStatus::Starting);

let project = store
.get_project(&branch.project_id)
.map_err(|e| e.to_string())?
Expand Down Expand Up @@ -1595,23 +1588,6 @@ pub async fn start_workspace(
.update_branch_workspace_status(&branch_id, &store::WorkspaceStatus::Running)
.map_err(|e| e.to_string())?;

// Trigger auto-review for the newly cloned secondary repo
// if this is the first start for this branch.
if is_first_start {
let store_bg = Arc::clone(&store);
let app_handle_bg = app_handle.clone();
let branch_id_bg = branch_id.clone();
tauri::async_runtime::spawn(async move {
crate::maybe_trigger_auto_review_for_new_repo(
&store_bg,
&app_handle_bg,
&branch_id_bg,
None,
)
.await;
});
}

return Ok(());
}
}
Expand Down Expand Up @@ -1696,24 +1672,6 @@ pub async fn start_workspace(
);
}

// If this is the first workspace start for a new branch, check
// whether the branch already has commits (e.g. from an existing
// PR) and kick off an automatic code review.
if is_first_start {
let store_bg = Arc::clone(&store);
let app_handle_bg = app_handle.clone();
let branch_id_bg = branch_id.clone();
tauri::async_runtime::spawn(async move {
crate::maybe_trigger_auto_review_for_new_repo(
&store_bg,
&app_handle_bg,
&branch_id_bg,
None,
)
.await;
});
}

Ok(())
}
Err(blox::BloxError::NotAuthenticated) => {
Expand Down
111 changes: 4 additions & 107 deletions apps/staged/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ pub struct ReviewTimelineItem {
pub completion_reason: Option<String>,
pub title: Option<String>,
pub comment_count: usize,
pub is_auto: bool,
pub created_at: i64,
pub updated_at: i64,
pub completed_at: Option<i64>,
Expand Down Expand Up @@ -310,70 +309,6 @@ fn confirm_reset_store(
// Project commands
// =============================================================================

/// Check whether a newly added repo already has commits on its branch and, if
/// so, kick off an automatic code review.
///
/// For **local** branches (`worktree_path: Some`) the check is done by
/// inspecting the worktree on disk before triggering.
/// For **remote** branches (`worktree_path: None`) the review is triggered
/// unconditionally — the caller is responsible for ensuring the workspace is
/// running before calling this (e.g. after `start_workspace` or
/// `setup_remote_repo_clone` completes).
///
/// This is fire-and-forget — errors are logged but never propagated.
pub(crate) async fn maybe_trigger_auto_review_for_new_repo(
store: &Arc<Store>,
app_handle: &tauri::AppHandle,
branch_id: &str,
worktree_path: Option<&str>,
) {
// For local branches, check whether there are any commits on the branch
// relative to its base before spinning up a review session.
if let Some(path) = worktree_path {
let branch = match store.get_branch(branch_id) {
Ok(Some(b)) => b,
_ => return,
};
let worktree = std::path::PathBuf::from(path);
let base_ref = git::origin_ref_for_branch(&branch.base_branch);
match git::get_commits_since_base(&worktree, &base_ref) {
Ok(commits) if commits.is_empty() => {
log::info!(
"[auto_review] branch {branch_id} has no commits yet — skipping auto review"
);
return;
}
Err(e) => {
log::warn!("[auto_review] failed to check commits for branch {branch_id}: {e}");
return;
}
Ok(_) => { /* has commits — fall through to trigger */ }
}
}

let registry = app_handle.state::<Arc<session_runner::SessionRegistry>>();
match session_commands::trigger_auto_review(
Arc::clone(store),
Arc::clone(&registry),
app_handle.clone(),
branch_id.to_string(),
None,
)
.await
{
Ok(resp) => {
log::info!(
"[auto_review] triggered for new repo on branch {branch_id}: session={}, review={}",
resp.session_id,
resp.artifact_id,
);
}
Err(e) => {
log::warn!("[auto_review] failed to trigger for branch {branch_id}: {e}");
}
}
}

#[tauri::command]
fn list_projects(
store: tauri::State<'_, Mutex<Option<Arc<Store>>>>,
Expand Down Expand Up @@ -517,15 +452,14 @@ fn create_project(
})
.await;

let worktree_path = match worktree_result {
match worktree_result {
Ok(Ok(path)) => {
log::info!("[create_project] worktree ready at {path}");
web_server::emit_to_all(
&app_handle,
"project-setup-progress",
project_id.clone(),
);
path
}
Ok(Err(e)) => {
log::warn!("[create_project] worktree setup failed: {e}");
Expand All @@ -535,7 +469,7 @@ fn create_project(
log::warn!("[create_project] worktree task panicked: {e}");
return;
}
};
}

let executor = app_handle.state::<Arc<actions::ActionExecutor>>();
let act_registry = app_handle.state::<Arc<actions::ActionRegistry>>();
Expand All @@ -553,21 +487,7 @@ fn create_project(
{
web_server::emit_to_all(&app_handle, "project-setup-progress", project_id);
}

// If the repo already has commits on this branch, kick off
// an automatic code review so the user gets immediate feedback.
maybe_trigger_auto_review_for_new_repo(
&store_bg,
&app_handle,
&branch_id,
Some(&worktree_path),
)
.await;
});
} else {
// Remote branches: auto-review is deferred until `start_workspace`
// completes — the workspace isn't running yet at this point, so
// attempting to trigger a review here would fail.
}
} else if project.location == store::ProjectLocation::Remote {
log::info!(
Expand Down Expand Up @@ -681,15 +601,14 @@ async fn add_project_repo(
})
.await;

let worktree_path = match worktree_result {
match worktree_result {
Ok(Ok(path)) => {
log::info!("[add_project_repo] worktree ready at {path}");
web_server::emit_to_all(
&app_handle,
"project-setup-progress",
project_id.clone(),
);
path
}
Ok(Err(e)) => {
log::warn!("[add_project_repo] worktree setup failed: {e}");
Expand All @@ -699,7 +618,7 @@ async fn add_project_repo(
log::warn!("[add_project_repo] worktree task panicked: {e}");
return;
}
};
}

let executor = app_handle.state::<Arc<actions::ActionExecutor>>();
let act_registry = app_handle.state::<Arc<actions::ActionRegistry>>();
Expand All @@ -720,16 +639,6 @@ async fn add_project_repo(
project_id.clone(),
);
}

// If the repo already has commits on this branch, kick off
// an automatic code review so the user gets immediate feedback.
maybe_trigger_auto_review_for_new_repo(
&store,
&app_handle,
&branch.id,
Some(&worktree_path),
)
.await;
} else {
// Remote branch: clone the repo into the running workspace,
// fetch the base branch, and create the feature branch.
Expand All @@ -750,16 +659,6 @@ async fn add_project_repo(
}
}
web_server::emit_to_all(&app_handle, "project-setup-progress", project_id);

// If the repo already has commits on this branch, kick off
// an automatic code review so the user gets immediate feedback.
maybe_trigger_auto_review_for_new_repo(
&store,
&app_handle,
&branch.id,
None, // remote — trigger_auto_review resolves HEAD via workspace
)
.await;
}
}
});
Expand Down Expand Up @@ -2337,8 +2236,6 @@ pub fn run() {
session_commands::queue_branch_session,
session_commands::drain_queued_sessions,
session_commands::start_project_session,
session_commands::find_fresh_auto_review,
session_commands::set_review_auto,
// Actions
actions::commands::detect_repo_actions,
actions::commands::run_branch_action,
Expand Down
38 changes: 4 additions & 34 deletions apps/staged/src-tauri/src/project_mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,22 +628,6 @@ impl ProjectToolsHandler {
self.provider.clone()
};

// An in-flight auto review of the same branch would duplicate a requested
// review, and is invalidated by a commit (which triggers a fresh auto review
// once it lands), so cancel it first — same as user-initiated sessions.
if matches!(
p.expected_outcome,
RepoSessionOutcome::CodeReview | RepoSessionOutcome::Commit
) {
if let Err(e) = crate::session_commands::cancel_in_flight_auto_review_for_branch(
&self.store,
&self.registry,
&target.branch.id,
) {
return format!("Error cancelling in-flight auto review: {e}");
}
}

let mut session = crate::store::Session::new_queued(&p.instructions);
if let Some(ref provider) = session_provider {
session = session.with_provider(provider);
Expand Down Expand Up @@ -852,7 +836,6 @@ impl ProjectToolsHandler {
branch_id: Some(branch_id.clone()),
project_id: Some(self.project_id.clone()),
session_type: None,
is_auto_review: false,
},
);
let _ = crate::session_commands::drain_queued_sessions_for_branch(
Expand Down Expand Up @@ -1035,7 +1018,7 @@ impl ProjectToolsHandler {
})
.await;

let worktree_path = match worktree_result {
match worktree_result {
Ok(Ok(path)) => {
log::debug!("[project_mcp] add_project_repo: worktree ready at {}", path);
// Notify UI that the worktree is ready so branch state updates
Expand All @@ -1044,7 +1027,6 @@ impl ProjectToolsHandler {
"project-setup-progress",
self.project_id.clone(),
);
path
}
Ok(Err(e)) => {
log::warn!(
Expand All @@ -1063,15 +1045,13 @@ impl ProjectToolsHandler {
"Added repository {github_repo} to project (worktree task error: {e})"
);
}
};
}

// Prerun waits out any in-flight action detection and then runs
// each setup action to completion — minutes, against an MCP
// client's request timeout. Nothing in the reply derives from it,
// so the whole tail is detached, in one task so the auto-review
// still follows the setup actions. Structurally this is now the
// Tauri `add_project_repo` command's spawned setup task. Note that
// the reply therefore also lands before the auto-review is queued.
// so the whole tail is detached. Structurally this is now the
// Tauri `add_project_repo` command's spawned setup task.
let store = Arc::clone(&self.store);
let app_handle = self.app_handle.clone();
let project_id = self.project_id.clone();
Expand Down Expand Up @@ -1105,16 +1085,6 @@ impl ProjectToolsHandler {
"[project_mcp] add_project_repo: no action executor available, skipping prerun actions"
);
}

// If the repo already has commits on this branch, kick off
// an automatic code review so the user gets immediate feedback.
crate::maybe_trigger_auto_review_for_new_repo(
&store,
&app_handle,
&branch_id,
Some(&worktree_path),
)
.await;
});

// The reply is the agent's whole account of what just happened, so
Expand Down
Loading