diff --git a/crates/db/src/models/execution_process.rs b/crates/db/src/models/execution_process.rs index 2f5cd86d..035302fe 100644 --- a/crates/db/src/models/execution_process.rs +++ b/crates/db/src/models/execution_process.rs @@ -168,25 +168,6 @@ impl ExecutionProcess { Ok(result) } - /// Count processes created after the given boundary process - pub async fn count_later_than( - pool: &SqlitePool, - task_attempt_id: Uuid, - boundary_process_id: Uuid, - ) -> Result { - let cnt = sqlx::query_scalar!( - r#"SELECT COUNT(1) as "count!:_" FROM execution_processes - WHERE task_attempt_id = $1 - AND created_at > (SELECT created_at FROM execution_processes WHERE id = $2)"#, - task_attempt_id, - boundary_process_id - ) - .fetch_one(pool) - .await - .unwrap_or(0i64); - Ok(cnt) - } - /// Find execution process by rowid pub async fn find_by_rowid(pool: &SqlitePool, rowid: i64) -> Result, sqlx::Error> { sqlx::query_as!( @@ -479,19 +460,6 @@ impl ExecutionProcess { Ok(()) } - pub async fn delete_by_task_attempt_id( - pool: &SqlitePool, - task_attempt_id: Uuid, - ) -> Result<(), sqlx::Error> { - sqlx::query!( - "DELETE FROM execution_processes WHERE task_attempt_id = $1", - task_attempt_id - ) - .execute(pool) - .await?; - Ok(()) - } - pub fn executor_action(&self) -> Result<&ExecutorAction, anyhow::Error> { match &self.executor_action.0 { ExecutorActionField::ExecutorAction(action) => Ok(action), @@ -501,28 +469,6 @@ impl ExecutionProcess { } } - /// Set restore boundary: drop processes newer than the specified process, undrop older/equal - pub async fn set_restore_boundary( - pool: &SqlitePool, - task_attempt_id: Uuid, - boundary_process_id: Uuid, - ) -> Result<(), sqlx::Error> { - // Monotonic drop: only mark newer records as dropped; never undrop. - sqlx::query!( - r#"UPDATE execution_processes - SET dropped = TRUE - WHERE task_attempt_id = $1 - AND created_at > (SELECT created_at FROM execution_processes WHERE id = $2) - AND dropped = FALSE - "#, - task_attempt_id, - boundary_process_id - ) - .execute(pool) - .await?; - Ok(()) - } - /// Soft-drop processes at and after the specified boundary (inclusive) pub async fn drop_at_and_after( pool: &SqlitePool, diff --git a/crates/db/src/models/execution_process_logs.rs b/crates/db/src/models/execution_process_logs.rs index 62206bc8..fc88f686 100644 --- a/crates/db/src/models/execution_process_logs.rs +++ b/crates/db/src/models/execution_process_logs.rs @@ -47,17 +47,6 @@ impl ExecutionProcessLogs { Ok(messages) } - /// Convert Vec to JSONL format - pub fn serialize_logs(messages: &[LogMsg]) -> Result { - let mut jsonl = String::new(); - for msg in messages { - let line = serde_json::to_string(msg)?; - jsonl.push_str(&line); - jsonl.push('\n'); - } - Ok(jsonl) - } - /// Append a JSONL line to the logs for an execution process pub async fn append_log_line( pool: &SqlitePool, diff --git a/crates/db/src/models/executor_session.rs b/crates/db/src/models/executor_session.rs index abe964a1..3fc370e7 100644 --- a/crates/db/src/models/executor_session.rs +++ b/crates/db/src/models/executor_session.rs @@ -32,28 +32,6 @@ pub struct UpdateExecutorSession { } impl ExecutorSession { - /// Find executor session by ID - #[allow(dead_code)] - pub async fn find_by_id(pool: &SqlitePool, id: Uuid) -> Result, sqlx::Error> { - sqlx::query_as!( - ExecutorSession, - r#"SELECT - id as "id!: Uuid", - task_attempt_id as "task_attempt_id!: Uuid", - execution_process_id as "execution_process_id!: Uuid", - session_id, - prompt, - summary, - created_at as "created_at!: DateTime", - updated_at as "updated_at!: DateTime" - FROM executor_sessions - WHERE id = $1"#, - id - ) - .fetch_optional(pool) - .await - } - /// Find executor session by execution process ID pub async fn find_by_execution_process_id( pool: &SqlitePool, @@ -78,57 +56,6 @@ impl ExecutorSession { .await } - /// Find all executor sessions for a task attempt - #[allow(dead_code)] - pub async fn find_by_task_attempt_id( - pool: &SqlitePool, - task_attempt_id: Uuid, - ) -> Result, sqlx::Error> { - sqlx::query_as!( - ExecutorSession, - r#"SELECT - id as "id!: Uuid", - task_attempt_id as "task_attempt_id!: Uuid", - execution_process_id as "execution_process_id!: Uuid", - session_id, - prompt, - summary, - created_at as "created_at!: DateTime", - updated_at as "updated_at!: DateTime" - FROM executor_sessions - WHERE task_attempt_id = $1 - ORDER BY created_at ASC"#, - task_attempt_id - ) - .fetch_all(pool) - .await - } - - pub async fn find_by_session_id( - pool: &SqlitePool, - session_id: &str, - ) -> Result, sqlx::Error> { - sqlx::query_as!( - ExecutorSession, - r#"SELECT - id as "id!: Uuid", - task_attempt_id as "task_attempt_id!: Uuid", - execution_process_id as "execution_process_id!: Uuid", - session_id, - prompt, - summary, - created_at as "created_at!: DateTime", - updated_at as "updated_at!: DateTime" - FROM executor_sessions - WHERE session_id = ? - ORDER BY updated_at DESC - LIMIT 1"#, - session_id - ) - .fetch_optional(pool) - .await - } - /// Create a new executor session pub async fn create( pool: &SqlitePool, @@ -194,28 +121,6 @@ impl ExecutorSession { Ok(()) } - /// Update executor session prompt - #[allow(dead_code)] - pub async fn update_prompt( - pool: &SqlitePool, - id: Uuid, - prompt: &str, - ) -> Result<(), sqlx::Error> { - let now = Utc::now(); - sqlx::query!( - r#"UPDATE executor_sessions - SET prompt = $1, updated_at = $2 - WHERE id = $3"#, - prompt, - now, - id - ) - .execute(pool) - .await?; - - Ok(()) - } - /// Update executor session summary pub async fn update_summary( pool: &SqlitePool, @@ -236,19 +141,4 @@ impl ExecutorSession { Ok(()) } - - /// Delete executor sessions for a task attempt (cleanup) - pub async fn delete_by_task_attempt_id( - pool: &SqlitePool, - task_attempt_id: Uuid, - ) -> Result<(), sqlx::Error> { - sqlx::query!( - "DELETE FROM executor_sessions WHERE task_attempt_id = $1", - task_attempt_id - ) - .execute(pool) - .await?; - - Ok(()) - } } diff --git a/crates/db/src/models/project.rs b/crates/db/src/models/project.rs index 4ce20752..e36b3e76 100644 --- a/crates/db/src/models/project.rs +++ b/crates/db/src/models/project.rs @@ -149,32 +149,6 @@ impl Project { .await } - pub async fn find_by_remote_project_id( - pool: &SqlitePool, - remote_project_id: Uuid, - ) -> Result, sqlx::Error> { - sqlx::query_as!( - Project, - r#"SELECT id as "id!: Uuid", - name, - git_repo_path, - setup_script, - dev_script, - cleanup_script, - copy_files, - parallel_setup_script as "parallel_setup_script!: bool", - remote_project_id as "remote_project_id: Uuid", - created_at as "created_at!: DateTime", - updated_at as "updated_at!: DateTime" - FROM projects - WHERE remote_project_id = $1 - LIMIT 1"#, - remote_project_id - ) - .fetch_optional(pool) - .await - } - pub async fn find_by_git_repo_path( pool: &SqlitePool, git_repo_path: &str, @@ -364,19 +338,4 @@ impl Project { .await?; Ok(result.rows_affected()) } - - pub async fn exists(pool: &SqlitePool, id: Uuid) -> Result { - let result = sqlx::query!( - r#" - SELECT COUNT(*) as "count!: i64" - FROM projects - WHERE id = $1 - "#, - id - ) - .fetch_one(pool) - .await?; - - Ok(result.count > 0) - } } diff --git a/crates/db/src/models/task.rs b/crates/db/src/models/task.rs index 25e25bf2..ce5b0684 100644 --- a/crates/db/src/models/task.rs +++ b/crates/db/src/models/task.rs @@ -238,23 +238,6 @@ ORDER BY t.created_at DESC"#, .await } - pub async fn find_by_id_and_project_id( - pool: &SqlitePool, - id: Uuid, - project_id: Uuid, - ) -> Result, sqlx::Error> { - sqlx::query_as!( - Task, - r#"SELECT id as "id!: Uuid", project_id as "project_id!: Uuid", title, description, status as "status!: TaskStatus", parent_task_attempt as "parent_task_attempt: Uuid", shared_task_id as "shared_task_id: Uuid", created_at as "created_at!: DateTime", updated_at as "updated_at!: DateTime" - FROM tasks - WHERE id = $1 AND project_id = $2"#, - id, - project_id - ) - .fetch_optional(pool) - .await - } - pub async fn find_by_shared_task_id<'e, E>( executor: E, shared_task_id: Uuid, @@ -458,21 +441,6 @@ ORDER BY t.created_at DESC"#, Ok(result.rows_affected()) } - pub async fn exists( - pool: &SqlitePool, - id: Uuid, - project_id: Uuid, - ) -> Result { - let result = sqlx::query!( - "SELECT id as \"id!: Uuid\" FROM tasks WHERE id = $1 AND project_id = $2", - id, - project_id - ) - .fetch_optional(pool) - .await?; - Ok(result.is_some()) - } - pub async fn find_children_by_attempt_id( pool: &SqlitePool, attempt_id: Uuid, diff --git a/crates/db/src/models/task_attempt.rs b/crates/db/src/models/task_attempt.rs index d2804264..63168711 100644 --- a/crates/db/src/models/task_attempt.rs +++ b/crates/db/src/models/task_attempt.rs @@ -262,30 +262,6 @@ impl TaskAttempt { .await } - /// Find task attempts by task_id with project git repo path for cleanup operations - pub async fn find_by_task_id_with_project( - pool: &SqlitePool, - task_id: Uuid, - ) -> Result, String)>, sqlx::Error> { - let records = sqlx::query!( - r#" - SELECT ta.id as "attempt_id!: Uuid", ta.container_ref, p.git_repo_path as "git_repo_path!" - FROM task_attempts ta - JOIN tasks t ON ta.task_id = t.id - JOIN projects p ON t.project_id = p.id - WHERE ta.task_id = $1 - "#, - task_id - ) - .fetch_all(pool) - .await?; - - Ok(records - .into_iter() - .map(|r| (r.attempt_id, r.container_ref, r.git_repo_path)) - .collect()) - } - pub async fn find_by_worktree_deleted( pool: &SqlitePool, ) -> Result, sqlx::Error> {