Skip to content

Conversation

@ltawfik
Copy link
Collaborator

@ltawfik ltawfik commented Jul 1, 2025

Summary

Fixes CLIJSONDecodeError when Claude Code CLI returns large JSON messages that exceed asyncio's default 64KB stream buffer limit.

Problem

When JSON messages are larger than the stream buffer, they arrive split across multiple reads. The previous implementation attempted to parse each fragment immediately, resulting in JSONDecodeError.

Solution

  • Add buffering to accumulate incomplete JSON messages
  • Continue accumulating until a complete JSON object can be parsed
  • Implement 1MB maximum buffer size to prevent unbounded growth
  • Clear buffer after successful parse or when limit exceeded

Testing

Added comprehensive test coverage:

  • Split JSON across multiple reads
  • Large minified JSON (simulating reported issue)
  • Buffer size limit enforcement
  • Mixed complete and partial messages

🤖 Generated with Claude Code

ltawfik and others added 3 commits June 30, 2025 21:55
Adds buffering to accumulate incomplete JSON messages that are split
across multiple stream reads due to asyncio's 64KB default buffer limit.

- Implement 1MB buffer to accumulate partial JSON
- Clear buffer on successful parse or size limit exceeded
- Add comprehensive tests for split JSON scenarios

Fixes CLIJSONDecodeError when reading large minified JSON files.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
The CLIJSONDecodeError constructor expects an Exception as the second
argument, not None. Changed to pass a ValueError with details about
the buffer size limit being exceeded.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Removed redundant comments that simply restate what the code is doing.
Kept only comments that provide valuable context or explain complex behavior.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
igorkofman
igorkofman previously approved these changes Jul 1, 2025
kushal-thakkar
kushal-thakkar previously approved these changes Jul 1, 2025
@ltawfik ltawfik dismissed stale reviews from kushal-thakkar and igorkofman via 8233533 July 1, 2025 06:00
@ltawfik ltawfik merged commit 4af210e into main Jul 1, 2025
7 checks passed
@ebetica
Copy link

ebetica commented Jul 1, 2025

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants