fix(runtime): age idle conversations by the conversation, not by the agent document - #660
Conversation
…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.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughIdle 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. ChangesIdle conversation sweep
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 winCover 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
📒 Files selected for processing (3)
docs/changelog.mdsrc/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.javasrc/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java
There was a problem hiding this comment.
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.
…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).
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/test/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagementIdleSweepTest.java (1)
107-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake the calendar-boundary tests deterministic.
LocalDate.now()runs in both the test andisOlderThanDays. 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
📒 Files selected for processing (2)
src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.javasrc/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.
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/main/java/ai/labs/eddi/engine/runtime/internal/AgentDeploymentManagement.javasrc/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.
…-sweep-age # Conflicts: # docs/changelog.md
Rebuilt onto current
main. Two defects inendOldConversationsWithOldAgents, fixed together because fixing either alone is worse than fixing neither.1.
isOlderThanDaysignoredPeriod's months componentIt read only
getYears()andgetDays(). For a 35-day-old date against a 30-day limit,Period.between(now, date)isP-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
lastModifiedOnThat 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
ENDslive conversations — strictly worse than the bug being fixed.Age now comes from the conversation's own newest step timestamp (
Datastamps 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 enclosingUndeploymentExecutordoes not catch, aborting every remaining undeploy in that pass.Testing
+9 tests.
recentConversationOnStaleAgentSurvives(an hour-old conversation on a two-year-stale agent survives) andnoGapsAcrossMonthBoundaries(every offset 30→400 days) both fail against the old code.Summary by CodeRabbit
Bug Fixes
Tests
Documentation