Skip to content

Surface opencode_session_id in memory retrieval tools #935

Description

@ManushGupta

Symptom

I wanted to find which OpenCode session I worked on a feature in.
codemem remembered the work — memory_get(305) returned the full context. But it only returned session_id: 75, a codemem-internal integer. There was no way to get the actual OpenCode session ID (ses_...) to pull up the transcript.
The mapping does exist in the database. A direct SQLite query against the opencode_sessions junction table resolves it immediately:

SELECT opencode_session_id FROM opencode_sessions WHERE session_id = 75;
-- → ses_251f3820dffedRNBbWdN4ITbUN

But none of the MCP tools perform this JOIN — the data is captured but invisible to consumers.

The gap

Layer Has opencode_session_id? Reference
raw_events table ✅ Captured at ingest schema.ts#L380
opencode_sessions junction table ✅ Maps to codemem session_id schema.ts#L241-L256
memory_items table (31 columns) ❌ Not present schema.ts#L71-L103
metadata_json on memories ❌ Observer doesn't propagate it ingest-pipeline.ts#L700-L730
store.get() / store.search() ❌ No JOIN against junction table store.ts
MCP tools (memory_get, memory_search, memory_pack) ❌ Return integer session_id only mcp-server/index.ts

Proposed solution

  1. Add opencode_session_id as a first-class column on memory_items:
    opencode_session_id: text("opencode_session_id"),
  2. Propagate it during observer extraction in ingest-pipeline.ts:
    const memoryId = store.remember(sessionId, kind, ..., {
      opencode_session_id: sessionContext.opencodeSessionId,
      ...
    });
  3. Include it in MemoryItemResponse and all MCP tool responses so memory_get, memory_search, etc. return it directly.
    This enables tracing any memory back to its source session transcript without manual SQLite queries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions