fix(jsonrpc): read response before waiting - #58
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a JSON-RPC stdio race where calling Cmd.Wait() too early could close StdoutPipe while the response decoder was still reading, causing nondeterministic failures for fast-exiting providers. The fix ensures the full JSON-RPC response is decoded before waiting, and adds a regression test that reproduces the prior failure mode with a large, valid response.
Changes:
- Reorder process lifecycle in
Provider.callto decodestdoutfully before invokingcmd.Wait(). - Preserve cleanup behavior by still terminating the provider process after reading the response.
- Add a regression test using a helper provider mode that emits a large response and exits immediately.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/adapters/jsonrpc/provider.go | Decodes the JSON-RPC response before cmd.Wait() to avoid StdoutPipe being closed mid-decode. |
| internal/adapters/jsonrpc/provider_test.go | Adds a regression test and helper mode producing a large fast response to validate the race fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
qiz029
marked this pull request as ready for review
August 5, 2026 21:06
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.
What changed
Cmd.Wait.Root cause
Provider.callstartedCmd.Waitin a goroutine before decodingStdoutPipe. Go closes the pipe whenWaitcompletes, so a fast-exiting provider could race the decoder and produceread |0: file already closedeven though it emitted a valid response.Impact
JSON-RPC providers no longer fail nondeterministically when they exit quickly after writing a response. Timeout behavior remains controlled by
exec.CommandContext.Validation
file already closedgo test ./... -count=1go vet ./...golangci-lint fmt --diffscripts/check-production-complexity.shLocal
golangci-lint runwas blocked by a broken local Go toolchain (go1.26.4loading no packages; the cached Go 1.25 toolchain is missingunsafe). GitHub Actions provides the clean Go 1.25 lint result.