fix: Remove all session validation to prevent continuation errors after /exit

Root cause: Hooks provide session_id as the source of truth. We were adding
unnecessary validation (checking if sessions exist, checking status, etc.)
which caused 409 conflicts when continuing sessions after /exit.

Changes:
1. worker-service.ts: Removed 409 "Session already exists" check in handleInit
2. SessionStore.ts: Made createSDKSession idempotent using INSERT OR IGNORE
3. new-hook.ts: Simplified to just call createSDKSession - no findActiveSDKSession,
   no reactivateSession logic, no status management
4. save-hook.ts: Removed session validation, use fixed port instead of session.worker_port
5. summary-hook.ts: Removed session validation, use fixed port instead of session.worker_port

Philosophy: Hooks manage lifecycle, we just save data with whatever session_id
they give us. No validation, no status checks, no guessing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2025-10-21 21:44:58 -04:00
parent e073c0b75f
commit c27f07023c
17 changed files with 3706 additions and 170 deletions
+11 -20
View File
@@ -27,31 +27,22 @@ export async function summaryHook(input?: StopInput): Promise<void> {
}
const db = new SessionStore();
const session = db.findActiveSDKSession(session_id);
if (!session) {
db.close();
console.log(createHookResponse('Stop', true));
return;
}
if (!session.worker_port) {
db.close();
logger.error('HOOK', 'No worker port for session', { sessionId: session.id });
throw new Error('No worker port for session - session may not be properly initialized');
}
// Get current prompt number
const promptNumber = db.getPromptCounter(session.id);
// Get or create session - no validation, just use the session_id from hook
const sessionDbId = db.createSDKSession(session_id, '', '');
const promptNumber = db.getPromptCounter(sessionDbId);
db.close();
// Use fixed worker port - no session.worker_port validation needed
const FIXED_PORT = parseInt(process.env.CLAUDE_MEM_WORKER_PORT || '37777', 10);
logger.dataIn('HOOK', 'Stop: Requesting summary', {
sessionId: session.id,
workerPort: session.worker_port,
sessionId: sessionDbId,
workerPort: FIXED_PORT,
promptNumber
});
const response = await fetch(`http://127.0.0.1:${session.worker_port}/sessions/${session.id}/summarize`, {
const response = await fetch(`http://127.0.0.1:${FIXED_PORT}/sessions/${sessionDbId}/summarize`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt_number: promptNumber }),
@@ -61,12 +52,12 @@ export async function summaryHook(input?: StopInput): Promise<void> {
if (!response.ok) {
const errorText = await response.text();
logger.failure('HOOK', 'Failed to generate summary', {
sessionId: session.id,
sessionId: sessionDbId,
status: response.status
}, errorText);
throw new Error(`Failed to request summary from worker: ${response.status} ${errorText}`);
}
logger.debug('HOOK', 'Summary request sent successfully', { sessionId: session.id });
logger.debug('HOOK', 'Summary request sent successfully', { sessionId: sessionDbId });
console.log(createHookResponse('Stop', true));
}