You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
json.load(sys.stdin) waits for EOF. Kiro IDE runCommand and similar hook runners can leave stdin open while sending no payload, so the hook process blocks before it can emit workflow state.
Tests
pnpm --filter @mindfoldhq/trellis-core build
pnpm --filter @mindfoldhq/trellis typecheck
pnpm --filter @mindfoldhq/trellis lint
pnpm --filter @mindfoldhq/trellis exec vitest run test/regression.test.ts -t "#356|inject-workflow-state.py emits BeforeAgent|silent exit 0 when not a Trellis project"
pnpm --filter @mindfoldhq/trellis exec vitest run test/templates/shared-hooks.test.ts
inject-workflow-state.py replaces its blocking json.load(sys.stdin) call with a new _load_hook_input() helper that reads stdin on a daemon thread with a 0.2 s timeout, returning {} on timeout, error, or invalid JSON. A regression test is added that spawns the hook with an open, empty stdin and asserts it exits cleanly within 1.5 s.
Adds queue and threading imports. Introduces _load_hook_input(), which spawns a daemon thread to call sys.stdin.read(), waits up to 0.2 s on a bounded queue, and returns {} on timeout, exception, empty/whitespace input, or JSON parse failure. main() calls this helper instead of the former direct json.load(sys.stdin).
Regression test for open-stdin hang packages/cli/test/regression.test.ts
Adds spawn to the node:child_process import. Inserts async test [#356] that spawns the hook as a Python subprocess with piped stdio, accumulates output, applies a 1.5 s SIGKILL watchdog, and asserts exit code 0, no timeout, and <workflow-state> in stdout.
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
🐇 A rabbit once sat by a pipe,
Waiting for data that ne'er would arrive.
Now a thread taps its paw — just 0.2 ticks —
Then hops along merrily, returning {}.
No more stuck hooks, no more frozen IDE!
✨ Stdin shall block us no longer, yippee!
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name
Status
Explanation
Resolution
Docstring Coverage
⚠️ Warning
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%.
Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name
Status
Explanation
Description Check
✅ Passed
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
✅ Passed
The title clearly and concisely describes the main change: preventing blocking on empty stdin.
Linked Issues check
✅ Passed
The code and regression test address #356 by handling open, empty stdin without hanging while preserving normal behavior.
Out of Scope Changes check
✅ Passed
The changes are focused on the stdin hang fix and its regression test, with no obvious unrelated additions.
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches📝 Generate docstrings
Create stacked PR
Commit on current branch
🧪 Generate unit tests (beta)
Create PR with unit tests
Commit unit tests in branch fix/issue-356-hook-stdin
Comment @coderabbitai help to get the list of available commands.
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
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
inject-workflow-state.pyso IDE hook runners that leave stdin open do not hangRoot Cause
json.load(sys.stdin)waits for EOF. Kiro IDErunCommandand similar hook runners can leave stdin open while sending no payload, so the hook process blocks before it can emit workflow state.Tests
pnpm --filter @mindfoldhq/trellis-core buildpnpm --filter @mindfoldhq/trellis typecheckpnpm --filter @mindfoldhq/trellis lintpnpm --filter @mindfoldhq/trellis exec vitest run test/regression.test.ts -t "#356|inject-workflow-state.py emits BeforeAgent|silent exit 0 when not a Trellis project"pnpm --filter @mindfoldhq/trellis exec vitest run test/templates/shared-hooks.test.tspython3 -m py_compile packages/cli/src/templates/shared-hooks/inject-workflow-state.pyFixes #356
Summary by CodeRabbit