fix: persist immediate agent termination and emit lifecycle event - #2010
arnabnandy7 wants to merge 2 commits into
Conversation
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
860a4b5 to
90477cc
Compare
0e51880 to
628981d
Compare
|
Thank you for the fix. The approach is correct: the immediate-termination branch must persist, because it has no guaranteed next tick. Three items block approval. 1. setStatus(AgentProcessStatusCode.TERMINATED)
platformServices.agentProcessRepository.update(this)
Attempted to update ephemeral AgentProcess [id={}].
Ephemeral processes are not persisted.
Operation skipped.Termination of an ephemeral process is legal. Each call now writes an error line. Please guard the new call: if (!processOptions.ephemeral) {
platformServices.agentProcessRepository.update(this)
}2. val previousStatus = _status.getAndSet(status)
if (status == AgentProcessStatusCode.TERMINATED && previousStatus != status) {
platformServices.eventListener.onProcessEvent(AgentProcessTerminatedEvent(this))
}
3. class AgentProcessTerminatedEvent(
agentProcess: AgentProcess,
) : AgentProcessFinishedEvent(agentProcess)
Minor - The new imports break the existing order. |
628981d to
68201e5
Compare
|
@simeshev thanks for the detailed review. I’ve addressed the points you raised:
|
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
68201e5 to
b351920
Compare
|
I'm adding the problem statement:
Fix: step 3 must also write TERMINATED to the database. |
Thanks for adding the concrete scenario. The updated immediate-termination path now persists |
External termination of a WAITING, PAUSED, STUCK, or COMPLETED process currently changes its runtime status without updating the repository. A stored WAITING snapshot can therefore survive termination and be restored after runtime state is lost.
This change calls the repository update in the immediate-termination branch, allowing the existing lifecycle checkpoint policy to persist TERMINATED. It adds AgentProcessTerminatedEvent at the status transition for observability and cache invalidation, emitting once per transition. Interrupted action delays now return AGENT_TERMINATED so the caller preserves the terminal status instead of overwriting it with FAILED.
The repository checkpoint policy remains the single persistence path. No event-driven checkpoint listener or snapshot deduplication is added.
Follow-up to #1988, replacing the approach in #2008 as requested in #2005 (comment).
Validation covers immediate termination from all four states, snapshot version advancement, repeated termination, restoration after runtime loss, signal/policy event status ordering, action-requested termination, and interrupted delays.
Validation on JDK 21:
mvn -B spotless:check -pl embabel-agent-apipassed.PersistentAgentProcessRepositoryTest,SimpleAgentProcessTest,AbstractAgentProcessTerminationStatusOrderingTest,TerminationAgenticTest, andAgentActionDelayTest.surefire:testrun. Every new regression and all termination/persistence tests passed in both runs.AgentActionDelayTestzero-delay assertions failed their strict< 50 mswall-clock threshold (66–163 ms observed on the separate run). The full lifecycle run also hit these assertions, with one passing on retry. These timing failures remain unresolved; the PR is draft for review.Reproduction:
mvn -B test -pl embabel-agent-api -Dkotlin.compiler.daemon=false -Dtest=PersistentAgentProcessRepositoryTest,SimpleAgentProcessTest,AbstractAgentProcessTerminationStatusOrderingTest,TerminationAgenticTest,AgentActionDelayTest mvn -B spotless:check surefire:test -pl embabel-agent-api -Dtest=PersistentAgentProcessRepositoryTest,SimpleAgentProcessTest,AbstractAgentProcessTerminationStatusOrderingTest,TerminationAgenticTest,AgentActionDelayTest