Swap executor config for executor

This commit is contained in:
Louis Knight-Webb
2025-06-16 20:34:56 -04:00
parent aeee2c8941
commit 73af2b6fd9
2 changed files with 33 additions and 19 deletions

View File

@@ -0,0 +1,18 @@
-- Change executor_config column to executor (string) in task_attempts table
-- Add the new executor column
ALTER TABLE task_attempts ADD COLUMN executor TEXT;
-- Convert existing executor_config data to executor names
-- This assumes the existing JSONB data has a structure we can extract from
UPDATE task_attempts
SET executor = CASE
WHEN executor_config IS NULL THEN NULL
WHEN executor_config->>'type' = 'Echo' THEN 'echo'
WHEN executor_config->>'type' = 'Claude' THEN 'claude'
ELSE 'echo' -- Default fallback
END
WHERE executor_config IS NOT NULL;
-- Drop the old executor_config column
ALTER TABLE task_attempts DROP COLUMN executor_config;

View File

@@ -62,8 +62,7 @@ pub struct TaskAttempt {
pub base_commit: Option<String>, pub base_commit: Option<String>,
pub merge_commit: Option<String>, pub merge_commit: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
#[ts(skip)] pub executor: Option<String>, // Name of the executor to use
pub executor_config: Option<serde_json::Value>, // JSON field for ExecutorConfig
pub stdout: Option<String>, pub stdout: Option<String>,
pub stderr: Option<String>, pub stderr: Option<String>,
pub created_at: DateTime<Utc>, pub created_at: DateTime<Utc>,
@@ -77,7 +76,7 @@ pub struct CreateTaskAttempt {
pub worktree_path: String, pub worktree_path: String,
pub base_commit: Option<String>, pub base_commit: Option<String>,
pub merge_commit: Option<String>, pub merge_commit: Option<String>,
pub executor_config: Option<ExecutorConfig>, pub executor: Option<String>,
} }
#[derive(Debug, Deserialize, TS)] #[derive(Debug, Deserialize, TS)]
@@ -92,7 +91,7 @@ impl TaskAttempt {
pub async fn find_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Self>, sqlx::Error> { pub async fn find_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Self>, sqlx::Error> {
sqlx::query_as!( sqlx::query_as!(
TaskAttempt, TaskAttempt,
r#"SELECT id, task_id, worktree_path, base_commit, merge_commit, executor_config, stdout, stderr, created_at, updated_at r#"SELECT id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at, updated_at
FROM task_attempts FROM task_attempts
WHERE id = $1"#, WHERE id = $1"#,
id id
@@ -104,7 +103,7 @@ impl TaskAttempt {
pub async fn find_by_task_id(pool: &PgPool, task_id: Uuid) -> Result<Vec<Self>, sqlx::Error> { pub async fn find_by_task_id(pool: &PgPool, task_id: Uuid) -> Result<Vec<Self>, sqlx::Error> {
sqlx::query_as!( sqlx::query_as!(
TaskAttempt, TaskAttempt,
r#"SELECT id, task_id, worktree_path, base_commit, merge_commit, executor_config, stdout, stderr, created_at, updated_at r#"SELECT id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at, updated_at
FROM task_attempts FROM task_attempts
WHERE task_id = $1 WHERE task_id = $1
ORDER BY created_at DESC"#, ORDER BY created_at DESC"#,
@@ -138,24 +137,18 @@ impl TaskAttempt {
let branch_name = format!("attempt-{}", attempt_id); let branch_name = format!("attempt-{}", attempt_id);
repo.worktree(&branch_name, worktree_path, None)?; repo.worktree(&branch_name, worktree_path, None)?;
// Serialize executor config to JSON
let executor_config_json = data.executor_config.as_ref()
.map(|config| serde_json::to_value(config))
.transpose()
.map_err(|e| TaskAttemptError::Database(sqlx::Error::decode(e)))?;
// Insert the record into the database // Insert the record into the database
let task_attempt = sqlx::query_as!( let task_attempt = sqlx::query_as!(
TaskAttempt, TaskAttempt,
r#"INSERT INTO task_attempts (id, task_id, worktree_path, base_commit, merge_commit, executor_config, stdout, stderr) r#"INSERT INTO task_attempts (id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, task_id, worktree_path, base_commit, merge_commit, executor_config, stdout, stderr, created_at, updated_at"#, RETURNING id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at, updated_at"#,
attempt_id, attempt_id,
data.task_id, data.task_id,
data.worktree_path, data.worktree_path,
data.base_commit, data.base_commit,
data.merge_commit, data.merge_commit,
executor_config_json, data.executor,
None::<String>, // stdout None::<String>, // stdout
None::<String> // stderr None::<String> // stderr
) )
@@ -181,13 +174,16 @@ impl TaskAttempt {
/// Get the executor for this task attempt, defaulting to Echo if none is specified /// Get the executor for this task attempt, defaulting to Echo if none is specified
pub fn get_executor(&self) -> Box<dyn crate::executor::Executor> { pub fn get_executor(&self) -> Box<dyn crate::executor::Executor> {
if let Some(config_json) = &self.executor_config { if let Some(executor_name) = &self.executor {
if let Ok(config) = serde_json::from_value::<ExecutorConfig>(config_json.clone()) { match executor_name.as_str() {
return config.create_executor(); "echo" => ExecutorConfig::Echo.create_executor(),
"claude" => ExecutorConfig::Claude.create_executor(),
_ => ExecutorConfig::Echo.create_executor(), // Default fallback
} }
} else {
// Default to echo executor
ExecutorConfig::Echo.create_executor()
} }
// Default to echo executor
ExecutorConfig::Echo.create_executor()
} }
/// Update stdout and stderr for this task attempt /// Update stdout and stderr for this task attempt