Skip to content

fix(runtime): age idle conversations by the conversation, not by the agent document - #660

Merged
ginccc merged 5 commits into
mainfrom
fix/idle-conversation-sweep-age
Aug 11, 2026
Merged

fix(runtime): age idle conversations by the conversation, not by the agent document#660
ginccc merged 5 commits into
mainfrom
fix/idle-conversation-sweep-age

Conversation

@ginccc

@ginccc ginccc commented Aug 10, 2026

Copy link
Copy Markdown
Member

Rebuilt onto current main. 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(). For a 35-day-old date against a 30-day limit, Period.between(now, date) is P-1M-4D, so 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 existing comment acknowledged the heuristic and left it in place.

Why they had to be fixed together

The arithmetic bug was masking the wrong signal. Correcting only the arithmetic would convert a mostly-inert sweep into an eager one that ENDs live conversations — strictly worse than the bug being fixed.

Age 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, and dereferencing a null descriptor timestamp would throw an NPE the enclosing UndeploymentExecutor does not catch, aborting every remaining undeploy in that pass.

Testing

+9 tests. recentConversationOnStaleAgentSurvives (an hour-old conversation on a two-year-stale agent survives) and noGapsAcrossMonthBoundaries (every offset 30→400 days) both fail against the old code.

Summary by CodeRabbit

  • Bug Fixes

    • Improved idle-conversation cleanup across month boundaries and exact age thresholds.
    • Uses the latest conversation activity timestamp, with descriptor time as a fallback.
    • Preserves recently active, human-awaiting, state-changed, and undated conversations.
  • Tests

    • Added regression coverage for timestamp selection, date calculations, descriptor availability, and idle-sweep behavior.
  • Documentation

    • Added a changelog entry describing the idle-conversation cleanup fixes.

…agent document

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

isOlderThanDays was written against Period, which normalizes to years/months/
days, and only read the years and days components. For a 35-day-old date against
a 30-day limit the period is P-1M-4D, so the test read -4 <= -30 and answered
'not old' — whole bands of ages were never reaped.

That bug was masking a wrong age SIGNAL: the age came from the AGENT document's
lastModifiedOn, which every conversation on that agent version shares, so a
conversation touched an hour ago was 'idle' whenever the agent config was old.
Correcting only the arithmetic would have started ENDing live conversations.

Age now comes from the conversation's own newest step timestamp, with the
descriptor as a fallback and the conversation skipped when no age signal exists
at all.

+9 tests.
@ginccc
ginccc requested a review from rolandpickl as a code owner August 10, 2026 19:47
@github-actions

Copy link
Copy Markdown

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ginccc, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f7957f60-28d4-4501-869a-4acac3d89f92

📥 Commits

Reviewing files that changed from the base of the PR and between 0e17227 and b878e3b.

📒 Files selected for processing (3)
  • docs/changelog.md
  • src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java
  • src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java
📝 Walkthrough

Walkthrough

Idle conversation sweeping now uses the newest conversation lifecycle timestamp, falls back to descriptor metadata, skips conversations without age data, and evaluates elapsed calendar days. Compare-and-set state updates preserve conversations that changed after the sweep read. Regression tests cover these behaviors.

Changes

Idle conversation sweep

Layer / File(s) Summary
Timestamp selection and age calculation
src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java
The sweep uses the newest lifecycle-task timestamp for conversation age. It falls back to the descriptor timestamp and skips conversations without either timestamp. Age checks and logging use elapsed calendar days.
Conditional conversation ending
src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java
The sweep changes a conversation to ENDED only when its state still matches the observed snapshot state.
Idle sweep regression coverage
src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java, docs/changelog.md
Tests cover timestamp selection, month boundaries, thresholds, descriptor fallback, missing descriptors, state changes, and sweep outcomes. The changelog records the fixes and test coverage.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AgentDeploymentManagement
  participant ConversationMemorySnapshot
  participant AgentDescriptor
  participant ConversationStore
  AgentDeploymentManagement->>ConversationMemorySnapshot: read conversation activity timestamps
  AgentDeploymentManagement->>AgentDescriptor: read fallback timestamp when needed
  AgentDeploymentManagement->>AgentDeploymentManagement: evaluate calendar-day idle threshold
  AgentDeploymentManagement->>ConversationStore: compare observed state and set ENDED
Loading

Possibly related PRs

  • labsai/EDDI#654: Both changes update AgentDeploymentManagement idle-sweep timestamp selection and calendar-day age calculations.

Suggested reviewers: rolandpickl

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: idle conversation age now uses conversation activity instead of the agent document.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/idle-conversation-sweep-age

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java (1)

203-223: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover both no-task-timestamp sweep branches.

This fixture always supplies DocumentDescriptor.lastModifiedOn. Add sweep tests where an untimestamped snapshot uses an old descriptor timestamp and is ended, and where both timestamps are absent and the conversation is preserved. These are the new fallback and skip behaviors described by this PR.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java`
around lines 203 - 223, Extend AgentDeploymentManagementIdleSweepTest beyond
givenOldAgentVersionWithConversation to cover both no-task-timestamp branches:
verify an untimestamped snapshot is ended when the descriptor lastModifiedOn is
old, and verify the conversation is preserved when both the snapshot task
timestamp and descriptor timestamp are absent. Reuse the existing deployment and
store setup while varying descriptor timestamp presence and asserting the
corresponding sweep outcome.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java`:
- Around line 441-444: Update the age value reported by the conversation sweep
to use the same calendar-day calculation as isOlderThanDays, based on
lastInteraction converted to the system-default LocalDate, rather than elapsed
24-hour duration. Ensure the log reports 30 days when the sweep expires a
conversation on the 30th calendar day.

---

Nitpick comments:
In
`@src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java`:
- Around line 203-223: Extend AgentDeploymentManagementIdleSweepTest beyond
givenOldAgentVersionWithConversation to cover both no-task-timestamp branches:
verify an untimestamped snapshot is ended when the descriptor lastModifiedOn is
old, and verify the conversation is preserved when both the snapshot task
timestamp and descriptor timestamp are absent. Reuse the existing deployment and
store setup while varying descriptor timestamp presence and asserting the
corresponding sweep outcome.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fba4f7e7-e449-49ff-8bb1-fce07cff0b8e

📥 Commits

Reviewing files that changed from the base of the PR and between c3cc407 and 7c8c64d.

📒 Files selected for processing (3)
  • docs/changelog.md
  • src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java
  • src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java

Comment thread src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes idle-conversation cleanup to use conversation activity rather than agent metadata.

Changes:

  • Corrects day calculations across month boundaries.
  • Derives activity from the newest conversation-step timestamp.
  • Adds regression tests and changelog documentation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
AgentDeploymentManagement.java Updates idle-age detection and timestamp selection.
AgentDeploymentManagementIdleSweepTest.java Adds regression coverage for cleanup behavior.
docs/changelog.md Documents the fixes and rationale.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java Outdated
…cover both fallback branches

CodeRabbit on #660:

- The sweep expires by LocalDate but the log reported elapsed 24-hour periods,
  so a conversation ended on its 30th calendar day could be logged as 29 days —
  the explanation contradicting the decision it explains. One calendar date now
  drives both.
- The two fallback branches this PR introduces had no coverage: the fixture
  always supplied both a step timestamp and a descriptor timestamp, so neither
  the descriptor fallback nor the no-signal skip was ever reached. Added three
  tests — untimestamped + old descriptor ends, untimestamped + recent descriptor
  survives, and no signal anywhere preserves the conversation (which would also
  NPE out of the uncaught UndeploymentExecutor without the guard).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java (1)

107-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the calendar-boundary tests deterministic.

LocalDate.now() runs in both the test and isOlderThanDays. If midnight occurs between those calls, the 29-day case becomes 30 days and can fail. Pass a fixed reference date through a testable overload, then use that date for all boundary assertions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java`
around lines 107 - 133, Make the calendar-boundary tests deterministic by adding
or using a testable overload of AgentDeploymentManagement.isOlderThanDays that
accepts a fixed reference date, then pass the same fixed date to every assertion
in boundaries, noGapsAcrossMonthBoundaries, and noFalsePositives instead of
calling LocalDate.now(). Ensure the production behavior remains unchanged for
callers using the existing API.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java`:
- Around line 107-133: Make the calendar-boundary tests deterministic by adding
or using a testable overload of AgentDeploymentManagement.isOlderThanDays that
accepts a fixed reference date, then pass the same fixed date to every assertion
in boundaries, noGapsAcrossMonthBoundaries, and noFalsePositives instead of
calling LocalDate.now(). Ensure the production behavior remains unchanged for
callers using the existing API.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ceaf86c2-0d05-4adf-804f-05f6439e8745

📥 Commits

Reviewing files that changed from the base of the PR and between 7c8c64d and 8c70903.

📒 Files selected for processing (2)
  • src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java
  • src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java

… ENDED write

Copilot + CodeRabbit on #660:

- readDescriptor was read unconditionally at the top of the loop but THROWS for a
  deleted agent — and manageAgentDeployments deliberately routes deleted agents
  down this path, since getCurrentResourceId throwing is how it decides the agent
  is gone. One deleted agent therefore aborted the whole sweep, including
  conversations carrying a perfectly good timestamp that never needed it. Now
  read lazily and never fatally.
- The ENDED write was a check-then-act race: snapshots are read at the top of the
  sweep, so a user turn or an HITL pause landing before the write would be
  destroyed by an unconditional set. Now a compareAndSetState against the state
  the snapshot was loaded with. This was latent while the arithmetic bug kept the
  sweep inert — correcting the arithmetic is what makes it fire.
- The log reported elapsed 24-hour periods while the sweep expires by calendar
  day, so a conversation ended on day 30 could be logged as 29.
- Boundary tests evaluated LocalDate.now() independently from the impl, so a case
  built at 23:59:59.999 and checked at 00:00:00.001 shifted by a day; both sides
  now share a pinned reference date.

+5 tests.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java`:
- Around line 468-471: Update the expiration handling in
AgentDeploymentManagement to capture a single LocalDate reference before the
expiration decision, then reuse it for both the idle-time calculation and the
log message formatting. Remove the separate LocalDate.now() call used by the
message so the reported age matches the date that triggered conversation
termination.
- Around line 462-467: The sweep in the conversation-ending flow around
conversationMemory.getConversationState and compareAndSetState must also
validate that the conversation has not changed since the snapshot. Capture and
include a revision or lastInteraction predicate in the atomic update, so the
transition to ConversationState.ENDED only succeeds when both the observed state
and activity marker still match; otherwise retain the existing skipped-ending
behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f6af8e78-1c26-4aa3-b926-9375a3d570c2

📥 Commits

Reviewing files that changed from the base of the PR and between 8c70903 and 0e17227.

📒 Files selected for processing (2)
  • src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.java
  • src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java

CodeRabbit Major on #660: compareAndSetState checks only the state, so a turn
that starts AND completes between the snapshot and the CAS returns the state to
the observed value — the CAS then succeeds against a demonstrably active
conversation.

The age is the ABA-resistant signal: a completed turn moves the newest step
timestamp. The sweep now re-reads the conversation and re-checks its age
immediately before the write, which also shrinks the window from 'the whole
scan' to one store round-trip. A re-read failure leaves the conversation alone —
unable to confirm it is still idle is not permission to end it.

What remains is a turn completing entirely between that re-read and the CAS.
Closing that needs a revision-conditional update in IConversationMemoryStore and
both backends rather than a state-only CAS; that is a store-contract change and
is documented in the code rather than bundled here.

Also captures one reference date for the decision and the reported age, which
could otherwise disagree across midnight.

+2 tests.
@aisabella-ai
aisabella-ai self-requested a review August 11, 2026 06:33
@ginccc
ginccc merged commit f430b28 into main Aug 11, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants