diff options
| author | soryu <soryu@soryu.co> | 2026-01-27 01:14:17 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-27 01:18:55 +0000 |
| commit | d2ae4ce4f5808f823a77c79afb37ca089a04431c (patch) | |
| tree | ba27ab3a84d2504427e92aa2486e464090100f62 /makima/src/server/handlers/mesh_supervisor.rs | |
| parent | ee21c74987c61715660ff877b547b430426a27fd (diff) | |
| download | soryu-makima/fix-supervisor-merge.tar.gz soryu-makima/fix-supervisor-merge.zip | |
Fix supervisor merge for completed tasks and make PR command synchronousmakima/fix-supervisor-merge
## Issue 1: makima supervisor merge doesn't work for completed tasks
When a task completes, the daemon removes it from in-memory task tracking.
This caused merge operations to fail with "Task not found".
Fixed by updating handle_merge_task_to_target() to use get_task_worktree_path()
which scans the worktrees directory as a fallback when the task is not in memory.
Also updated handle_create_pr() with the same pattern for consistency.
## Issue 2: makima supervisor pr returns immediately without result
The create_pr handler was asynchronous - it sent the CreatePR command to the
daemon and immediately returned without waiting for the result.
Fixed by:
1. Adding PrResultNotification struct and pr_results broadcast channel to AppState
2. Updating mesh_daemon.rs to broadcast PRCreated results to the channel
3. Updating create_pr() handler to subscribe to pr_results and wait for the
result with a 60-second timeout (matching the merge command pattern)
Now the PR command returns the actual pr_url and pr_number from the daemon.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'makima/src/server/handlers/mesh_supervisor.rs')
| -rw-r--r-- | makima/src/server/handlers/mesh_supervisor.rs | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/makima/src/server/handlers/mesh_supervisor.rs b/makima/src/server/handlers/mesh_supervisor.rs index 6d9f8fb..24ba4bb 100644 --- a/makima/src/server/handlers/mesh_supervisor.rs +++ b/makima/src/server/handlers/mesh_supervisor.rs @@ -1538,6 +1538,9 @@ pub async fn create_pr( ).into_response(); }; + // Subscribe to PR results BEFORE sending the command + let mut rx = state.pr_results.subscribe(); + // Send CreatePR command to daemon let cmd = DaemonCommand::CreatePR { task_id: request.task_id, @@ -1554,16 +1557,57 @@ pub async fn create_pr( ).into_response(); } - ( - StatusCode::CREATED, - Json(CreatePRResponse { - task_id: request.task_id, - success: true, - message: "PR creation command sent".to_string(), - pr_url: None, - pr_number: None, - }), - ).into_response() + // Wait for the PR result with a timeout (60 seconds should be plenty for PR creation) + let timeout = tokio::time::Duration::from_secs(60); + let result = tokio::time::timeout(timeout, async { + loop { + match rx.recv().await { + Ok(notification) => { + if notification.task_id == request.task_id { + return Some(notification); + } + // Not our task, keep waiting + } + Err(_) => { + // Channel closed or lagged + return None; + } + } + } + }).await; + + match result { + Ok(Some(notification)) => { + let status = if notification.success { + StatusCode::CREATED + } else { + StatusCode::INTERNAL_SERVER_ERROR + }; + ( + status, + Json(CreatePRResponse { + task_id: request.task_id, + success: notification.success, + message: notification.message, + pr_url: notification.pr_url, + pr_number: notification.pr_number, + }), + ).into_response() + } + Ok(None) | Err(_) => { + // Timeout or channel error - return error status + ( + StatusCode::GATEWAY_TIMEOUT, + Json(CreatePRResponse { + task_id: request.task_id, + success: false, + message: "PR creation timed out waiting for daemon response".to_string(), + pr_url: None, + pr_number: None, + }), + ).into_response() + } + } } /// Get the diff for a task's changes. |
