embabel-agent icon indicating copy to clipboard operation
embabel-agent copied to clipboard

EarlyTermination event published before status is set to TERMINATED (inconsistent with other terminal events)

Open azanux opened this issue 5 months ago • 3 comments

Problem

In AbstractAgentProcess.identifyEarlyTermination(), the termination event is dispatched to listeners before the process status is updated:

// AbstractAgentProcess.kt:407-409 and 433-435
platformServices.eventListener.onProcessEvent(signalTermination)
_failureInfo = signalTermination
setStatus(AgentProcessStatusCode.TERMINATED)

Any listener that reads event.getAgentProcess().getStatus() in response therefore observes the previous status (RUNNING) instead of TERMINATED.

This is inconsistent with every other terminal/lifecycle transition (COMPLETED, FAILED, WAITING, PAUSED, STUCK, KILLED), where the status is set before the corresponding event is published. Listeners reacting to a termination event see a stale, contradictory state.

Expected

When a termination event is delivered, agentProcess.getStatus() already reflects TERMINATED, matching the behaviour of all other lifecycle events.

Fix

Set the status before publishing the event at both sites in identifyEarlyTermination():

_failureInfo = signalTermination
setStatus(AgentProcessStatusCode.TERMINATED)
platformServices.eventListener.onProcessEvent(signalTermination)

azanux avatar Jun 14 '26 16:06 azanux

@azanux - good catch. Would you be able to make it for 0.5.0?

igordayen avatar Jun 14 '26 20:06 igordayen

@igordayen I will add the fix in the observability migration if is ok

. still doing some tests on the migration observability almost finish

azanux avatar Jun 14 '26 21:06 azanux

fix in #1718

azanux avatar Jun 15 '26 00:06 azanux