Enhance HooksDatabase and WorkerService functionality
- Updated save-hook.js and summary-hook.js to include new database columns for tracking worker ports and prompt numbers. - Implemented migration logic to remove UNIQUE constraints from session_summaries table and added necessary indices. - Modified HooksDatabase methods to return boolean values indicating success or failure of updates. - Changed logging from error to info level in WorkerService for better clarity on session management and initialization.
This commit is contained in:
@@ -305,8 +305,9 @@ export class HooksDatabase {
|
||||
/**
|
||||
* Update SDK session ID (captured from init message)
|
||||
* Only updates if current sdk_session_id is NULL to avoid breaking foreign keys
|
||||
* Returns true if update succeeded, false if skipped
|
||||
*/
|
||||
updateSDKSessionId(id: number, sdkSessionId: string): void {
|
||||
updateSDKSessionId(id: number, sdkSessionId: string): boolean {
|
||||
const stmt = this.db.prepare(`
|
||||
UPDATE sdk_sessions
|
||||
SET sdk_session_id = ?
|
||||
@@ -317,7 +318,10 @@ export class HooksDatabase {
|
||||
|
||||
if (result.changes === 0) {
|
||||
console.error(`[HooksDatabase] Skipped updating sdk_session_id for session ${id} - already set (prevents FOREIGN KEY constraint violation)`);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,14 +79,14 @@ class WorkerService {
|
||||
db.close();
|
||||
|
||||
if (cleanedCount > 0) {
|
||||
console.error(`[WorkerService] Cleaned up ${cleanedCount} orphaned sessions`);
|
||||
console.log(`[WorkerService] Cleaned up ${cleanedCount} orphaned sessions`);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.app.listen(port, '127.0.0.1', () => {
|
||||
console.error(`[WorkerService] Started on http://127.0.0.1:${port}`);
|
||||
console.error(`[WorkerService] PID: ${process.pid}`);
|
||||
console.error(`[WorkerService] Active sessions: ${this.sessions.size}`);
|
||||
console.log(`[WorkerService] Started on http://127.0.0.1:${port}`);
|
||||
console.log(`[WorkerService] PID: ${process.pid}`);
|
||||
console.log(`[WorkerService] Active sessions: ${this.sessions.size}`);
|
||||
|
||||
// Write port to file for hooks to discover
|
||||
const { writeFileSync } = require('fs');
|
||||
@@ -122,7 +122,7 @@ class WorkerService {
|
||||
const sessionDbId = parseInt(req.params.sessionDbId, 10);
|
||||
const { project, userPrompt } = req.body;
|
||||
|
||||
console.error(`[WorkerService] Initializing session ${sessionDbId}`, { project });
|
||||
console.log(`[WorkerService] Initializing session ${sessionDbId}`, { project });
|
||||
|
||||
if (this.sessions.has(sessionDbId)) {
|
||||
res.status(409).json({ error: 'Session already exists' });
|
||||
@@ -178,7 +178,7 @@ class WorkerService {
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(`[WorkerService] Queueing observation for session ${sessionDbId}:`, tool_name);
|
||||
console.log(`[WorkerService] Queueing observation for session ${sessionDbId}:`, tool_name);
|
||||
|
||||
session.pendingMessages.push({
|
||||
type: 'observation',
|
||||
@@ -205,7 +205,7 @@ class WorkerService {
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(`[WorkerService] Requesting summary for session ${sessionDbId}, prompt #${prompt_number}`);
|
||||
console.log(`[WorkerService] Requesting summary for session ${sessionDbId}, prompt #${prompt_number}`);
|
||||
|
||||
session.pendingMessages.push({
|
||||
type: 'summarize',
|
||||
|
||||
Reference in New Issue
Block a user