fix: generate synthetic memorySessionId for stateless providers (PR #615)

Gemini and OpenRouter are stateless APIs that never return session IDs.
Without synthetic IDs, PR #693's defensive memorySessionId checks throw
errors on every observation processing call for these providers.

Generates provider-prefixed IDs (gemini-/openrouter-{contentSessionId}-
{timestamp}) before the first API call, persisted to the database via
updateMemorySessionId(). Applied from PR #615 (closed due to staleness).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2026-02-06 02:04:49 -05:00
parent e36efff00d
commit 711f5455df
3 changed files with 17 additions and 1 deletions
+8
View File
@@ -134,6 +134,14 @@ export class GeminiAgent {
throw new Error('Gemini API key not configured. Set CLAUDE_MEM_GEMINI_API_KEY in settings or GEMINI_API_KEY environment variable.');
}
// Generate synthetic memorySessionId (Gemini is stateless, doesn't return session IDs)
if (!session.memorySessionId) {
const syntheticMemorySessionId = `gemini-${session.contentSessionId}-${Date.now()}`;
session.memorySessionId = syntheticMemorySessionId;
this.dbManager.getSessionStore().updateMemorySessionId(session.sessionDbId, syntheticMemorySessionId);
logger.info('SESSION', `MEMORY_ID_GENERATED | sessionDbId=${session.sessionDbId} | provider=Gemini`);
}
// Load active mode
const mode = ModeManager.getInstance().getActiveMode();
+8
View File
@@ -92,6 +92,14 @@ export class OpenRouterAgent {
throw new Error('OpenRouter API key not configured. Set CLAUDE_MEM_OPENROUTER_API_KEY in settings or OPENROUTER_API_KEY environment variable.');
}
// Generate synthetic memorySessionId (OpenRouter is stateless, doesn't return session IDs)
if (!session.memorySessionId) {
const syntheticMemorySessionId = `openrouter-${session.contentSessionId}-${Date.now()}`;
session.memorySessionId = syntheticMemorySessionId;
this.dbManager.getSessionStore().updateMemorySessionId(session.sessionDbId, syntheticMemorySessionId);
logger.info('SESSION', `MEMORY_ID_GENERATED | sessionDbId=${session.sessionDbId} | provider=OpenRouter`);
}
// Load active mode
const mode = ModeManager.getInstance().getActiveMode();