fix: tolerate unknown Claude Code enum values in hook events#109
Open
punk-dev-robot wants to merge 1 commit into
Open
fix: tolerate unknown Claude Code enum values in hook events#109punk-dev-robot wants to merge 1 commit into
punk-dev-robot wants to merge 1 commit into
Conversation
Claude Code hooks intermittently exited with a non-blocking error code
(most visibly for UserPromptSubmit), surfacing an INFO log line in the
transcript.
Root cause: `permission_mode` (part of CommonEventData, present on every
event) is typed as the `PermissionMode` enum, which only modeled four of
the six values Claude Code now sends. `#[serde(default)]` rescues an
absent field but not a present-but-unknown value. The engine evaluates the
tolerant `serde_json::Value` and succeeds, but the typed re-parse used for
response formatting (cupcake-cli/src/main.rs) then fails on values like
"dontAsk"/"auto", `?`-propagates, and the process exits 1. Per the Claude
Code hooks spec, exit 1 is a non-blocking error: the transcript shows a
hook-error notice plus the first stderr line. It also silently discarded
real Block decisions.
Changes:
- Add `#[serde(other)] Unknown` catch-all to the externally-driven event
enums (PermissionMode, CompactTrigger, SessionSource, NotificationType,
SessionEndReason) so deserialization never fails on a newer value; add
the now-documented Auto/DontAsk PermissionMode variants.
- Demote the per-invocation `info!("Processing harness")` to `debug!` so a
genuine error surfaces its real first stderr line, not noise.
- Update the claude_code README permission-mode list.
- Add regression tests: unit parse of dontAsk/unknown modes, and a CLI
test asserting `cupcake eval` exits 0 with valid JSON for an unknown
permission_mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Claude Code hooks intermittently exited non-zero (most visibly
UserPromptSubmit), showing a hook-error notice and silently dropping Block decisions.permission_modeis typed as thePermissionModeenum, but Claude Code now sends values it doesn't model (e.g.dontAsk,auto).#[serde(default)]covers an absent field, not a present-but-unknown one: the engine evaluates the tolerantValuefine, but the typed re-parse for response formatting fails,?-propagates, and exits 1 (a non-blocking hook error per spec).#[serde(other)] Unknownto the externally-driven enums (PermissionMode,CompactTrigger,SessionSource,NotificationType,SessionEndReason); add documentedAuto/DontAsk.info!("Processing harness")todebug!so real errors surface.