From 3d825af587a55bcb0a3220c7987f1148666970ce Mon Sep 17 00:00:00 2001 From: idrojone Date: Sun, 26 Apr 2026 22:05:51 +0200 Subject: [PATCH] fix(lifecycle): implement session end for OpenCode, Gemini CLI, and Codex - Added engramFetch to POST /sessions/{id}/end in OpenCode's session.deleted event - Added explicit mem_session_end instruction to MEMORY_INSTRUCTIONS and memoryProtocolMarkdown Closes #48 --- internal/setup/plugins/opencode/engram.ts | 7 ++++++- internal/setup/setup.go | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/setup/plugins/opencode/engram.ts b/internal/setup/plugins/opencode/engram.ts index 9f4a27b7..9e8b6747 100644 --- a/internal/setup/plugins/opencode/engram.ts +++ b/internal/setup/plugins/opencode/engram.ts @@ -109,7 +109,9 @@ Before ending a session or saying "done" / "listo" / "that's it", you MUST: ## Relevant Files - path/to/file — [what it does or what changed] -This is NOT optional. If you skip this, the next session starts blind. +2. Call \`mem_session_end\` to formally close the session. + +This is NOT optional. If you skip this, the next session starts blind and leaves orphaned sessions. ### AFTER COMPACTION @@ -313,6 +315,9 @@ export const Engram: Plugin = async (ctx) => { const info = (event.properties as any)?.info const sessionId = info?.id if (sessionId) { + // Tell Engram the session ended + await engramFetch(`/sessions/${sessionId}/end`, { method: "POST" }) + toolCounts.delete(sessionId) knownSessions.delete(sessionId) subAgentSessions.delete(sessionId) diff --git a/internal/setup/setup.go b/internal/setup/setup.go index d0a8453f..aa0ab62b 100644 --- a/internal/setup/setup.go +++ b/internal/setup/setup.go @@ -172,7 +172,9 @@ Before ending a session or saying "done" / "listo" / "that's it", you MUST: ## Relevant Files - path/to/file — [what it does or what changed] -This is NOT optional. If you skip this, the next session starts blind. +2. Call mem_session_end to formally close the session. + +This is NOT optional. If you skip this, the next session starts blind and leaves orphaned sessions. ### PASSIVE CAPTURE — automatic learning extraction