summaryrefslogtreecommitdiff
path: root/makima/src/server/handlers/mesh_supervisor.rs
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-01-22 00:59:18 +0000
committersoryu <soryu@soryu.co>2026-01-22 00:59:18 +0000
commitb84b3f782d3a3d6bf7ed8040fd72907ca19db8c6 (patch)
tree47307136f44dbd69f38675d2c1a0da08d9628114 /makima/src/server/handlers/mesh_supervisor.rs
parent0a30c9d3a9227660860abcd48ea1e9bd5cc2350c (diff)
downloadsoryu-b84b3f782d3a3d6bf7ed8040fd72907ca19db8c6.tar.gz
soryu-b84b3f782d3a3d6bf7ed8040fd72907ca19db8c6.zip
Add pausing tasks
Diffstat (limited to 'makima/src/server/handlers/mesh_supervisor.rs')
-rw-r--r--makima/src/server/handlers/mesh_supervisor.rs69
1 files changed, 65 insertions, 4 deletions
diff --git a/makima/src/server/handlers/mesh_supervisor.rs b/makima/src/server/handlers/mesh_supervisor.rs
index 668ea7b..0bb58ed 100644
--- a/makima/src/server/handlers/mesh_supervisor.rs
+++ b/makima/src/server/handlers/mesh_supervisor.rs
@@ -1589,9 +1589,40 @@ pub async fn ask_question(
).await;
}
- // If non_blocking mode or phaseguard is enabled, return immediately with the question_id
- // Phaseguard questions persist until answered (no timeout) and are displayed by the frontend
- if request.non_blocking || request.phaseguard {
+ // If non_blocking mode, return immediately
+ if request.non_blocking {
+ return (
+ StatusCode::OK,
+ Json(AskQuestionResponse {
+ question_id,
+ response: None,
+ timed_out: false,
+ }),
+ ).into_response();
+ }
+
+ // If phaseguard is enabled, pause the supervisor task and return
+ // The task will be auto-resumed when a message is sent to it (e.g., when user answers)
+ if request.phaseguard {
+ // Pause the supervisor task
+ if let Some(daemon_id) = supervisor.daemon_id {
+ let cmd = DaemonCommand::PauseTask { task_id: supervisor_id };
+ if let Err(e) = state.send_daemon_command(daemon_id, cmd).await {
+ tracing::warn!(supervisor_id = %supervisor_id, error = %e, "Failed to pause supervisor for phaseguard");
+ } else {
+ tracing::info!(supervisor_id = %supervisor_id, "Paused supervisor for phaseguard question");
+ }
+ }
+
+ // Update task status to paused in DB
+ let update = crate::db::models::UpdateTaskRequest {
+ status: Some("paused".to_string()),
+ ..Default::default()
+ };
+ if let Err(e) = repository::update_task_for_owner(pool, supervisor_id, owner_id, update).await {
+ tracing::warn!(supervisor_id = %supervisor_id, error = %e, "Failed to update task status to paused");
+ }
+
return (
StatusCode::OK,
Json(AskQuestionResponse {
@@ -1725,7 +1756,7 @@ pub async fn answer_question(
};
// Submit the response
- let success = state.submit_question_response(question_id, request.response);
+ let success = state.submit_question_response(question_id, request.response.clone());
if success {
tracing::info!(
@@ -1733,6 +1764,36 @@ pub async fn answer_question(
task_id = %question.task_id,
"User answered supervisor question"
);
+
+ // Send the response to the task as a message
+ // This will auto-resume the task if it was paused (phaseguard)
+ let pool = state.db_pool.as_ref().unwrap();
+ if let Ok(Some(task)) = repository::get_task_for_owner(pool, question.task_id, auth.owner_id).await {
+ if let Some(daemon_id) = task.daemon_id {
+ // Format the response message
+ let response_msg = format!(
+ "\n[User Response to Question]\nQuestion: {}\nAnswer: {}\n",
+ question.question,
+ request.response
+ );
+ let cmd = DaemonCommand::SendMessage {
+ task_id: question.task_id,
+ message: response_msg,
+ };
+ if let Err(e) = state.send_daemon_command(daemon_id, cmd).await {
+ tracing::warn!(
+ task_id = %question.task_id,
+ error = %e,
+ "Failed to send response message to task"
+ );
+ } else {
+ tracing::info!(
+ task_id = %question.task_id,
+ "Sent response message to task (will auto-resume if paused)"
+ );
+ }
+ }
+ }
}
Json(AnswerQuestionResponse { success }).into_response()