fix: Update project name when session already exists in createSDKSession
**Problem:** - Sessions created with empty project names couldn't be updated - INSERT OR IGNORE skipped updates when session already existed - Context-hook couldn't find observations (WHERE project = 'claude-mem') - 364 observations had empty project names **Root Cause:** createSDKSession() used INSERT OR IGNORE for idempotency, but never updated project/prompt fields when session already existed. If SAVE hook created session first (with empty project), NEW hook couldn't fix it. **Solution:** When INSERT is ignored (session exists), UPDATE project and user_prompt if we have non-empty values. This ensures project name gets set even when session was created by SAVE hook or with incomplete data. **Impact:** - New sessions will always have correct project name - Backfilled 364 historical observations with project='claude-mem' - Context injection will now work (finds observations by project) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,7 @@ import { stdin } from 'process';
|
||||
import { SessionStore } from '../services/sqlite/SessionStore.js';
|
||||
import { createHookResponse } from './hook-response.js';
|
||||
import { ensureWorkerRunning, getWorkerPort } from '../shared/worker-utils.js';
|
||||
import { silentDebug } from '../utils/silent-debug.js';
|
||||
|
||||
export interface UserPromptSubmitInput {
|
||||
session_id: string;
|
||||
@@ -55,8 +56,27 @@ async function newHook(input?: UserPromptSubmitInput): Promise<void> {
|
||||
}
|
||||
|
||||
const { session_id, cwd, prompt } = input;
|
||||
|
||||
// Debug: Log what we received
|
||||
silentDebug('[new-hook] Input received', {
|
||||
session_id,
|
||||
cwd,
|
||||
cwd_type: typeof cwd,
|
||||
cwd_length: cwd?.length,
|
||||
has_cwd: !!cwd,
|
||||
prompt_length: prompt?.length
|
||||
});
|
||||
|
||||
const project = path.basename(cwd);
|
||||
|
||||
silentDebug('[new-hook] Project extracted', {
|
||||
project,
|
||||
project_type: typeof project,
|
||||
project_length: project?.length,
|
||||
is_empty: project === '',
|
||||
cwd_was: cwd
|
||||
});
|
||||
|
||||
// Ensure worker is running
|
||||
await ensureWorkerRunning();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user