Refactor session ID references from sdk_session_id to memory_session_id across multiple services and database queries
- Updated SQL queries in cleanup-duplicates.ts and context-generator.ts to use memory_session_id. - Modified interfaces in context-generator.ts to reflect the new session ID naming. - Implemented a repair migration in SessionStore.ts to rename columns in existing tables. - Adjusted FormattingService.ts and SDKAgent.ts to utilize memory_session_id for session handling. - Ensured SearchManager.ts retrieves summaries and observations using the updated memory_session_id.
This commit is contained in:
@@ -74,7 +74,7 @@ Tips:
|
||||
const id = `#S${session.id}`;
|
||||
const time = this.formatTime(session.created_at_epoch);
|
||||
const icon = '🎯';
|
||||
const title = session.request || `Session ${session.sdk_session_id?.substring(0, 8) || 'unknown'}`;
|
||||
const title = session.request || `Session ${session.memory_session_id?.substring(0, 8) || 'unknown'}`;
|
||||
|
||||
return `| ${id} | ${time} | ${icon} | ${title} | - | - |`;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ Tips:
|
||||
const id = `#S${session.id}`;
|
||||
const time = this.formatTime(session.created_at_epoch);
|
||||
const icon = '🎯';
|
||||
const title = session.request || `Session ${session.sdk_session_id?.substring(0, 8) || 'unknown'}`;
|
||||
const title = session.request || `Session ${session.memory_session_id?.substring(0, 8) || 'unknown'}`;
|
||||
|
||||
// Use ditto mark if same time as previous row
|
||||
const timeDisplay = time === lastTime ? '″' : time;
|
||||
|
||||
@@ -64,22 +64,29 @@ export class SDKAgent {
|
||||
// Create message generator (event-driven)
|
||||
const messageGenerator = this.createMessageGenerator(session);
|
||||
|
||||
// CRITICAL: Only resume if memorySessionId is a REAL captured SDK session ID,
|
||||
// not the placeholder (which equals contentSessionId). The placeholder is set
|
||||
// for FK purposes but would cause the bug where we try to resume the USER's session!
|
||||
const hasRealMemorySessionId = session.memorySessionId &&
|
||||
session.memorySessionId !== session.contentSessionId;
|
||||
|
||||
logger.info('SDK', 'Starting SDK query', {
|
||||
sessionDbId: session.sessionDbId,
|
||||
contentSessionId: session.contentSessionId,
|
||||
memorySessionId: session.memorySessionId,
|
||||
resume_parameter: session.memorySessionId || '(none - fresh start)',
|
||||
hasRealMemorySessionId,
|
||||
resume_parameter: hasRealMemorySessionId ? session.memorySessionId : '(none - fresh start)',
|
||||
lastPromptNumber: session.lastPromptNumber
|
||||
});
|
||||
|
||||
// Run Agent SDK query loop
|
||||
// Use memorySessionId for resume (captured from previous SDK response) if available
|
||||
// Only resume if we have a REAL captured memory session ID (not the placeholder)
|
||||
const queryResult = query({
|
||||
prompt: messageGenerator,
|
||||
options: {
|
||||
model: modelId,
|
||||
// Only resume if we have a captured memory session ID from previous SDK interaction
|
||||
...(session.memorySessionId && { resume: session.memorySessionId }),
|
||||
// Only resume if memorySessionId differs from contentSessionId (meaning it was captured)
|
||||
...(hasRealMemorySessionId && { resume: session.memorySessionId }),
|
||||
disallowedTools,
|
||||
abortController: session.abortController,
|
||||
pathToClaudeCodeExecutable: claudePath
|
||||
|
||||
@@ -1376,13 +1376,13 @@ export class SearchManager {
|
||||
lines.push('');
|
||||
|
||||
for (const session of sessions) {
|
||||
if (!session.sdk_session_id) continue;
|
||||
if (!session.memory_session_id) continue;
|
||||
|
||||
lines.push('---');
|
||||
lines.push('');
|
||||
|
||||
if (session.has_summary) {
|
||||
const summary = this.sessionStore.getSummaryForSession(session.sdk_session_id);
|
||||
const summary = this.sessionStore.getSummaryForSession(session.memory_session_id);
|
||||
if (summary) {
|
||||
const promptLabel = summary.prompt_number ? ` (Prompt #${summary.prompt_number})` : '';
|
||||
lines.push(`**Summary${promptLabel}**`);
|
||||
@@ -1432,7 +1432,7 @@ export class SearchManager {
|
||||
lines.push(`**Request:** ${session.user_prompt}`);
|
||||
}
|
||||
|
||||
const observations = this.sessionStore.getObservationsForSession(session.sdk_session_id);
|
||||
const observations = this.sessionStore.getObservationsForSession(session.memory_session_id);
|
||||
if (observations.length > 0) {
|
||||
lines.push('');
|
||||
lines.push(`**Observations (${observations.length}):**`);
|
||||
|
||||
Reference in New Issue
Block a user