Skip to content

⚡ Bolt: Remove lock contention in rule synchronization#120

Merged
abhimehro merged 1 commit intomainfrom
bolt/remove-locks-6965379817159253390
Jan 22, 2026
Merged

⚡ Bolt: Remove lock contention in rule synchronization#120
abhimehro merged 1 commit intomainfrom
bolt/remove-locks-6965379817159253390

Conversation

@google-labs-jules
Copy link

  • 💡 What: Refactored get_all_existing_rules and push_rules to use a scatter-gather pattern. Workers now return data instead of updating a shared set under a lock. The main thread aggregates the results.
  • 🎯 Why: Removing threading.Lock eliminates lock contention between worker threads, allowing for better parallelism and CPU utilization during rule processing.
  • 📊 Impact: Reduces synchronization overhead. Simplifies code by removing explicit locking logic.
  • 🔬 Measurement: pytest test_main.py passes. Verify sync functionality works as expected.

PR created automatically by Jules for task 6965379817159253390 started by @abhimehro

@google-labs-jules
Copy link
Author

👋 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.

@trunk-io
Copy link

trunk-io bot commented Jan 21, 2026

😎 Merged manually by Abhi Mehrotra (@abhimehro) - details.

client=mock_client
)

assert "h1" in existing_rules

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
)

assert "h1" in existing_rules
assert "h2" in existing_rules

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
all_rules.update(result)
except Exception as e:
folder_id = future_to_folder[future]
log.warning(f"Failed to fetch rules for folder ID {folder_id}: {e}")

Check warning

Code scanning / Prospector (reported by Codacy)

Use lazy % formatting in logging functions (logging-fstring-interpolation) Warning

Use lazy % formatting in logging functions (logging-fstring-interpolation)
test_main.py Outdated

Check notice

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
test_main.py Outdated

Check notice

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
existing_rules_lock = threading.Lock()

# CRITICAL FIX: Switch to Serial Processing (1 worker)
# This prevents API rate limits and ensures stability for large folders.

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Line too long (106/100) Warning

Line too long (106/100)
folder_data,
profile_id,
existing_rules,
existing_rules_lock,

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Line too long (112/100) Warning

Line too long (112/100)
hostnames = ["h1", "h2"]
existing_rules = set()

m.push_rules(

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning test

Missing function or method docstring
all_rules.update(result)
except Exception as e:
folder_id = future_to_folder[future]
log.warning(f"Failed to fetch rules for folder ID {folder_id}: {e}")

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Use lazy % formatting in logging functions Note

Use lazy % formatting in logging functions
return False
return None

# Optimization 3: Parallelize batch processing

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning

Missing function docstring
existing_rules_lock,
client # Pass the persistent client
): folder_data
for folder_data in folder_data_list

Check warning

Code scanning / Pylint (reported by Codacy)

Line too long (106/100) Warning

Line too long (106/100)
main.py Outdated

Check warning

Code scanning / Pylint (reported by Codacy)

Line too long (112/100) Warning

Line too long (112/100)
hostnames = ["h1", "h2"]
existing_rules = set()

m.push_rules(

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning test

Missing function docstring
existing_rules = set()

m.push_rules(
profile_id="p1",

Check warning

Code scanning / Pylint (reported by Codacy)

Variable name "m" doesn't conform to snake_case naming style Warning test

Variable name "m" doesn't conform to snake_case naming style
@abhimehro abhimehro marked this pull request as ready for review January 21, 2026 18:41
Copilot AI review requested due to automatic review settings January 21, 2026 18:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the rule synchronization logic to eliminate lock contention by implementing a scatter-gather pattern. Worker threads now return data instead of updating shared sets under locks, with the main thread aggregating results. This simplifies the code and improves parallelism potential.

Changes:

  • Removed all threading.Lock usage from get_all_existing_rules and push_rules
  • Refactored worker functions to return results instead of updating shared state
  • Updated tests to reflect lock removal and verify correct behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
main.py Refactored get_all_existing_rules and push_rules to use scatter-gather pattern; removed threading import and lock-related parameters
test_main.py Removed lock-related test assertions; added new test case to verify existing_rules update behavior; updated comments

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@abhimehro abhimehro merged commit 50df8ae into main Jan 22, 2026
24 checks passed
@abhimehro abhimehro deleted the bolt/remove-locks-6965379817159253390 branch January 22, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants