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:
File diff suppressed because one or more lines are too long
@@ -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.');
|
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
|
// Load active mode
|
||||||
const mode = ModeManager.getInstance().getActiveMode();
|
const mode = ModeManager.getInstance().getActiveMode();
|
||||||
|
|
||||||
|
|||||||
@@ -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.');
|
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
|
// Load active mode
|
||||||
const mode = ModeManager.getInstance().getActiveMode();
|
const mode = ModeManager.getInstance().getActiveMode();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user