Skip to content

⚡ Bolt: Parallelize and optimize unit test gate - #477

Open
heidi-dang wants to merge 1 commit into
feat/bootstrap-scaffoldfrom
bolt-parallel-unit-test-gate-13153362908866744744
Open

⚡ Bolt: Parallelize and optimize unit test gate#477
heidi-dang wants to merge 1 commit into
feat/bootstrap-scaffoldfrom
bolt-parallel-unit-test-gate-13153362908866744744

Conversation

@heidi-dang

Copy link
Copy Markdown
Owner

💡 What:
Parallelized sample testing in scripts/03_unit_test_gate.py using ThreadPoolExecutor and optimized regex operations by pre-compiling patterns and using non-capturing groups where appropriate. Fixed robustness issues in save_jsonl and test_python_code. Also fixed a NameError in heidi_engine/telemetry.py.

🎯 Why:
Unit test execution was sequential and slow, spending significant time waiting for subprocesses. Robustness fixes prevent FileNotFoundError on relative paths and IndentationError in test wrappers when injecting code blocks.

📊 Impact:
Reduced execution time for 50 samples from ~1.5s to ~0.7s (~2.1x speedup). This optimization is expected to scale linearly with the number of CPU cores for larger datasets.

🔬 Measurement:
Verified by running a benchmark with 50 samples before and after optimization using time python3 scripts/03_unit_test_gate.py. Correctness verified by ensuring injected code blocks execute successfully and pass/fail as expected. All system tests passed.


PR created automatically by Jules for task 13153362908866744744 started by @heidi-dang

This commit parallelizes the unit test gate using ThreadPoolExecutor,
providing a ~2.1x speedup on a 4-core system. It also optimizes regex
operations and fixes robustness bugs in path handling and code injection.

Key changes:
- Parallelized sample testing in 03_unit_test_gate.py.
- Pre-compiled regex patterns for extraction and safety checks.
- Fixed IndentationError in test wrapper using textwrap.indent.
- Robust path handling in save_jsonl to prevent FileNotFoundError.
- Fixed NameError in telemetry.py cache lookup.
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request parallelizes and optimizes the unit test gate script by executing sample tests concurrently using a ThreadPoolExecutor, pre-compiling regex patterns for security and code extraction, and using textwrap.indent to handle indentation in the execution wrapper. It also removes a state cache check in the telemetry module. Feedback highlights that the execution wrapper currently discards stderr output and fails to capture stdout or print tracebacks on failure, and suggests a fix to preserve all execution outputs.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 202 to +211
sys.stdout = original_stdout
sys.stderr = original_stderr

print("__EXECUTION_SUCCESS__")
print(stdout_capture.getvalue())
sys.stdout.write("__EXECUTION_SUCCESS__\\n")
sys.stdout.write(stdout_capture.getvalue())

except Exception as e:
sys.stdout = original_stdout
sys.stderr = original_stderr
print(f"__EXECUTION_ERROR__: {{e}}", file=sys.stderr)
sys.stderr.write(f"__EXECUTION_ERROR__: {{e}}\\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In the current implementation of the test wrapper, if the user's code executes successfully or raises an exception, any output written to sys.stderr (e.g., warnings, logs) is completely lost. Furthermore, if an exception is raised:

  1. The captured stdout (from stdout_capture) is never written back to the actual sys.stdout, meaning any output printed before the crash is lost.
  2. The traceback of the exception is not printed, making it very difficult to debug the failure.

To fix this, we should:

  • Write the captured stderr in the success path.
  • Write the captured stdout, stderr, and the exception traceback (using traceback.print_exc) in the error path.
    sys.stdout = original_stdout
    sys.stderr = original_stderr

    sys.stdout.write("__EXECUTION_SUCCESS__\\n")
    sys.stdout.write(stdout_capture.getvalue())
    sys.stderr.write(stderr_capture.getvalue())

except Exception as e:
    import traceback
    sys.stdout = original_stdout
    sys.stderr = original_stderr
    sys.stderr.write(f"__EXECUTION_ERROR__: {{e}}\\n")
    traceback.print_exc(file=sys.stderr)
    sys.stderr.write(stderr_capture.getvalue())
    sys.stdout.write(stdout_capture.getvalue())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant