fix(opencode): run CLI under a Linux pseudo-TTY so subprocess calls work#283
Open
kazutoshi-ishimori wants to merge 1 commit into
Open
fix(opencode): run CLI under a Linux pseudo-TTY so subprocess calls work#283kazutoshi-ishimori wants to merge 1 commit into
kazutoshi-ishimori wants to merge 1 commit into
Conversation
The `opencode` CLI requires a TTY. When beast mode invokes it via
`subprocess.run` with piped stdout/stderr, it can return exit 0 with empty
output and no generated files, so the pipeline treats a no-op as a successful
run that produced no code.
Wrap the call on Linux with util-linux `script -q -e -c "<cmd>" /dev/null`:
* -q suppresses script's start/done messages,
* -c runs the requested command,
* -e returns the child's exit status — without it `script` can return 0
even when the child command fails, which would re-mask an opencode
failure as success.
The wrapper is gated on `sys.platform == "linux"` because the
`script -q -e -c ... /dev/null` form is util-linux syntax; BSD/macOS `script`
is not compatible with it. On non-Linux platforms, and when `script` is
unavailable, we fall back to direct invocation — the prior behaviour, no
regression.
Command construction is extracted into `_build_opencode_command` and covered
by unit tests (Linux-wraps / no-script-falls-back / non-Linux-no-wrap /
exit-status-preservation / shell-metachar quoting).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
The
opencodeCLI requires a TTY. When beast mode invokes it viasubprocess.runwith piped stdout/stderr, it can return exit 0 with empty output and no generated files. The pipeline then treats this as a successful run that produced no code.This PR wraps the
opencodecall on Linux with util-linuxscriptso the CLI runs under a pseudo-TTY:script -q -e -c "<cmd>" /dev/null-qsuppressesscript's start/done messages-cruns the requested command-ereturns the child's exit status — without itscriptcan return 0 even when the child command fails, which would re-mask anopencodefailure as success (the very behaviour this wrapper exists to fix)Why gate on Linux
The
script -q -e -c ... /dev/nullform is util-linux-specific. BSD/macOSscriptimplementations are not compatible with this argument form, so an unconditionalshutil.which("script")check could break non-Linux platforms rather than help them. The wrapper is therefore gated onsys.platform == "linux". On other platforms, and whenscriptis missing, the bridge falls back to direct invocation — identical to current behaviour, with no regression.Tests
Command construction is extracted into
_build_opencode_commandwith unit tests covering:scriptscriptfalls back to direct invocation-etests/test_opencode_bridge.pypasses (51 tests).Notes
script -qc "exit 7"returns 0, whilescript -q -e -c "exit 7"correctly returns 7.ptymodule, but that's a larger change — happy to follow up if preferred.