diff options
Diffstat (limited to 'Omni')
| -rw-r--r-- | Omni/Agent/Worker.hs | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs index 9a6a86f..f732436 100644 --- a/Omni/Agent/Worker.hs +++ b/Omni/Agent/Worker.hs @@ -66,29 +66,43 @@ processTask worker task = do -- Run formatting and linting before commit AgentLog.updateActivity "Running formatters..." - formatResult <- runFormatters repo - - case formatResult of - Left err -> do - AgentLog.log ("Formatting failed: " <> err) - AgentLog.updateActivity "Format failed, task incomplete" - -- Don't update status, leave as InProgress for retry + _ <- runFormatters repo + + -- Try to commit (this runs git hooks which may fail) + let commitMsg = formatCommitMessage output tid + AgentLog.updateActivity "Committing..." + commitResult <- tryCommit repo commitMsg + + case commitResult of + Left commitErr -> do + AgentLog.log ("Commit failed: " <> commitErr) + AgentLog.updateActivity "Commit failed, will retry" + + -- Save failure context and reopen task for retry + maybeCtx <- TaskCore.getRetryContext tid + let attempt = maybe 1 (\c -> TaskCore.retryAttempt c + 1) maybeCtx + + if attempt > 3 + then do + AgentLog.log "Task failed 3 times, needs human intervention" + TaskCore.updateTaskStatus tid TaskCore.Open [] + else do + TaskCore.setRetryContext + TaskCore.RetryContext + { TaskCore.retryTaskId = tid, + TaskCore.retryOriginalCommit = "", + TaskCore.retryConflictFiles = [], + TaskCore.retryAttempt = attempt, + TaskCore.retryReason = "commit_failed: " <> commitErr + } + TaskCore.updateTaskStatus tid TaskCore.Open [] + AgentLog.log ("Task reopened (attempt " <> tshow attempt <> "/3)") Right () -> do - -- Update status to Review + -- Only set to Review after successful commit TaskCore.updateTaskStatus tid TaskCore.Review [] - - -- Commit changes using Amp output (Gerrit-style trailer) - let commitMsg = formatCommitMessage output tid - commitResult <- tryCommit repo commitMsg - - case commitResult of - Left commitErr -> do - AgentLog.log ("Commit failed: " <> commitErr) - AgentLog.updateActivity "Commit failed" - Right () -> do - AgentLog.updateActivity "Task completed" - AgentLog.log ("[✓] Task " <> tid <> " completed") - AgentLog.update (\s -> s {AgentLog.statusTask = Nothing}) + AgentLog.updateActivity "Task completed" + AgentLog.log ("[✓] Task " <> tid <> " completed") + AgentLog.update (\s -> s {AgentLog.statusTask = Nothing}) Exit.ExitFailure code -> do AgentLog.log ("Agent failed with code " <> tshow code) AgentLog.updateActivity "Agent failed, retrying..." |
