Skip to content

fix(session): preserve lastAccountId and lastThreadId on session reset#44773

Merged
obviyus merged 2 commits intoopenclaw:mainfrom
Lanfei:fix/session-reset-account-id
Mar 13, 2026
Merged

fix(session): preserve lastAccountId and lastThreadId on session reset#44773
obviyus merged 2 commits intoopenclaw:mainfrom
Lanfei:fix/session-reset-account-id

Conversation

@Lanfei
Copy link
Contributor

@Lanfei Lanfei commented Mar 13, 2026

Summary

  • Problem: performGatewaySessionReset omitted lastAccountId and lastThreadId when constructing nextEntry, causing both fields to be lost after a session reset.
  • Why it matters: These fields identify the source account and thread for message routing; losing them after reset can cause replies to fail to route back to the original conversation.
  • What changed: Added lastAccountId and lastThreadId to the nextEntry construction in session-reset-service.ts, consistent with how lastChannel and lastTo are already handled.
  • What did NOT change: No other fields, reset flow steps, or ACP cleanup behavior are affected.

Change Type

  • Bug fix

Scope

  • Gateway / orchestration

Linked Issue/PR

  • Closes #

User-visible / Behavior Changes

After a session reset, lastAccountId and lastThreadId are now correctly preserved, restoring proper message routing behavior.

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS:
  • Runtime/container:
  • Model/provider:
  • Integration/channel (if any):
  • Relevant config (redacted):

Steps

  1. Establish an active session with lastAccountId / lastThreadId set (e.g. via a Discord thread message)
  2. Trigger a session reset (/reset or equivalent)
  3. Send a new message

Expected

  • Reply is routed back to the original account/thread

Actual (before fix)

  • lastAccountId / lastThreadId were cleared on reset, causing routing failure or lost replies

Evidence

  • Code diff directly shows the omitted fields

Human Verification

  • Verified scenarios: code review confirmed fields were missing from nextEntry
  • Edge cases checked: currentEntry being undefined is handled safely via optional chaining
  • What you did not verify: end-to-end Discord/Telegram thread reset flow

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery

  • How to disable/revert this change quickly: git revert this commit
  • Files/config to restore: src/gateway/session-reset-service.ts
  • Known bad symptoms reviewers should watch for: None

Risks and Mitigations

None

@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime size: XS labels Mar 13, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 13, 2026

Greptile Summary

This PR fixes a bug in performGatewaySessionReset where lastAccountId and lastThreadId were omitted from the nextEntry object, causing those fields to be cleared on every session reset and breaking reply-routing back to the originating account/thread.

  • The two-line fix in session-reset-service.ts is correct, minimal, and symmetric with how lastChannel and lastTo are already preserved.
  • Both fields are properly declared as optional properties in SessionEntry (src/config/sessions/types.ts), so no type changes are needed.
  • No existing test exercises performGatewaySessionReset with these fields set; the only test file that references the function mocks it out entirely. A regression test for this specific preservation behaviour would strengthen confidence.

Confidence Score: 4/5

  • Safe to merge — the fix is minimal, correct, and consistent with existing field-preservation patterns.
  • The change is a two-line addition that mirrors how lastChannel/lastTo are already handled; the fields are properly typed; and no unrelated logic is touched. The small score deduction reflects the absence of a dedicated unit or integration test verifying the preserved behaviour post-reset.
  • No files require special attention beyond the missing test coverage noted in src/gateway/session-reset-service.ts.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/gateway/session-reset-service.ts
Line: 341-342

Comment:
**No unit test covers the preserved fields after reset**

The fix is correct and symmetric with `lastChannel`/`lastTo`, but no test was added to verify that `lastAccountId` and `lastThreadId` survive a `performGatewaySessionReset` call. The existing test suite mocks out `performGatewaySessionReset` entirely (`agent.test.ts`) and the sessions integration test (`server.sessions.gateway-server-sessions-a.test.ts`) doesn't exercise the reset path with these fields set.

Consider adding a test that:
1. Seeds a session store entry with `lastAccountId` and `lastThreadId` populated.
2. Calls `performGatewaySessionReset`.
3. Asserts both fields are present and equal on the returned `entry`.

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

Last reviewed commit: 4166db7

Comment on lines +341 to +342
lastAccountId: currentEntry?.lastAccountId,
lastThreadId: currentEntry?.lastThreadId,
Copy link
Contributor

Choose a reason for hiding this comment

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

No unit test covers the preserved fields after reset

The fix is correct and symmetric with lastChannel/lastTo, but no test was added to verify that lastAccountId and lastThreadId survive a performGatewaySessionReset call. The existing test suite mocks out performGatewaySessionReset entirely (agent.test.ts) and the sessions integration test (server.sessions.gateway-server-sessions-a.test.ts) doesn't exercise the reset path with these fields set.

Consider adding a test that:

  1. Seeds a session store entry with lastAccountId and lastThreadId populated.
  2. Calls performGatewaySessionReset.
  3. Asserts both fields are present and equal on the returned entry.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/session-reset-service.ts
Line: 341-342

Comment:
**No unit test covers the preserved fields after reset**

The fix is correct and symmetric with `lastChannel`/`lastTo`, but no test was added to verify that `lastAccountId` and `lastThreadId` survive a `performGatewaySessionReset` call. The existing test suite mocks out `performGatewaySessionReset` entirely (`agent.test.ts`) and the sessions integration test (`server.sessions.gateway-server-sessions-a.test.ts`) doesn't exercise the reset path with these fields set.

Consider adding a test that:
1. Seeds a session store entry with `lastAccountId` and `lastThreadId` populated.
2. Calls `performGatewaySessionReset`.
3. Asserts both fields are present and equal on the returned `entry`.

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

@Lanfei
Copy link
Contributor Author

Lanfei commented Mar 13, 2026

Hey @jalehman @obviyus — could you take a look when you have a moment? CI is green and the change is small. I currently have several open PRs waiting for review, which is making it hard for me to continue contributing. Any feedback or a quick merge would be much appreciated. Thanks!

@obviyus obviyus self-assigned this Mar 13, 2026
@obviyus obviyus force-pushed the fix/session-reset-account-id branch from 4166db7 to 22947a4 Compare March 13, 2026 07:09
@obviyus obviyus merged commit d40a4e3 into openclaw:main Mar 13, 2026
28 checks passed
@obviyus
Copy link
Contributor

obviyus commented Mar 13, 2026

Landed on main.

Thanks @Lanfei.

@Lanfei Lanfei deleted the fix/session-reset-account-id branch March 13, 2026 07:11
@Lanfei
Copy link
Contributor Author

Lanfei commented Mar 13, 2026

Landed on main.

Thanks @Lanfei.

Thanks @obviyus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants