Skip to content

⚡ Bolt: optimize dataset validation and fix telemetry NameError#171

Open
heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
bolt-optimize-validation-telemetry-1865705048273226241
Open

⚡ Bolt: optimize dataset validation and fix telemetry NameError#171
heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
bolt-optimize-validation-telemetry-1865705048273226241

Conversation

@heidi-dang
Copy link
Copy Markdown
Owner

Optimized scripts/02_validate_clean.py for faster dataset validation by replacing regex-based whitespace removal with string operations (~82% gain) and pre-compiling secret detection patterns. Also fixed a NameError in heidi_engine/telemetry.py caused by a broken redundant cache check, while preserving the functional primary cache. All tests pass.


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

Optimized `scripts/02_validate_clean.py` for faster dataset validation:
- Replaced regex-based whitespace removal in `fuzzy_hash` with a string `split/join` approach, yielding a ~82% speedup in this hot-path.
- Pre-compiled secret detection regex patterns to reduce overhead during large-scale scanning, providing a measurable (~4%) gain per check.

Fixed a critical regression in `heidi_engine/telemetry.py`:
- Removed a redundant and broken secondary cache check in `get_state` that referenced an undefined `target_run_id`, causing a `NameError`.
- Ensured the primary, thread-safe `StateCache` remains functional and efficient.

Verified correctness with `pytest tests/` (21/21 passed) and performance with dedicated benchmarking.
@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
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the performance of dataset validation processes and addresses a critical bug in the telemetry system. By optimizing string manipulation and regex usage in scripts/02_validate_clean.py, the validation script now runs considerably faster. Concurrently, a NameError in heidi_engine/telemetry.py was fixed by removing an erroneous cache check, ensuring the telemetry system operates correctly.

Highlights

  • Performance Optimization: Improved dataset validation speed in scripts/02_validate_clean.py by replacing regex-based whitespace removal with faster string operations, yielding an 82% performance gain.
  • Performance Optimization: Enhanced secret detection performance in scripts/02_validate_clean.py by pre-compiling regex patterns, resulting in a 4% speedup.
  • Bug Fix: Resolved a NameError in heidi_engine/telemetry.py by removing a broken and redundant thread-safe state cache check.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

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

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 introduces some great performance optimizations to the dataset validation script and fixes a bug in the telemetry module.

The move to pre-compiled regexes and using string splitting instead of re.sub for whitespace removal in 02_validate_clean.py are solid improvements. The fix in telemetry.py correctly removes a redundant and broken cache check.

I have one suggestion regarding the secret detection logic to improve its consistency and robustness, which I've detailed in a specific comment. Overall, these are valuable changes.

SECRET_CHECK_FIELDS = ["instruction", "input", "output", "response", "completion"]

# BOLT OPTIMIZATION: Pre-compiled secret patterns for faster detection (~4% gain)
_COMPILED_SECRET_PATTERNS = [(re.compile(p), t) for p, t in SECRET_PATTERNS]
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

While pre-compiling regexes is a good optimization, there's an inconsistency with how secrets are handled in heidi_engine/telemetry.py that could pose a security risk.

In telemetry.py, all secret patterns are matched case-insensitively. However, in this file, case-insensitivity is only applied if the pattern string contains (?i). Several patterns, such as those for ghp_, glpat-, and sk- tokens, are missing this and will be matched case-sensitively.

This discrepancy could result in a secret being missed by this validation script but redacted in the logs, allowing it to remain in the dataset.

To ensure consistent and more robust secret detection across the project, I recommend compiling all patterns with re.IGNORECASE.

Additionally, I noticed the SECRET_PATTERNS lists themselves differ between this file and telemetry.py. It would be beneficial to consolidate them into a single source of truth to prevent such inconsistencies in the future.

Suggested change
_COMPILED_SECRET_PATTERNS = [(re.compile(p), t) for p, t in SECRET_PATTERNS]
_COMPILED_SECRET_PATTERNS = [(re.compile(p, re.IGNORECASE), t) for p, t in SECRET_PATTERNS]

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