Task attempt 16132ff6-fd9b-4551-86b9-c6b161df4f57 - Final changes
This commit is contained in:
50
backend/.sqlx/query-bd57e47989627ac5e9f44e83f4bacff590d357586b149c7c17ff0e8f349e7025.json
generated
Normal file
50
backend/.sqlx/query-bd57e47989627ac5e9f44e83f4bacff590d357586b149c7c17ff0e8f349e7025.json
generated
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT \n taa.id as \"activity_id!: Uuid\",\n taa.execution_process_id as \"execution_process_id!: Uuid\",\n taa.status as \"status!: TaskAttemptStatus\",\n taa.note,\n taa.created_at as \"created_at!: DateTime<Utc>\",\n es.prompt\n FROM task_attempt_activities taa\n INNER JOIN execution_processes ep ON taa.execution_process_id = ep.id\n LEFT JOIN executor_sessions es ON es.execution_process_id = ep.id\n WHERE ep.task_attempt_id = $1\n ORDER BY taa.created_at ASC",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "activity_id!: Uuid",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "execution_process_id!: Uuid",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "status!: TaskAttemptStatus",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "note",
|
||||
"ordinal": 3,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "created_at!: DateTime<Utc>",
|
||||
"ordinal": 4,
|
||||
"type_info": "Datetime"
|
||||
},
|
||||
{
|
||||
"name": "prompt",
|
||||
"ordinal": 5,
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "bd57e47989627ac5e9f44e83f4bacff590d357586b149c7c17ff0e8f349e7025"
|
||||
}
|
||||
@@ -24,6 +24,17 @@ pub struct CreateTaskAttemptActivity {
|
||||
pub note: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||
#[ts(export)]
|
||||
pub struct TaskAttemptActivityWithPrompt {
|
||||
pub id: Uuid,
|
||||
pub execution_process_id: Uuid,
|
||||
pub status: TaskAttemptStatus,
|
||||
pub note: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub prompt: Option<String>, // From executor_session
|
||||
}
|
||||
|
||||
impl TaskAttemptActivity {
|
||||
pub async fn find_by_execution_process_id(
|
||||
pool: &SqlitePool,
|
||||
@@ -84,4 +95,40 @@ impl TaskAttemptActivity {
|
||||
|
||||
Ok(records.into_iter().map(|r| r.id).collect())
|
||||
}
|
||||
|
||||
/// Find activities for all execution processes in a task attempt, with executor session prompts
|
||||
pub async fn find_with_prompts_by_task_attempt_id(
|
||||
pool: &SqlitePool,
|
||||
task_attempt_id: Uuid,
|
||||
) -> Result<Vec<TaskAttemptActivityWithPrompt>, sqlx::Error> {
|
||||
let records = sqlx::query!(
|
||||
r#"SELECT
|
||||
taa.id as "activity_id!: Uuid",
|
||||
taa.execution_process_id as "execution_process_id!: Uuid",
|
||||
taa.status as "status!: TaskAttemptStatus",
|
||||
taa.note,
|
||||
taa.created_at as "created_at!: DateTime<Utc>",
|
||||
es.prompt
|
||||
FROM task_attempt_activities taa
|
||||
INNER JOIN execution_processes ep ON taa.execution_process_id = ep.id
|
||||
LEFT JOIN executor_sessions es ON es.execution_process_id = ep.id
|
||||
WHERE ep.task_attempt_id = $1
|
||||
ORDER BY taa.created_at ASC"#,
|
||||
task_attempt_id
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
|
||||
Ok(records
|
||||
.into_iter()
|
||||
.map(|record| TaskAttemptActivityWithPrompt {
|
||||
id: record.activity_id,
|
||||
execution_process_id: record.execution_process_id,
|
||||
status: record.status,
|
||||
note: record.note,
|
||||
created_at: record.created_at,
|
||||
prompt: record.prompt,
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::models::{
|
||||
BranchStatus, CreateFollowUpAttempt, CreateTaskAttempt, TaskAttempt, TaskAttemptStatus,
|
||||
WorktreeDiff,
|
||||
},
|
||||
task_attempt_activity::{CreateTaskAttemptActivity, TaskAttemptActivity},
|
||||
task_attempt_activity::{CreateTaskAttemptActivity, TaskAttemptActivity, TaskAttemptActivityWithPrompt},
|
||||
ApiResponse,
|
||||
};
|
||||
|
||||
@@ -51,7 +51,7 @@ pub async fn get_task_attempts(
|
||||
pub async fn get_task_attempt_activities(
|
||||
Path((project_id, task_id, attempt_id)): Path<(Uuid, Uuid, Uuid)>,
|
||||
Extension(pool): Extension<SqlitePool>,
|
||||
) -> Result<ResponseJson<ApiResponse<Vec<TaskAttemptActivity>>>, StatusCode> {
|
||||
) -> Result<ResponseJson<ApiResponse<Vec<TaskAttemptActivityWithPrompt>>>, StatusCode> {
|
||||
// Verify task attempt exists and belongs to the correct task
|
||||
match TaskAttempt::exists_for_task(&pool, attempt_id, task_id, project_id).await {
|
||||
Ok(false) => return Err(StatusCode::NOT_FOUND),
|
||||
@@ -62,40 +62,8 @@ pub async fn get_task_attempt_activities(
|
||||
Ok(true) => {}
|
||||
}
|
||||
|
||||
// Get all execution processes for the task attempt
|
||||
let execution_processes =
|
||||
match ExecutionProcess::find_by_task_attempt_id(&pool, attempt_id).await {
|
||||
Ok(processes) => processes,
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
"Failed to fetch execution processes for attempt {}: {}",
|
||||
attempt_id,
|
||||
e
|
||||
);
|
||||
return Err(StatusCode::INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
};
|
||||
|
||||
// Get activities for all execution processes
|
||||
let mut all_activities = Vec::new();
|
||||
for process in execution_processes {
|
||||
match TaskAttemptActivity::find_by_execution_process_id(&pool, process.id).await {
|
||||
Ok(mut activities) => all_activities.append(&mut activities),
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
"Failed to fetch activities for execution process {}: {}",
|
||||
process.id,
|
||||
e
|
||||
);
|
||||
return Err(StatusCode::INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort activities by created_at
|
||||
all_activities.sort_by(|a, b| a.created_at.cmp(&b.created_at));
|
||||
|
||||
match Ok::<Vec<TaskAttemptActivity>, sqlx::Error>(all_activities) {
|
||||
// Get activities with prompts for the task attempt
|
||||
match TaskAttemptActivity::find_with_prompts_by_task_attempt_id(&pool, attempt_id).await {
|
||||
Ok(activities) => Ok(ResponseJson(ApiResponse {
|
||||
success: true,
|
||||
data: Some(activities),
|
||||
|
||||
Reference in New Issue
Block a user