Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(opencode-plugin): derive session id from parentID only on session events (#6243)
Vladimir Babin66f528de3ce2
diff --git a/examples/opencode-plugin/lib/memory-session.mjs b/examples/opencode-plugin/lib/memory-session.mjsindex 69f8594c4..05b318225 100644--- a/examples/opencode-plugin/lib/memory-session.mjs+++ b/examples/opencode-plugin/lib/memory-session.mjs@@ -350,7 +350,10 @@ export function createMemorySessionManager({ config, pluginRoot }) {}function createSessionState(opencodeSessionId, event = {}) {- const parentId = event?.properties?.info?.parentID ?? event?.properties?.parentID ?? event?.parentID ?? ""+ const isSessionEvent = typeof event?.type === "string" && event.type.startsWith("session.")+ const parentId = isSessionEvent+ ? (event?.properties?.info?.parentID ?? event?.properties?.parentID ?? event?.parentID ?? "")+ : ""const ovSessionId = parentId? deriveHarnessSessionId("oc-", parentId, `subagent-${opencodeSessionId}`): deriveHarnessSessionId("oc-", opencodeSessionId)diff --git a/examples/opencode-plugin/tests/memory-session.test.mjs b/examples/opencode-plugin/tests/memory-session.test.mjsindex d71a04f48..1f32f296e 100644--- a/examples/opencode-plugin/tests/memory-session.test.mjs+++ b/examples/opencode-plugin/tests/memory-session.test.mjs@@ -167,6 +167,46 @@ test("autoCapture=false skips lifecycle commits but preserves explicit commits",})})+test("a session first seen via message.updated keeps its own session id (#6222)", async () => {+ await withCaptureServer(async ({ endpoint, requests }) => {+ await withTempDir("ov-oc-session-", async (dir) => {+ const manager = createMemorySessionManager({ config: baseConfig(endpoint), pluginRoot: dir })++ await manager.init()+ await manager.handleEvent({+ type: "message.updated",+ properties: {+ info: {+ id: "msg-first",+ sessionID: "oc-child",+ parentID: "msg-parent",+ role: "user",+ },+ },+ })+ await manager.handleEvent({+ type: "message.part.updated",+ properties: {+ part: {+ id: "part-first",+ messageID: "msg-first",+ sessionID: "oc-child",+ type: "text",+ text: "A message event must not derive a session id from the parent message id.",+ },+ },+ })++ await manager.handleEvent({ type: "session.idle", sessionID: "oc-child" })++ const addMessage = requests.find((request) => request.url?.endsWith("/messages/batch"))+ assert.ok(addMessage, "message.updated should flush the captured message")+ assert.equal(addMessage.url, "/api/v1/sessions/oc-oc-child/messages/batch")+ await manager.flushAll({ commit: false })+ })+ })+})+test("session.idle event flushes pending OpenCode capture", async () => {await withCaptureServer(async ({ endpoint, requests }) => {await withTempDir("ov-oc-session-", async (dir) => {