Skip to content

Bug Fix - IntelliJIdea IDE freezes caused by a stdin/stdout pipe deadlock betwee… - #92

Open
Lycogrypho wants to merge 1 commit into
serialexperimentslainnnn:developfrom
Lycogrypho:develop
Open

Lycogrypho wants to merge 1 commit into
serialexperimentslainnnn:developfrom
Lycogrypho:develop

Conversation

@Lycogrypho

Copy link
Copy Markdown

PROBLEM
During long sessions IntelliJ IDEA froze, sometimes for over an hour, and only recovered when the claude process was restarted. idea.log records 41 UI freezes. All the long ones are blocked in ClaudeProcess.writeLine / FileOutputStream.writeBytes.

ROOT CAUSE
The stdout reader thread wrote auto-approved permission replies to claude's stdin synchronously, while processing claude's output. When the stdin pipe was full, that thread blocked and stopped draining stdout. claude then blocked on its own stdout and stopped reading stdin, so neither side could proceed. The UI thread, sending a periodic usage query, then blocked on the same write lock and froze the IDE. Teardown also closed stdin under that lock, so it could stall behind the stuck write.

CHANGES

  • New controller/process/StdinWriter.kt: writes newline-terminated UTF-8 lines to stdin on a single dedicated thread, preserving order. Write failures are logged and do not stop later lines.
  • controller/process/ClaudeProcess.kt: writeLine queues the line on a bounded single-thread application pool executor and returns immediately; it still returns false when the process is dead. The write lock is removed. Teardown destroys the process before closing stdin, so a write stuck on a full pipe fails instead of stalling the shutdown.
  • New test controller/process/StdinWriterTest.kt: a pipe that stops draining does not block the caller; lines arrive whole and in order; a broken pipe does not stop later lines.
  • No security code was changed. The fix sits below PermissionBroker, which is untouched.
  • Documentation: CLAUDE.md gains the standard header. DIRECTIVES.md gains a "How the plugin is put together" architecture section. AGENTS.md points to DIRECTIVES.md for architecture and adds commands for a single test class, integration tests, a single frontend test file, and running builds and tests through the IDE's run server. CONTRIBUTING.md points to CLAUDE.md and DIRECTIVES.md and drops the link to the missing PROJECTMAP.md.

BEHAVIOUR CHANGE
writeLine now reports that a line was queued, not that it was written. A later pipe failure is logged and handled by the existing process-termination path.

VERIFICATION
Built with JBR 21.0.11 on Windows. StdinWriterTest (3), EdtProcessTeardownContractTest (4), and the NoComments, PackageDependency and FileSize contract tests pass. spotlessCheck and detekt pass. Full JVM suite: 4881 tests, 21 failed, 8 skipped. The same 21 fail on the original code: they depend on a POSIX environment (the bin/fake-claude script, Unix socket permissions and path length, symlinks, path separators). buildPlugin produced build/distributions/claude-code-native-6.0.1.zip, which contains StdinWriter and the updated ClaudeProcess.

OPEN POINTS
Not yet verified end to end in a running IDE. The integration tests that drive a real process cannot run on Windows. Manual check: install the zip and run a long task that previously froze.

…n the plugin and the claude process. Restructure the agent documentation so its cross-references resolve.

PROBLEM
During long sessions IntelliJ IDEA froze, sometimes for over an hour, and only recovered when the claude process was restarted. idea.log records 41 UI freezes. All the long ones are blocked in ClaudeProcess.writeLine / FileOutputStream.writeBytes.

ROOT CAUSE
The stdout reader thread wrote auto-approved permission replies to claude's stdin synchronously, while processing claude's output. When the stdin pipe was full, that thread blocked and stopped draining stdout. claude then blocked on its own stdout and stopped reading stdin, so neither side could proceed. The UI thread, sending a periodic usage query, then blocked on the same write lock and froze the IDE. Teardown also closed stdin under that lock, so it could stall behind the stuck write.

CHANGES
- New controller/process/StdinWriter.kt: writes newline-terminated UTF-8 lines to stdin on a single dedicated thread, preserving order. Write failures are logged and do not stop later lines.
- controller/process/ClaudeProcess.kt: writeLine queues the line on a bounded single-thread application pool executor and returns immediately; it still returns false when the process is dead. The write lock is removed. Teardown destroys the process before closing stdin, so a write stuck on a full pipe fails instead of stalling the shutdown.
- New test controller/process/StdinWriterTest.kt: a pipe that stops draining does not block the caller; lines arrive whole and in order; a broken pipe does not stop later lines.
- No security code was changed. The fix sits below PermissionBroker, which is untouched.
- Documentation: CLAUDE.md gains the standard header. DIRECTIVES.md gains a "How the plugin is put together" architecture section. AGENTS.md points to DIRECTIVES.md for architecture and adds commands for a single test class, integration tests, a single frontend test file, and running builds and tests through the IDE's run server. CONTRIBUTING.md points to CLAUDE.md and DIRECTIVES.md and drops the link to the missing PROJECTMAP.md.

BEHAVIOUR CHANGE
writeLine now reports that a line was queued, not that it was written. A later pipe failure is logged and handled by the existing process-termination path.

VERIFICATION
Built with JBR 21.0.11 on Windows. StdinWriterTest (3), EdtProcessTeardownContractTest (4), and the NoComments, PackageDependency and FileSize contract tests pass. spotlessCheck and detekt pass. Full JVM suite: 4881 tests, 21 failed, 8 skipped. The same 21 fail on the original code: they depend on a POSIX environment (the bin/fake-claude script, Unix socket permissions and path length, symlinks, path separators). buildPlugin produced build/distributions/claude-code-native-6.0.1.zip, which contains StdinWriter and the updated ClaudeProcess.

OPEN POINTS
Not yet verified end to end in a running IDE. The integration tests that drive a real process cannot run on Windows. Manual check: install the zip and run a long task that previously froze.

This branch has not been deployed

No deployments
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.

1 participant