Fix #2327: memmy-agent 第二条消息固定报错 session not found - #2328
Closed
Memtensor-AI wants to merge 1 commit into
Closed
Conversation
…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
Collaborator
Author
🤖 Open Code ReviewTarget: PR #2328 ✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). Generated by cloud-assistant via Open Code Review. |
Collaborator
Author
✅ Automated Test Results: PASSEDAll tests passed (52/52 executed). memos_local_plugin/unit: 52/52. Duration: 12s [advisory, non-gating] AI-generated tests on branch test/auto-gen-1d452ba963e2f9cb-20260902164416: 20/21 passed — these do NOT affect the PR verdict; review the branch manually. Branch: |
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
Fixed #2327: memmy-agent second-message "session not found" error.
Root cause:
apps/memos-local-plugin/core/pipeline/memory-core.ts::closeSessionthrewMemosError("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.
How Has This Been Tested?
Automated tests are pending.
Checklist
@whipser030, @hijzy please review this PR.
Reviewer Checklist