Fix #1532: Agent incorrectly acts on cross-session memory context in new sessions - #1869
Merged
Conversation
- Add session tracking to detect when memories are from previous sessions - Tag cross-session memories with [from previous session] marker - Inject passive instructions for cross-session memories (background knowledge only) - Agent now waits for user's explicit instruction in new sessions - Preserve active memory usage within same session Fixes #1532
Memtensor-AI
requested review from
CarltonXiang,
MatthewZhuang and
syzsunshine219
June 3, 2026 08:41
Collaborator
Author
|
Automated Test Results: PASSED\n\nCloud test-engine rerun after resolving the dev-v2.0.22 merge conflict.\n\nRun: tr-a3469260-15d\nScope: memos_local_openclaw\nResult: 13/13 tests passed\nCommand group: memos_local_openclaw/unit\nDuration: 3s\n\nLocal pre-push verification also passed: npm run build, plus focused vitest for cross-session-memory.\n\nStatus: merge conflict resolved; automated scope test passed. Manual code review is still required before merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Successfully fixed issue #1532 where the agent incorrectly acted on cross-session memory context in new sessions.
Root Cause:
The
before_prompt_buildhook in memos-local-openclaw-plugin was injecting memories from all historical sessions without distinguishing between current and previous session context. The injected instructions told the agent to "MUST treat these as established knowledge and use them directly," causing the agent to proactively respond to historical context before the user spoke in a new session.Solution Implemented:
currentSessionKeyvariable to track the active session and detect session boundariessessionKeythan current session/new//resetcommand pattern[from previous session]in the injected contextChanges:
apps/memos-local-openclaw/index.ts(lines 1864-2090)apps/memos-local-openclaw/tests/cross-session-memory.test.tsTesting:
The fix correctly handles three scenarios:
Impact:
The agent now correctly treats cross-session memories as background knowledge and waits for the user's explicit instruction before taking action, fixing the unprompted response behavior.
Related Issue (Required): Fixes #1532
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Executor did not report tests.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219 please review this PR.
Reviewer Checklist