⚡ Bolt: Optimize dataset validation and fix telemetry cache NameError#166
Conversation
This commit implements several performance optimizations in the data validation script and fixes a critical NameError in the telemetry engine.
Changes:
- In `scripts/02_validate_clean.py`:
- Pre-compiled secret detection patterns to reduce regex overhead.
- Added a fast-path indicator check to skip detailed secret scanning for clean inputs (~42% speedup).
- Optimized `fuzzy_hash` whitespace removal using `"".join(text.split())` (~20% speedup).
- In `heidi_engine/telemetry.py`:
- Removed a redundant and broken cache check that referenced an undefined `target_run_id`, fixing a `NameError` while preserving the primary functional cache.
Verified with benchmark scripts and pytest.
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello, 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 and fuzzy hashing operations by introducing optimized regex handling and more efficient string manipulation techniques. Additionally, it addresses a critical bug in the telemetry module, ensuring its stability and correct functionality. The changes collectively contribute to a faster and more robust system. Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces several performance optimizations and a bug fix. The optimizations in scripts/02_validate_clean.py for secret detection and fuzzy hashing are well-implemented, significantly improving performance. The bug fix in heidi_engine/telemetry.py correctly resolves a NameError by removing a redundant and faulty cache check. I've identified a potential issue in the fast-path secret detection logic where some secret patterns might be missed. My review includes a suggestion to make the indicator regex more comprehensive.
| # BOLT OPTIMIZATION: Combined regex for fast-path skip. | ||
| # Skip expensive detailed searches for samples without obvious secret indicators. | ||
| _SECRET_INDICATORS = re.compile( | ||
| r"ghp_|glpat-|sk-|bearer|api[_-]?key|apikey|secret[_-]?key|AKIA|PRIVATE\s+KEY|OPENSSH|token|password|pwd|mongodb|postgres|mysql|redis", |
There was a problem hiding this comment.
The fast-path optimization is a great idea for performance. However, the _SECRET_INDICATORS regex seems to be missing some keywords from SECRET_PATTERNS, which could cause some secrets to be missed.
Specifically, patterns for aws_secret and postgres_url are not fully covered:
- The pattern for
aws_secret((r'(?i)aws[_-]?secret[_-]?access[_-]?key...') is not covered. A string likeaws_secret_access_key=...would be missed by the fast-path check. - The pattern for
postgres_url((r"(?i)postgresql://...")) is not covered.postgresis included, but notpostgresql.
To ensure all patterns are checked, please consider adding aws[_-]?secret and postgresql to the indicators regex.
| r"ghp_|glpat-|sk-|bearer|api[_-]?key|apikey|secret[_-]?key|AKIA|PRIVATE\s+KEY|OPENSSH|token|password|pwd|mongodb|postgres|mysql|redis", | |
| r"ghp_|glpat-|sk-|bearer|api[_-]?key|apikey|secret[_-]?key|AKIA|PRIVATE\s+KEY|OPENSSH|token|password|pwd|mongodb|postgres|mysql|redis|aws[_-]?secret|postgresql", |
⚡ Bolt Performance Boost:
scripts/02_validate_clean.pyusing a combined regex of common secret indicators. This allows the script to skip expensive per-pattern matching for most (clean) samples, resulting in a ~42% performance gain on representative datasets.re.sub(r"\s+", "", text)with the more efficient"".join(text.split())in thefuzzy_hashfunction, yielding a ~20% speedup for large text payloads.NameErrorinheidi_engine/telemetry.pywhere a redundant cache check referenced a non-existent variable. This fix ensures theget_stateAPI remains functional and efficient.Measurements:
detect_secrets(Clean): 0.0372 ms -> 0.0214 ms (~42% faster)fuzzy_hash(Large): 0.4349 ms -> 0.3494 ms (~20% faster)tests/test_telemetry_cache.py: PASSED (was failing with NameError)PR created automatically by Jules for task 13836788363663064678 started by @heidi-dang