From 42adfe29c87cff295f139daa217f6299017fc364 Mon Sep 17 00:00:00 2001 From: Albert Hui Date: Mon, 16 Feb 2026 13:25:55 +0800 Subject: [PATCH] fix: gracefully handle missing input fields in hook handlers (#1098) The summarize (Stop) and observation (PostToolUse) handlers throw blocking errors (exit code 2) when optional input fields like transcriptPath, toolName, or cwd are missing. This causes visible hook errors on every session stop and after some tool uses. Replace throws with graceful returns matching the existing pattern used for worker-unavailable checks. Fixes #1097 Co-authored-by: Claude Opus 4.6 --- src/cli/handlers/observation.ts | 3 ++- src/cli/handlers/summarize.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cli/handlers/observation.ts b/src/cli/handlers/observation.ts index b498976f..bee81bac 100644 --- a/src/cli/handlers/observation.ts +++ b/src/cli/handlers/observation.ts @@ -24,7 +24,8 @@ export const observationHandler: EventHandler = { const { sessionId, cwd, toolName, toolInput, toolResponse } = input; if (!toolName) { - throw new Error('observationHandler requires toolName'); + // No tool name provided - skip observation gracefully + return { continue: true, suppressOutput: true, exitCode: HOOK_EXIT_CODES.SUCCESS }; } const port = getWorkerPort(); diff --git a/src/cli/handlers/summarize.ts b/src/cli/handlers/summarize.ts index bd0756ae..19cd46d9 100644 --- a/src/cli/handlers/summarize.ts +++ b/src/cli/handlers/summarize.ts @@ -29,7 +29,9 @@ export const summarizeHandler: EventHandler = { // Validate required fields before processing if (!transcriptPath) { - throw new Error(`Missing transcriptPath in Stop hook input for session ${sessionId}`); + // No transcript available - skip summary gracefully (not an error) + logger.debug('HOOK', `No transcriptPath in Stop hook input for session ${sessionId} - skipping summary`); + return { continue: true, suppressOutput: true, exitCode: HOOK_EXIT_CODES.SUCCESS }; } // Extract last assistant message from transcript (the work Claude did)