diff options
| author | Ben Sima <ben@bensima.com> | 2025-11-26 08:53:53 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-11-26 08:53:53 -0500 |
| commit | c119ac2fa14d99a7ac5cd4cfe809e862d4d892db (patch) | |
| tree | 47e46a712c43504d2c34bebdee2865b157c6a9ac /Omni/Agent/Worker.hs | |
| parent | b8df9ce47e36b0c643701f07fd24b1e75c8389c5 (diff) | |
Improve jr loop logging and fix review race condition
- Reorder loop to check pending reviews before starting new work -
Loop no longer exits on missing commit (skips instead) - Add [loop],
[review], [worker] prefixes to all log messages - Worker leaves task
in InProgress on amp failure (avoids retry loop)
Diffstat (limited to 'Omni/Agent/Worker.hs')
| -rw-r--r-- | Omni/Agent/Worker.hs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs index 3190bc7..d4809d2 100644 --- a/Omni/Agent/Worker.hs +++ b/Omni/Agent/Worker.hs @@ -18,7 +18,10 @@ import qualified System.Process as Process start :: Core.Worker -> Maybe Text -> IO () start worker maybeTaskId = do AgentLog.init (Core.workerName worker) - AgentLog.log ("Worker starting for " <> Core.workerName worker) + AgentLog.log ("[worker] Starting for " <> Core.workerName worker) + case maybeTaskId of + Just tid -> AgentLog.log ("[worker] Target task: " <> tid) + Nothing -> AgentLog.log "[worker] No specific task, will pick from ready queue" runOnce worker maybeTaskId runOnce :: Core.Worker -> Maybe Text -> IO () @@ -38,10 +41,10 @@ runOnce worker maybeTaskId = do case maybeTaskId of Just tid -> do AgentLog.updateActivity ("Task " <> tid <> " not found.") - AgentLog.log ("Task " <> tid <> " not found.") + AgentLog.log ("[worker] Task " <> tid <> " not found.") Nothing -> do AgentLog.updateActivity "No work found." - AgentLog.log "No ready tasks found." + AgentLog.log "[worker] No ready tasks found." Just task -> do processTask worker task @@ -51,32 +54,30 @@ processTask worker task = do let tid = TaskCore.taskId task AgentLog.update (\s -> s {AgentLog.statusTask = Just tid}) - AgentLog.updateActivity ("Claiming task " <> tid) + AgentLog.log ("[worker] Claiming task " <> tid) -- Claim task TaskCore.updateTaskStatus tid TaskCore.InProgress [] + AgentLog.log "[worker] Status -> InProgress" -- Run Amp - AgentLog.updateActivity "Running Amp agent..." + AgentLog.log "[worker] Starting amp..." (exitCode, output) <- runAmp repo task + AgentLog.log ("[worker] Amp exited with: " <> tshow exitCode) case exitCode of Exit.ExitSuccess -> do - AgentLog.log "Agent finished successfully" - - -- Run formatting and linting before commit - AgentLog.updateActivity "Running formatters..." + AgentLog.log "[worker] Running formatters..." _ <- runFormatters repo -- Try to commit (this runs git hooks which may fail) let commitMsg = formatCommitMessage task output - AgentLog.updateActivity "Committing..." + AgentLog.log "[worker] Attempting commit..." commitResult <- tryCommit repo commitMsg case commitResult of Left commitErr -> do - AgentLog.log ("Commit failed: " <> commitErr) - AgentLog.updateActivity "Commit failed, will retry" + AgentLog.log ("[worker] Commit failed: " <> commitErr) -- Save failure context and reopen task for retry maybeCtx <- TaskCore.getRetryContext tid @@ -84,7 +85,7 @@ processTask worker task = do if attempt > 3 then do - AgentLog.log "Task failed 3 times, needs human intervention" + AgentLog.log "[worker] Task failed 3 times, needs human intervention" TaskCore.updateTaskStatus tid TaskCore.Open [] else do TaskCore.setRetryContext @@ -96,17 +97,16 @@ processTask worker task = do TaskCore.retryReason = "commit_failed: " <> commitErr } TaskCore.updateTaskStatus tid TaskCore.Open [] - AgentLog.log ("Task reopened (attempt " <> tshow attempt <> "/3)") + AgentLog.log ("[worker] Task reopened (attempt " <> tshow attempt <> "/3)") Right () -> do -- Only set to Review after successful commit TaskCore.updateTaskStatus tid TaskCore.Review [] - AgentLog.updateActivity "Task completed" - AgentLog.log ("[✓] Task " <> tid <> " completed") + AgentLog.log ("[worker] ✓ Task " <> tid <> " -> Review") AgentLog.update (\s -> s {AgentLog.statusTask = Nothing}) Exit.ExitFailure code -> do - AgentLog.log ("Agent failed with code " <> tshow code) - AgentLog.updateActivity "Agent failed, retrying..." - threadDelay (10 * 1000000) -- Sleep 10s + AgentLog.log ("[worker] Amp failed with code " <> tshow code) + -- Don't set back to Open here - leave in InProgress for debugging + AgentLog.log "[worker] Task left in InProgress (amp failure)" -- | Run lint --fix to format and fix lint issues runFormatters :: FilePath -> IO (Either Text ()) |
