Consolidated lessons are always labelled `session:unknown` (ExtensionContext has no sessionId)
Summary
Consolidated memory entries are always labelled with the source session:unknown instead of the real session id.
Root cause
src/index.ts (master, line ~438) reads the session id from the extension context:
sessionId = (ctx as any).sessionId ?? (ctx as any).session?.id;
But ExtensionContext exposes neither sessionId nor session — only a read-only sessionManager (@earendil-works/pi-coding-agent, dist/core/extensions/types.d.ts). Both property accesses therefore resolve to undefined, and the label built at line ~739 becomes:
`session:${sessionId ?? "unknown"}` // → "session:unknown"
Verified at runtime with a probe extension on a live ExtensionRunner:
Object.keys(ctx) => [abort, compact, cwd, getContextUsage, getSystemPrompt,
hasPendingMessages, hasUI, isIdle, isProjectTrusted, mode,
model, modelRegistry, scopedModels, sessionManager, shutdown,
signal, thinkingLevel, ui]
"sessionId" in ctx => false
"session" in ctx => false
ctx.sessionManager.getSessionId() => "01a0ecbd-5e63-7057-9091-a91fe6b15f65"
Impact
- Facts (
semantictable) are unaffected — theirsourceis hardcoded toconsolidation. - Lessons are affected:
sourceis stored assession:<id>, so every consolidated lesson is recorded assession:unknown, losing provenance.
Search, injection and thresholds are unaffected; only traceability of where a lesson came from is lost.
Suggested fix
Read the id from the session manager, keeping the existing fallbacks:
sessionId = ctx.sessionManager?.getSessionId?.() ?? (ctx as any).sessionId ?? (ctx as any).session?.id;
getSessionId() is part of the public ReadonlySessionManager surface (Pick<SessionManager, ... | "getSessionId" | ...>), so no extra typing work is needed.
Environment
@samfp/pi-memory1.5.0@earendil-works/pi-coding-agent0.87.0- macOS arm64, Node 25.9.0
Verification
After the change, a real consolidation run writes source = session:<real id> (confirmed end-to-end with an isolated memory DB). Existing rows keep their historical session:unknown value; only new consolidations pick up the fix.