feat: auto-trigger code review when adding repos with existing commits#404
feat: auto-trigger code review when adding repos with existing commits#404
Conversation
When creating a new project with a repo or adding a repo to an existing project, automatically kick off an auto code review if the branch already has commits (e.g. from an existing PR). Adds a shared helper `maybe_trigger_auto_review_for_new_repo` that: - For local branches, checks for commits since base via the worktree and only triggers a review if commits exist - For remote branches, optimistically triggers the review and lets `trigger_auto_review` resolve the HEAD via the workspace The helper is called from three code paths: - `create_project` (lib.rs) — after worktree + prerun actions setup - `add_project_repo` Tauri command (lib.rs) — after worktree/remote clone setup, for both local and remote branches - `add_project_repo` MCP tool (project_mcp.rs) — after worktree + prerun actions setup
Previously the create_project path set branch_id to None for remote projects, which meant the if-let block containing the auto-review trigger was never entered. Remote projects created with existing commits (e.g. from a PR) would not receive an automatic code review. Restructure the match to always return the branch ID alongside a boolean indicating local vs remote. Local branches follow the existing worktree + prerun-actions + auto-review path. Remote branches now spawn a task that optimistically triggers auto-review via the workspace, matching the behavior already present in the add_project_repo command.
When creating a remote project from an existing PR, the workspace was
checking out the local branch from origin/{base_ref} (e.g. origin/main)
instead of origin/{branch_name}. This meant the local branch had zero
commits ahead of the base, so the branch card showed no commits.
Fix both code paths that set up the branch in a remote workspace:
- clone_repo_into_workspace: After fetching the base branch, also
attempt to fetch the feature branch from origin. If it exists,
create the local branch from origin/{branch_name} instead of
origin/{base_ref}.
- start_workspace: After ws_start completes (which clones at the
base ref), fetch the feature branch from origin. If it exists,
use 'checkout -B' to create the local branch from the remote
tracking ref, picking up all existing PR commits.
The auto-review for remote branches in create_project was firing immediately after creating the branch record, before the frontend called start_workspace. The workspace wasn't running yet, so the `sq blox acp` process would exit immediately with: ACP init failed: server shut down unexpectedly Move the remote auto-review trigger from create_project into start_workspace, which is where the workspace actually becomes ready and the branch is checked out. The trigger fires on both success paths (primary ws_start and secondary repo clone into an already-running workspace). To avoid spurious reviews on workspace restarts, the trigger only fires on the first start (Starting → Running), not on restarts (Stopped → Running). Also update the doc comment on maybe_trigger_auto_review_for_new_repo to clarify that callers are responsible for ensuring the workspace is running before calling it for remote branches.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 794115cf95
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| let registry = app_handle.state::<Arc<session_runner::SessionRegistry>>(); | ||
| match session_commands::trigger_auto_review( | ||
| Arc::clone(store), | ||
| Arc::clone(®istry), | ||
| app_handle.clone(), |
There was a problem hiding this comment.
Gate remote auto-review on branch commits
When worktree_path is None (the remote-branch path), this helper skips any commit check and always calls trigger_auto_review, so a brand-new remote branch created from base with zero branch commits still starts an automatic review session. All new remote callsites in this commit pass None, so adding/starting remote repos without existing commits now triggers unnecessary reviews and token spend instead of only reviewing pre-existing branch work.
Useful? React with 👍 / 👎.
When a repository with existing commits on its branch is added to a project (or a workspace starts for the first time), automatically trigger a code review so the user gets immediate feedback.
Changes:
lib.rs: Addmaybe_trigger_auto_review_for_new_repo()helper that checks whether a branch has commits relative to its base and triggers an auto-review session. Called fromcreate_projectandadd_project_repofor both local and remote branches.branches.rs: Instart_workspace, track whether this is the first start (Starting → Running) vs a restart, and trigger auto-review only on first start. Also fetch the remote branch when it already exists (e.g. from an existing PR) so we pick up its commits instead of starting fresh from the base ref.project_mcp.rs: Call auto-review after worktree setup in the MCPadd_project_repotool handler.For local branches, the review is gated on actually having commits. For remote branches, the review is deferred until the workspace is running.