Conversation
…l fallback The tool server inside Docker sandbox containers was failing to start reliably, producing "Tool server health check failed after 3s, tools may not work" warnings for every container. This was caused by port collisions (timestamp-based port derivation with --network=host), insufficient health check timeout, no retry mechanism, and no fallback when the server was unavailable. Port allocation: Replaced timestamp-based port derivation (which suffered from u16 truncation and TOCTOU races) with a global AtomicU16 counter that guarantees unique ports across all concurrent containers. Each sandbox atomically increments the counter, wrapping from 60000 back to 10000. Tool server Python code (tool_server.rs): Added HTTPServer.allow_reuse_address = True to reduce EADDRINUSE errors, and wrapped server creation in try/except to log port binding failures before exiting cleanly. Health check robustness (docker_sandbox.rs): Increased health check from 6x500ms (3s) to 12x500ms (6s). Added full retry loop (up to 2 attempts) that kills stale processes, re-writes the script, and restarts on failure. Verifies script was written correctly by checking file size. Changed start_tool_server() to return bool indicating success, exposed via has_tool_server() for callers. Error handling improvements (docker_sandbox.rs): git install failure now aborts sandbox creation (was a silent warning). git checkout failure now aborts sandbox creation instead of silently continuing on HEAD, which would produce invalid test results. Shell-based tool fallback (test_generator.rs): When the tool server is unavailable or returns connection errors, tools (read_file, list_dir, grep_files, search_files, apply_patch) now fall back to equivalent shell commands. Extracted parse_tool_response() helper for cleaner code. This ensures the agent loop continues even if the tool server never starts.
…ction Add validate_file_path() checks for file/directory path arguments and sanitize_shell_arg() escaping for pattern/glob arguments in the shell_fallback() function. Previously, LLM-provided values containing single quotes could break out of shell quoting and execute arbitrary commands inside the Docker container.
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
Fix the Docker sandbox tool server failing to start in all containers during concurrent pipeline execution, eliminating the pervasive "Tool server health check failed after 3s, tools may not work" warnings.
Changes
Port Allocation (
docker_sandbox.rs)AtomicU16counter (NEXT_PORT) that guarantees unique ports across all concurrent containersas u16truncation bug and TOCTOU race conditions when multiple sandboxes start simultaneously under--network=hostTool Server Robustness (
docker_sandbox.rs,tool_server.rs)HTTPServer.allow_reuse_address = Truein the embedded Python server to reduceAddress already in useerrorsHTTPServer()creation in try/except to catch and logOSErroron port bind failurestart_tool_server()to returnboolindicating success, tracked viatool_server_okfieldShell-Based Tool Fallback (
test_generator.rs)shell_fallback()function implementing all 5 tools (read_file,list_dir,grep_files,search_files,apply_patch) via direct shell commandsparse_tool_response()into a standalone function for cleaner code organizationError Handling Improvements (
docker_sandbox.rs)git install failedfrom WARN-and-continue toanyhow::bail!— a sandbox without git is unusablecheckout failedfrom WARN-and-continue toanyhow::bail!— running tests against the wrong commit produces invalid resultsTests
test_allocate_port_returns_valid_rangeandtest_allocate_port_sequential_uniqueunit tests for the new port allocator