Repository navigation
Fix: read hook payloads over 1 MiB instead of dropping them - #190
Merged
Merged
Conversation
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.
Fixes #154
The hook read at most 1 MiB of stdin. Anything longer was cut off in the middle of a JSON string, failed to parse, and the whole event was dropped. Piping a 1.1 MB
UserPromptSubmitpayload intotrodden hook claude-codeprinted nothing and loggedparse the hook payload: EOF while parsing a string at line 1 column 1048576. The same happened to tool payloads from agents learned through hooks: a CursorpostToolUseforcargo testwith about 1.5 MB of output never reached the session journal, so if that run was the passing check the task looked unverified.The hook now reads the whole payload. A cap only turns a big payload into a lost one, and the payload comes from the agent on the same machine, so there is nothing to defend against. Reading to the end also drains stdin, so the agent never blocks on a full pipe. I considered a streaming parser that skips the large fields, but every harness parses its own payload shape, and the extra memory for a few megabytes of JSON held for the length of one hook call does not justify that complexity. The read moves into a small
read_payloadmethod that takes any reader, so it can be tested without a real stdin.To test it, I built the binary with a scratch
TRODDEN_HOMEand piped in a 1.1 MB Claude Code prompt and a 1.5 MB Cursor shell payload. Before the change both logged the EOF error above and the Cursor journal was never written. After it, the error log stays empty and the Cursor run is journaled as a succeededcargo test. A new unit test reads a 3 MiB prompt payload throughread_payloadand checks it arrives whole and parses into a prompt event. It fails with the old cap in place.