summaryrefslogtreecommitdiff
path: root/makima/src/server/handlers/mesh_supervisor.rs
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-01-26 21:24:04 +0000
committersoryu <soryu@soryu.co>2026-01-26 21:24:04 +0000
commitbc1ce8013bc36a1585be05b928f2386ab56529c2 (patch)
tree8a6f2f5641103a029138047d675d0008986d60b7 /makima/src/server/handlers/mesh_supervisor.rs
parent04e1e8f0dd85d19917ac5ba0b73cba65ebac8976 (diff)
downloadsoryu-bc1ce8013bc36a1585be05b928f2386ab56529c2.tar.gz
soryu-bc1ce8013bc36a1585be05b928f2386ab56529c2.zip
Make merges synchronous
Diffstat (limited to 'makima/src/server/handlers/mesh_supervisor.rs')
-rw-r--r--makima/src/server/handlers/mesh_supervisor.rs59
1 files changed, 49 insertions, 10 deletions
diff --git a/makima/src/server/handlers/mesh_supervisor.rs b/makima/src/server/handlers/mesh_supervisor.rs
index 1b476ef..d1a1a99 100644
--- a/makima/src/server/handlers/mesh_supervisor.rs
+++ b/makima/src/server/handlers/mesh_supervisor.rs
@@ -1349,6 +1349,9 @@ pub async fn merge_task(
).into_response();
};
+ // Subscribe to merge results BEFORE sending the command
+ let mut rx = state.merge_results.subscribe();
+
// Send MergeTaskToTarget command to daemon
let cmd = DaemonCommand::MergeTaskToTarget {
task_id,
@@ -1364,16 +1367,52 @@ pub async fn merge_task(
).into_response();
}
- (
- StatusCode::OK,
- Json(MergeTaskResponse {
- task_id,
- success: true,
- message: "Merge command sent".to_string(),
- commit_sha: None,
- conflicts: None,
- }),
- ).into_response()
+ // Wait for the merge result with a timeout (60 seconds should be plenty for a merge)
+ 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 == task_id {
+ return Some(notification);
+ }
+ // Not our task, keep waiting
+ }
+ Err(_) => {
+ // Channel closed or lagged
+ return None;
+ }
+ }
+ }
+ }).await;
+
+ match result {
+ Ok(Some(notification)) => {
+ (
+ StatusCode::OK,
+ Json(MergeTaskResponse {
+ task_id,
+ success: notification.success,
+ message: notification.message,
+ commit_sha: notification.commit_sha,
+ conflicts: notification.conflicts,
+ }),
+ ).into_response()
+ }
+ Ok(None) | Err(_) => {
+ // Timeout or channel error - return error status
+ (
+ StatusCode::GATEWAY_TIMEOUT,
+ Json(MergeTaskResponse {
+ task_id,
+ success: false,
+ message: "Merge operation timed out waiting for daemon response".to_string(),
+ commit_sha: None,
+ conflicts: None,
+ }),
+ ).into_response()
+ }
+ }
}
/// Create a pull request for a task's changes.