Skip to content

Fix #2327: memmy-agent 第二条消息固定报错 session not found - #2572

Open
syzsunshine219 wants to merge 1 commit into
MemTensor:mainfrom
Memtensor-AI:bugfix/autodev-2327-20260902070028337
Open

syzsunshine219 wants to merge 1 commit into
MemTensor:mainfrom
Memtensor-AI:bugfix/autodev-2327-20260902070028337

Conversation

@syzsunshine219

@syzsunshine219 syzsunshine219 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Restores the change proposed in #2328 for review against main after its former base branch, dev-v2.0.33, was deleted. The source commits and authors are preserved.

Source head: 3cb77e5ccb12af9c3d0ccb5c2d0d21ae9a10f011

This PR is open for review. Review and CI against the current base are pending; validation claims in the original description below refer to the earlier snapshot. The original discussion and evidence remain in #2328.


Original change description

Description

Fixed #2327: memmy-agent second-message "session not found" error.

Root cause: apps/memos-local-plugin/core/pipeline/memory-core.ts::closeSession threw MemosError("session_not_found") when the session was no longer in the orchestrator's in-memory live map. After the first message, the adapter's on_session_end hook calls session.close which evicts the session from the live map. Any subsequent duplicate close (lifecycle race, adapter retry, memmy-agent bridge re-firing) hit the null branch and threw, surfacing to the user on the second message.

Fix: Made closeSession idempotent — unknown session ids are a silent no-op with a debug log, matching the existing semantics of closeEpisode/discardEmptyEpisode. Added 4 regression tests in tests/unit/pipeline/regression-2327-second-message.test.ts. All 176 session + pipeline unit tests pass.

Changed files: core/pipeline/memory-core.ts (fix), core/pipeline/README.md + ALGORITHMS.md (doc update), tests/unit/pipeline/regression-2327-second-message.test.ts (new regression tests).

Related Issue (Required): Fixes #2327

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Automated tests are pending.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@whipser030, @hijzy please review this PR.

Reviewer Checklist

…on_not_found (MemTensor#2327)

When the host fires session.close (e.g. /new, adapter lifecycle end) and
then immediately starts a new turn, closeSession could be called on a session
id that is no longer in the orchestrator's live Map. Previously this threw a
hard MemosError('session_not_found') that surfaced to the user as an error
on the second message.

Make closeSession idempotent: if the session is not found, log a debug
message and return without error. The turnStartApiLogBySession entry is
still cleaned up. This mirrors the existing behaviour of closeEpisode and
discardEmptyEpisode, which already handle the not-found case as a no-op.

Update README.md and ALGORITHMS.md to document the new semantics.

Add regression test (tests/unit/pipeline/regression-2327-second-message.test.ts):
- closeSession on already-closed session does not throw
- openEpisode succeeds on second message after closeSession
- openEpisode succeeds when adapter skips re-openSession (defensive path)
- onTurnStart succeeds on second message after closeSession (ensureSession reopens)

Fixes MemTensor#2327
@syzsunshine219
syzsunshine219 marked this pull request as ready for review November 9, 2026 15:47
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.

memmy-agent 第二条消息固定报错 session not found

1 participant