Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@
## 2026-07-09 - Avoid N+1 API blocking in SBOM aggregator
**Learning:** The `collect_inventories` function in `scripts/ci/sbom_inventory_aggregator.py` was fetching SBOMs from the GitHub dependency graph synchronously for every repository in the organization. For large organizations (up to 500 repos), this N+1 network/CLI bottleneck significantly stalled the aggregation workflow.
**Action:** Use `concurrent.futures.ThreadPoolExecutor` to fetch SBOMs concurrently when multiple repositories are provided, bounded by a `max_workers` limit (e.g., 10) to avoid overwhelming the CLI/API, while preserving the fast serial path for single-item inputs.
## 2026-07-09 - Pre-compile Regex Patterns in Embedded Python Loop-called Functions
**Learning:** Found a regex recompilation bottleneck in `scripts/ci/opencode_review_approve_gate.sh` where `hunk_header = re.compile(...)` was defined inside the `changed_new_lines` inner Python function. Even when the outer Python execution is embedded in a shell script, recompiling a regex object inside a function called repetitively (like processing git diff lines for multiple files) incurs measurable overhead.
**Action:** Move inline regex compilation (using `re.compile()`) outside of loop-called functions to the module level, even when the Python script is embedded in a bash file (`cat << 'EOF' | python3`). Ensure global variables/constants are well documented.
8 changes: 6 additions & 2 deletions scripts/ci/opencode_review_approve_gate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ def normalized_line(value: str) -> str:
return " ".join(value.strip().split())


# ⚡ Bolt: Pre-compile regex at the module level to prevent recompilation in loop-called functions
# Impact: Reduces regex recompilation overhead when processing git diff hunk headers for every changed file
HUNK_HEADER_RE = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@")


# ⚡ Bolt: Memoize changed_new_lines to prevent N+1 git diff subprocess calls
# Impact: Substantially reduces I/O wait overhead when multiple findings are on the same file path
@functools.cache
Expand Down Expand Up @@ -265,9 +270,8 @@ def changed_new_lines(path_value: str) -> frozenset[int]:
return frozenset()

line_numbers: set[int] = set()
hunk_header = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@")
for raw_line in completed.stdout.splitlines():
match = hunk_header.match(raw_line)
match = HUNK_HEADER_RE.match(raw_line)
if not match:
continue
start = int(match.group(1))
Expand Down
3 changes: 3 additions & 0 deletions tests/test_opencode_existing_approval_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def trusted_adversarial_artifacts(tmp_path, monkeypatch):
),
encoding="utf-8",
)
changed_files.chmod(0o600)
manifest.chmod(0o600)

monkeypatch.setenv("RUNNER_TEMP", str(runner_temp))
monkeypatch.setenv("OPENCODE_SOURCE_WORKDIR", str(source_root))
monkeypatch.setenv("OPENCODE_CHANGED_FILES_FILE", str(changed_files))
Expand Down
Loading