Fix critical session persistence bug in new-hook (#224)
* Fix critical session persistence bug in new-hook Restores the second POST call to /sessions/:sessionDbId/init that was incorrectly removed as "duplicate" in the hooks refactor. The two POST calls serve different purposes: - POST /api/sessions/init: Creates DB session, saves prompt (no SDK agent) - POST /sessions/:sessionDbId/init: Starts the SDK agent session Without the second call, the SDK agent never started, causing: - First prompts saved to DB but never processed - Subsequent prompts queued but no agent running to consume them - Each new prompt creating orphaned sessions instead of continuing This fix restores proper session continuation across multiple prompts. Fixes conversation fragmentation reported in production. * updated agent-sdk * Skip meta-observations for session-memory file operations Added a check to skip meta-observations when file operations (Edit, Write, Read, NotebookEdit) are performed on session-memory files. If the file path includes 'session-memory', a debug log is generated and the response indicates that the observation was skipped.
This commit is contained in:
@@ -71,6 +71,27 @@ async function newHook(input?: UserPromptSubmitInput): Promise<void> {
|
||||
handleWorkerError(error);
|
||||
}
|
||||
|
||||
// Strip leading slash from commands for memory agent
|
||||
// /review 101 → review 101 (more semantic for observations)
|
||||
const cleanedPrompt = prompt.startsWith('/') ? prompt.substring(1) : prompt;
|
||||
|
||||
try {
|
||||
// Initialize SDK agent session via HTTP (starts the agent!)
|
||||
const response = await fetch(`http://127.0.0.1:${port}/sessions/${sessionDbId}/init`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ userPrompt: cleanedPrompt, promptNumber }),
|
||||
signal: AbortSignal.timeout(5000)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Failed to start SDK agent: ${response.status} ${errorText}`);
|
||||
}
|
||||
} catch (error: any) {
|
||||
handleWorkerError(error);
|
||||
}
|
||||
|
||||
console.log(createHookResponse('UserPromptSubmit', true));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user