fix: Refresh in-memory session project when updated in database
**Problem:** - Summaries created with empty project names even after database fix - 13 summaries had empty project, couldn't appear in context-hook - In-memory sessions cached stale empty project value **Root Cause:** SessionManager caches ActiveSession objects in memory. When reusing an existing session, it never refreshed the project field from the database. Even though createSDKSession() now updates the DB with the correct project, the in-memory session.project remained empty, causing summaries to be stored with empty project. **Flow:** 1. Session created with empty project (cached in memory) 2. new-hook UPDATE fixes project in database 3. SessionManager reuses cached session (stale project="") 4. Summary stored with session.project (empty) 5. Context-hook can't find summary (WHERE project = 'claude-mem') **Solution:** When SessionManager.initializeSession() reuses an existing session, refresh the project field from the database. This ensures summaries and observations always use the latest project value. **Impact:** - Future summaries will have correct project name - Backfilled 13 historical summaries with project='claude-mem' - Context injection will now show recent summaries - Both observations AND summaries fixed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,19 @@ export class SessionManager {
|
||||
// Check if already active
|
||||
let session = this.sessions.get(sessionDbId);
|
||||
if (session) {
|
||||
// Refresh project from database in case it was updated by new-hook
|
||||
// This fixes the bug where sessions created with empty project get updated
|
||||
// in the database but the in-memory session still has the stale empty value
|
||||
const dbSession = this.dbManager.getSessionById(sessionDbId);
|
||||
if (dbSession.project && dbSession.project !== session.project) {
|
||||
silentDebug('[SessionManager] Updating project from database', {
|
||||
sessionDbId,
|
||||
oldProject: session.project,
|
||||
newProject: dbSession.project
|
||||
});
|
||||
session.project = dbSession.project;
|
||||
}
|
||||
|
||||
// Update userPrompt for continuation prompts
|
||||
if (currentUserPrompt) {
|
||||
silentDebug('[SessionManager] Updating userPrompt for continuation', {
|
||||
|
||||
Reference in New Issue
Block a user