Skip to content

Commit e24fc77

Browse files
ericdalloeca-agent
andcommitted
Fix race in kill-job! overwriting :killed with :failed
Commit :killed to the registry before destroying the process so the exit monitor can't race ahead and overwrite it with :failed (exit 143). Fixes the flaky background-job-lifecycle integration test. (#510) 🤖 Generated with [ECA](https://eca.dev) (nubank-anthropic/opus-4.8 - max) Co-Authored-By: eca-agent <git@eca.dev>
1 parent 970cca8 commit e24fc77

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Bugfix: `kill-job!` commits `:killed` before destroying the process, fixing a race where the exit monitor overwrote it with `:failed` (exit 143). (#510)
6+
57
## 0.142.1
68

79
- Bugfix: `postRequest` hook no longer fires for subagent chats; subagents use `subagentPostRequest` only, preventing duplicate hook notifications. (#505)

src/eca/features/background_tasks.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,13 @@
214214
(if-let [job (get-job job-id)]
215215
(if (= :running (:status job))
216216
(do
217-
(kill-job-impl job)
217+
;; Commit :killed before destroying the process so monitor-process-exit!
218+
;; never races ahead and overwrites it with :failed (exit 143/SIGTERM).
218219
(swap! registry* (fn [reg]
219220
(-> reg
220221
(assoc-in [:jobs job-id :status] :killed)
221222
(assoc-in [:jobs job-id :ended-at] (Instant/now)))))
223+
(kill-job-impl job)
222224
(logger/info logger-tag "Killed background job" {:id job-id})
223225
true)
224226
(do

0 commit comments

Comments
 (0)