Fix validate_tool hang: pass stdin=DEVNULL to the validation subprocess#218
Merged
lilly-luo merged 3 commits intoJul 17, 2026
Merged
Conversation
`validate_tool` runs each tool's smoke test (e.g. `pi --print "say hi in 5 words or less"`) via `subprocess.run(..., timeout=60)` without setting `stdin`, so the child inherits ucode's own stdin. In print/headless mode some agent CLIs (pi among them) still open stdin and block waiting for input/EOF. When ucode is launched from a non-interactive parent whose stdin is an open pipe with no EOF — e.g. an agent harness spawning `ucode <tool>` as a subprocess — the validation command never sees EOF, blocks for the full 60s, and `validate_tool` returns `(False, "timed out")`. The caller (`_auto_configure_tool` / configure) then reverts the config and aborts with "<tool> validation failed — config reverted", even though the tool is correctly configured and the gateway is reachable. The validation smoke test is one-shot and never needs interactive input, so pass `stdin=subprocess.DEVNULL`. This is benign for every tool (an interactive prompt in a validation run would itself be a bug) and makes validation robust regardless of how ucode was launched. Verified on a managed sandbox: `pi --print "say hi"` returns instantly with `stdin=DEVNULL` but hangs to the timeout when it inherits an open stdin pipe. Signed-off-by: Edwin He <edwin.he@databricks.com>
Edwinhe03
marked this pull request as draft
July 16, 2026 19:32
Edwinhe03
marked this pull request as ready for review
July 16, 2026 21:17
Edwinhe03
marked this pull request as draft
July 16, 2026 21:30
lilly-luo
reviewed
Jul 17, 2026
lilly-luo
previously approved these changes
Jul 17, 2026
Per review: the kwarg is self-explanatory; drop the comment block.
Edwinhe03
marked this pull request as ready for review
July 17, 2026 18:38
lilly-luo
approved these changes
Jul 17, 2026
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
validate_toolruns each tool's smoke test (pi --print …,codex exec …) viasubprocess.run(..., timeout=60)without settingstdin, so the child inherits ucode's stdin. pi and codex open stdin in print/exec mode and block on it. When ucode is launched from a non-interactive parent whose stdin is an open pipe with no EOF (e.g. an agent harness spawningucode <tool>), validation hangs the full 60s and returns a spurioustimed out→<tool> validation failed — config reverted, even though the tool is configured correctly.Fix
Pass
stdin=subprocess.DEVNULL— the smoke test is one-shot and never needs input. Benign for every tool.Verified
Open-stdin-pipe condition, before (
main) vs after:validate_tool)timed out, 60svalidate_tool)timed out, 60spi --printon sandboxcodex execon sandboxAdded
TestValidateTool(assertsstdin=DEVNULL;TimeoutExpired→timed out). Full suite: 875 passed, ruff clean.