Fix hooks to fail gracefully instead of blocking user prompts
Three issues fixed: 1. session-init handler: Worker 500 errors caused `throw`, which hook-command.ts caught and exited with code 2 (blocking error). This blocked the user's prompt entirely with: "Hook error: Error: Session initialization failed: 500" Fix: Log the failure and return SUCCESS so the prompt proceeds. 2. user-message handler: Referenced nonexistent constant HOOK_EXIT_CODES.USER_MESSAGE_ONLY (undefined). Also used console.error() for informational output, which Claude Code may flag as an error. Fix: Use process.stderr.write() and return HOOK_EXIT_CODES.SUCCESS explicitly. 3. Both handlers threw on HTTP errors from the worker, causing exit code 2 (blocking). Memory plugin failures should never prevent users from using Claude Code. All worker HTTP failures now log and return gracefully. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Alex Newman
parent
311d62cc02
commit
67f9d631bd
@@ -43,7 +43,9 @@ export const sessionInitHandler: EventHandler = {
|
||||
});
|
||||
|
||||
if (!initResponse.ok) {
|
||||
throw new Error(`Session initialization failed: ${initResponse.status}`);
|
||||
// Log but don't throw - a worker 500 should not block the user's prompt
|
||||
logger.failure('HOOK', `Session initialization failed: ${initResponse.status}`, { contentSessionId: sessionId, project });
|
||||
return { continue: true, suppressOutput: true, exitCode: HOOK_EXIT_CODES.SUCCESS };
|
||||
}
|
||||
|
||||
const initResult = await initResponse.json() as {
|
||||
@@ -86,7 +88,8 @@ export const sessionInitHandler: EventHandler = {
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`SDK agent start failed: ${response.status}`);
|
||||
// Log but don't throw - SDK agent failure should not block the user's prompt
|
||||
logger.failure('HOOK', `SDK agent start failed: ${response.status}`, { sessionDbId, promptNumber });
|
||||
}
|
||||
} else if (input.platform === 'cursor') {
|
||||
logger.debug('HOOK', 'session-init: Skipping SDK agent init for Cursor platform', { sessionDbId, promptNumber });
|
||||
|
||||
Reference in New Issue
Block a user