Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
> **Purpose:** Living document tracking all changes, decisions, and reasoning during implementation. Updated as work progresses for easy reference and review.


---

## 🔎 fix(runtime): the idle-conversation sweep aged conversations by the wrong clock (2026-08-10)

**Repo:** EDDI (`fix/idle-conversation-sweep-age`)

Two defects in `endOldConversationsWithOldAgents`, fixed together because fixing either alone is worse than fixing neither.

1. **`isOlderThanDays` ignored `Period`'s months component.** It read only `getYears()` and `getDays()`, so for a 35-day-old date against a 30-day limit `Period.between(now, date)` is `P-1M-4D` and the test became `-4 <= -30` → "not old". Whole bands of ages between the limit and one year were never reaped; the ones that were passed by coincidence of where the month boundary fell.
2. **The age came from the AGENT document's `lastModifiedOn`.** That is not a property of the conversation: every conversation on a given agent version shared one age, so a conversation the user was talking in an hour ago counted as idle whenever the agent config happened to be old.

The second was masked by the first. Correcting only the arithmetic would have converted a mostly-inert sweep into an eager one that ENDs live conversations — so the age signal now comes from the conversation's own newest step timestamp (`Data` stamps every entry at construction), with the descriptor kept only as a fallback and the conversation skipped entirely when no age signal exists at all. "Cannot prove it is idle" must never end a conversation.

Pinned by `recentConversationOnStaleAgentSurvives` (an hour-old conversation on a two-year-stale agent survives) and `noGapsAcrossMonthBoundaries` (every offset 30→400 days). +9 tests.

---

## 🔗 fix(agents): wire the deployment-wait machinery that only the ZIP importer ever used (2026-08-09)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import ai.labs.eddi.engine.hitl.lint.ReservedActionLint;
import ai.labs.eddi.engine.lifecycle.IConversation;
import ai.labs.eddi.engine.memory.IConversationMemoryStore;
import ai.labs.eddi.engine.memory.model.ConversationMemorySnapshot;
import ai.labs.eddi.engine.runtime.IAgentDeploymentManagement;
import ai.labs.eddi.engine.runtime.IAgentFactory;
import ai.labs.eddi.engine.runtime.IRuntime;
Expand All @@ -44,9 +45,9 @@
import java.net.URI;
import java.time.Instant;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -415,14 +416,35 @@ private void endOldConversationsWithOldAgents(String agentId, Integer agentVersi

var documentDescriptor = documentDescriptorStore.readDescriptor(conversationMemory.getAgentId(), conversationMemory.getAgentVersion());

// NOTE: age is derived from the AGENT document's lastModifiedOn, not the
// conversation's — a pre-existing heuristic that predates the HITL branch
// and is intentionally left unchanged here.
var timeOfLastInteractionInConversation = documentDescriptor.getLastModifiedOn();
// Age comes from the CONVERSATION's own newest step timestamp.
//
// It used to come from the AGENT document's lastModifiedOn, which is not a
// property of the conversation at all: every conversation on a given agent
// version shared one age, so a conversation the user was talking in an hour
// ago counted as idle whenever its agent config happened to be old. That
// mis-signal was masked by the arithmetic bug in isOlderThanDays below —
// fixing the arithmetic alone would have started ENDing live conversations,
// which is why both are corrected together.
var lastInteraction = lastInteractionOf(conversationMemory);
Comment thread
ginccc marked this conversation as resolved.
Resolved
if (lastInteraction == null) {
// No step ever carried a timestamp. Fall back to the descriptor, and
// skip entirely when even that is absent: "cannot prove it is idle" must
// never end a conversation, and dereferencing here would throw an NPE
// the enclosing UndeploymentExecutor does not catch — aborting every
// remaining undeploy attempt in this pass.
var descriptorLastModified = documentDescriptor.getLastModifiedOn();
if (descriptorLastModified == null) {
continue;
}
lastInteraction = descriptorLastModified.toInstant();
}
// ONE calendar date drives both the decision and the message. The sweep
// expires by LocalDate, so reporting elapsed 24-hour periods could end a
// conversation on its 30th calendar day while the log said 29 — the
// explanation contradicting the decision it explains.
var lastInteractionDate = lastInteraction.atZone(ZoneId.systemDefault()).toLocalDate();

var isOlderThanMaximumAmountOfDays = isOlderThanDays(
Instant.ofEpochMilli(timeOfLastInteractionInConversation.getTime()).atZone(ZoneId.systemDefault()).toLocalDate(),
maximumLifeTimeOfIdleConversationsInDays);
var isOlderThanMaximumAmountOfDays = isOlderThanDays(lastInteractionDate, maximumLifeTimeOfIdleConversationsInDays);

if (isOlderThanMaximumAmountOfDays) {
String conversationId = conversationMemory.getId();
Expand All @@ -431,7 +453,7 @@ private void endOldConversationsWithOldAgents(String agentId, Integer agentVersi
"Ended conversation (id: %s) with Agent (name: %s, id: %s, version: %d) "
+ "because it is %d days older than the maximum idle time of %d days",
conversationId, documentDescriptor.getName(), agentId, agentVersion,
DAYS.between(timeOfLastInteractionInConversation.toInstant(), Instant.now()), maximumLifeTimeOfIdleConversationsInDays);
DAYS.between(lastInteractionDate, LocalDate.now()), maximumLifeTimeOfIdleConversationsInDays);

LOGGER.info(message);
}
Expand All @@ -445,23 +467,52 @@ private void endOldConversationsWithOldAgents(String agentId, Integer agentVersi
}
}

private boolean isOlderThanDays(final LocalDate date, final int days) {
boolean result = false;

LocalDate now = LocalDate.now();
// period from now to date
Period period = Period.between(now, date);
/**
* The newest timestamp any data item in the conversation carries, or
* {@code null} when nothing is timestamped. This is the conversation's own
* last-interaction time: every turn writes step data through
* {@code ConversationStep}, and {@code Data} stamps each entry at construction.
*/
static Instant lastInteractionOf(ConversationMemorySnapshot snapshot) {
if (snapshot == null || snapshot.getConversationSteps() == null) {
return null;
}

if (period.getYears() < 0) {
// if year is negative, 100% older than 6 months
result = true;
} else if (period.getYears() == 0) {
if (period.getDays() <= -days) {
result = true;
Date newest = null;
for (var step : snapshot.getConversationSteps()) {
if (step == null || step.getWorkflows() == null) {
continue;
}
for (var workflow : step.getWorkflows()) {
if (workflow == null || workflow.getLifecycleTasks() == null) {
continue;
}
for (var task : workflow.getLifecycleTasks()) {
Date timestamp = task != null ? task.getTimestamp() : null;
if (timestamp != null && (newest == null || timestamp.after(newest))) {
newest = timestamp;
}
}
}
}

return result;
return newest != null ? newest.toInstant() : null;
}

/**
* True when {@code date} is at least {@code days} days in the past.
* <p>
* This was written against {@link Period}, which normalizes into
* years/months/days — and the check only ever looked at the years and days
* components, never the months. For a 35-day-old date and a 30-day limit,
* {@code Period.between(now, date)} is {@code P-1M-4D}, so the test read
* {@code -4 <= -30} and answered "not old". Whole bands of ages between
* {@code days} and one year were therefore never reaped, and the ones that were
* passed only by coincidence of where the month boundary fell. Day arithmetic
* has no such components.
*/
static boolean isOlderThanDays(final LocalDate date, final int days) {
return DAYS.between(date, LocalDate.now()) >= days;
}

private interface UndeploymentExecutor {
Expand Down
Loading
Loading