From f6a40e2304585f140ed5766b25fe71a6958f4425 Mon Sep 17 00:00:00 2001 From: soryu Date: Thu, 29 Jan 2026 01:14:17 +0000 Subject: Fix makima supervisor pr CLI command --- makima/src/server/handlers/mesh_supervisor.rs | 41 +++++++++++++-------------- makima/src/server/state.rs | 4 ++- 2 files changed, 23 insertions(+), 22 deletions(-) (limited to 'makima/src/server') diff --git a/makima/src/server/handlers/mesh_supervisor.rs b/makima/src/server/handlers/mesh_supervisor.rs index 016367f..a0a3a96 100644 --- a/makima/src/server/handlers/mesh_supervisor.rs +++ b/makima/src/server/handlers/mesh_supervisor.rs @@ -1267,15 +1267,9 @@ pub struct MergeTaskResponse { #[derive(Debug, Deserialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct CreatePRRequest { - pub task_id: Uuid, + pub branch: String, pub title: String, pub body: Option, - #[serde(default = "default_base_branch")] - pub base_branch: String, -} - -fn default_base_branch() -> String { - "main".to_string() } /// Response for PR creation. @@ -1513,48 +1507,53 @@ pub async fn create_pr( headers: HeaderMap, Json(request): Json, ) -> impl IntoResponse { - let (_supervisor_id, owner_id) = match verify_supervisor_auth(&state, &headers, None).await { + let (supervisor_id, _owner_id) = match verify_supervisor_auth(&state, &headers, None).await { Ok(ids) => ids, Err(e) => return e.into_response(), }; let pool = state.db_pool.as_ref().unwrap(); - // Get the target task - let task = match repository::get_task_for_owner(pool, request.task_id, owner_id).await { + // Get the supervisor's own task to find daemon and base_branch + let task = match repository::get_task(pool, supervisor_id).await { Ok(Some(t)) => t, Ok(None) => { return ( StatusCode::NOT_FOUND, - Json(ApiError::new("NOT_FOUND", "Task not found")), + Json(ApiError::new("NOT_FOUND", "Supervisor task not found")), ).into_response(); } Err(e) => { - tracing::error!(error = %e, "Failed to get task"); + tracing::error!(error = %e, "Failed to get supervisor task"); return ( StatusCode::INTERNAL_SERVER_ERROR, - Json(ApiError::new("DB_ERROR", "Failed to get task")), + Json(ApiError::new("DB_ERROR", "Failed to get supervisor task")), ).into_response(); } }; - // Get daemon running the task + // Get daemon running the supervisor let Some(daemon_id) = task.daemon_id else { return ( StatusCode::SERVICE_UNAVAILABLE, - Json(ApiError::new("NO_DAEMON", "Task has no assigned daemon")), + Json(ApiError::new("NO_DAEMON", "Supervisor has no assigned daemon")), ).into_response(); }; + // Use base_branch from the task's repository config, falling back to "main" + let base_branch = task.base_branch.unwrap_or_else(|| "main".to_string()); + // Subscribe to PR results BEFORE sending the command let mut rx = state.pr_results.subscribe(); - // Send CreatePR command to daemon + // Send CreatePR command to daemon using the supervisor's task ID + // (the branch is in the supervisor's worktree) let cmd = DaemonCommand::CreatePR { - task_id: request.task_id, + task_id: supervisor_id, title: request.title.clone(), body: request.body.clone(), - base_branch: request.base_branch.clone(), + base_branch, + branch: request.branch.clone(), }; if let Err(e) = state.send_daemon_command(daemon_id, cmd).await { @@ -1571,7 +1570,7 @@ pub async fn create_pr( loop { match rx.recv().await { Ok(notification) => { - if notification.task_id == request.task_id { + if notification.task_id == supervisor_id { return Some(notification); } // Not our task, keep waiting @@ -1594,7 +1593,7 @@ pub async fn create_pr( ( status, Json(CreatePRResponse { - task_id: request.task_id, + task_id: supervisor_id, success: notification.success, message: notification.message, pr_url: notification.pr_url, @@ -1607,7 +1606,7 @@ pub async fn create_pr( ( StatusCode::GATEWAY_TIMEOUT, Json(CreatePRResponse { - task_id: request.task_id, + task_id: supervisor_id, success: false, message: "PR creation timed out waiting for daemon response".to_string(), pr_url: None, diff --git a/makima/src/server/state.rs b/makima/src/server/state.rs index bf8f6f2..041b101 100644 --- a/makima/src/server/state.rs +++ b/makima/src/server/state.rs @@ -461,9 +461,11 @@ pub enum DaemonCommand { task_id: Uuid, title: String, body: Option, - /// Base branch for the PR (default: main) + /// Base branch for the PR #[serde(rename = "baseBranch")] base_branch: String, + /// Source branch name to push and create PR from + branch: String, }, /// Get the diff for a task's changes -- cgit v1.2.3