Skip to content

fix(session): prevent updateLastRoute from bypassing idle reset (#11520)#11580

Closed
VintLin wants to merge 1 commit into
openclaw:mainfrom
VintLin:fix/idle-session-reset-trigger
Closed

fix(session): prevent updateLastRoute from bypassing idle reset (#11520)#11580
VintLin wants to merge 1 commit into
openclaw:mainfrom
VintLin:fix/idle-session-reset-trigger

Conversation

@VintLin

@VintLin VintLin commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a bug where sessions configured with idleMinutes would never reset because updateLastRoute (called during inbound message recording) would bump the updatedAt timestamp to the current time before the session freshness check in initSessionState occurred.\n\n### Changes\n- Modified updateLastRoute in src/config/sessions/store.ts to preserve the existing updatedAt timestamp instead of refreshing it to Date.now(). This ensures that route metadata updates (which are purely administrative) do not affect the idle timeout logic.\n- Added a regression test in src/auto-reply/reply/session.test.ts that simulates an updateLastRoute call followed by initSessionState on a stale session.\n\nFixes #11520

Greptile Overview

Greptile Summary

This change updates updateLastRoute so that route/delivery metadata writes no longer refresh the session’s updatedAt, preventing idle-based reset logic in initSessionState from being bypassed. It also adds a regression test that writes a stale session entry, calls updateLastRoute, and asserts the session still resets under reset: { mode: "idle" }.

Key interaction: updatedAt is used by session freshness checks to decide whether to reuse an existing session or start a new one; updateLastRoute is invoked during inbound message recording, so its timestamp behavior directly affects idle reset behavior.

Confidence Score: 3/5

  • This PR is close to safe, but a timestamp edge case in updateLastRoute can cause incorrect idle resets for newly-created session keys.
  • The main fix (not bumping updatedAt during route metadata writes) matches the intended behavior and has a targeted regression test. However, the new logic sets updatedAt to 0 when existing is missing, which can make newly-created entries appear immediately stale and trigger unwanted session churn when updateLastRoute runs before session initialization.
  • src/config/sessions/store.ts

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

@greptile-apps greptile-apps 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.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +456 to +463
const next: SessionEntry = {
...(existing ?? {}),
...(metaPatch ?? {}),
...basePatch,
sessionId: existing?.sessionId ?? crypto.randomUUID(),
// Route metadata writes must not refresh session freshness timestamps.
updatedAt: existing?.updatedAt ?? 0,
};

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.

Stale updatedAt on new entry

updateLastRoute now forces updatedAt: existing?.updatedAt ?? 0. When the session key doesn’t exist yet, this creates a new SessionEntry with updatedAt = 0, which can cause an immediate idle reset on the next initSessionState (since the entry looks extremely stale). If updateLastRoute is called before the session is initialized for a brand-new conversation, this will likely churn session IDs/files until something else sets updatedAt.

Also appears in the same function by virtue of bypassing mergeSessionEntry, which previously ensured updatedAt was at least Date.now() for new entries.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/sessions/store.ts
Line: 456:463

Comment:
**Stale `updatedAt` on new entry**

`updateLastRoute` now forces `updatedAt: existing?.updatedAt ?? 0`. When the session key doesn’t exist yet, this creates a new `SessionEntry` with `updatedAt = 0`, which can cause an immediate idle reset on the next `initSessionState` (since the entry looks extremely stale). If `updateLastRoute` is called before the session is initialized for a brand-new conversation, this will likely churn session IDs/files until something else sets `updatedAt`.

Also appears in the same function by virtue of bypassing `mergeSessionEntry`, which previously ensured `updatedAt` was at least `Date.now()` for new entries.

How can I resolve this? If you propose a fix, please make it concise.

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.

1 participant