Skip to content

perf(review): Run Gitleaks once per review instead of per file #2232

Closed

Description

@dan-petty

Problem

A review starts one sandboxed Gitleaks run for each file that it reviews, so the static stage of a review grows with the number of files.

Measured on 2026-10-25 on the devcontainer, with the default sandbox of a review (#2096) and no model:

  • devops review path src/devops_cli/security --static-scan-only (37 Python files): 3 min 10 s. Bandit, Semgrep and Gitleaks ran.
  • The Gitleaks part alone, run_gitleaks_scan(paths, ignore_tests=True, isolated=True) with SandboxToolExecutor over the same 37 files, as the review starts it (src/devops_cli/ai/review/pipeline.py): 37 runs, 65 s, about 1.8 s for each run.
  • devops review path . --static-scan-only (1514 files) did not finish in 30 minutes.

GitleaksScanner.scan runs Gitleaks one time for each file of a list target (src/devops_cli/security/gitleaks.py), because a Gitleaks scan takes one path. Each run makes its own scratch directory, isolation files and sandbox.

Proposed remedy

Run Gitleaks one time over a scratch directory that holds the reviewed files, as Semgrep does with materialize_targets (#1079), and map each finding back to its file. Then measure the other tools of the static stage (Bandit, Semgrep) the same way, and give each one run for all files where the tool takes many paths.

Existing Tool Considered

Gitleaks dir scans a directory in one run. The review already links its files under a scratch directory for Semgrep.

Acceptance criteria

  • A review of N files starts Gitleaks one time, and a test counts the runs on the tool executor fake.
  • Each finding names the reviewed file, not the scratch directory.
  • The static stage of the 37-file review above takes less time, measured before and after in the pull request.

Source: #772

Proposed design

Problem statement

A review starts one sandboxed Gitleaks run for each file it reviews. For 37 files, this takes 65 seconds. The fix is to run Gitleaks once over a scratch directory that holds all reviewed files, following the Semgrep materialize_targets pattern, and map each finding back to its original reviewed file.

Acceptance criteria

  • Criterion 1: A review of N files starts Gitleaks exactly one time.
    Verification: A test uses a fake tool executor and asserts the Gitleaks run count equals 1 for N > 1 files.
  • Criterion 2: Each Gitleaks finding names the reviewed file path, not the scratch directory path.
    Verification: A test creates a file with a known secret, runs the scan, and asserts the finding location contains the reviewed file path and not the scratch directory.
  • Criterion 3: The static stage of the 37-file review takes less time than before the change.
    Verification: The pull request records a before-and-after measurement of devops review path src/devops_cli/security --static-scan-only showing reduced wall-clock time.

Key questions

  • How does the Semgrep materialize_targets pattern work in this codebase?: The _scan_semgrep function passes all paths and a reviewed_tree to run_semgrep_scan. Semgrep links or copies files under the working directory and runs once. Gitleaks should follow the same approach: materialize files under a scratch directory and run Gitleaks dir once. [sources: src/devops_cli/ai/review/pipeline.py]
  • What is the current Gitleaks per-file invocation?: run_gitleaks_scan is called from _scan_secrets with all paths, ignore_tests=True, isolated=True, and a tool_executor. Inside, GitleaksScanner.scan runs Gitleaks one time per file, each with its own scratch directory, isolation files, and sandbox. [sources: src/devops_cli/security/gitleaks.py, src/devops_cli/ai/review/pipeline.py]
  • How should findings be mapped back to reviewed files after a single directory scan?: Use the same approach as the existing _match_static_findings_to_files and _find_matching_file functions in the pipeline. After the single Gitleaks run, map each finding's scratch-directory path back to the corresponding reviewed file path. (proposed) [sources: src/devops_cli/ai/review/pipeline.py]

Open questions

  • Can Gitleaks scan a directory in one run? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-03: not-applicable.
Class: perf, no search.
Tool: none found.

Activity

  1. added
    source/agent
    type/refactor
    on Oct 25, 2026
  2. dan-petty commented on Oct 25, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/refactor. The change improves performance by optimizing how Gitleaks runs during reviews without changing functionality.
    • Priority: P2-Medium. Improves performance of security scanning but does not block other work or introduce critical bugs.
    • Value: High. Reduces review time significantly from minutes to seconds for large codebases, improving developer productivity.
    • Effort: Medium. Requires changes to how Gitleaks is called and how findings are mapped back to files, but follows existing patterns like Semgrep's materialize_targets approach.
    • Related: test(ci): the suite's slowest tests run on recorded scanner and installer results, not real semgrep, gitleaks, bandit, uv audit, uv pip sync or sudo #1666, which asks for a different change. Both items address performance issues in security scanning, but the candidate focuses on Gitleaks optimization while item #1666 addresses slow test suite execution involving real scanners.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Refine cannot set this item to Ready at bb46660 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • Can Gitleaks scan a directory in one run? (missing verified source)
  4. added
    priority/p2-medium
    status/new
    effort/medium
    value/high
    type/infra
    scope/review
    and removed
    type/refactor
    on Oct 28, 2026
  5. devops-cli-service commented on Nov 3, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: perf. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-03. A person decides what this means for the item. The check changes no label and closes no issue.

  6. changed the title [-]perf(review): a review starts one sandboxed Gitleaks run for each file, so 37 files spend 65 s in Gitleaks[/-] [+]perf(review): Run Gitleaks once per review instead of per file[/+] on Nov 6, 2026
  7. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 92 characters, and the limit is 60. The type and the scope stay.

    • Before: perf(review): a review starts one sandboxed Gitleaks run for each file, so 37 files spend 65 s in Gitleaks
    • After: perf(review): Run Gitleaks once per review instead of per file
    • Source of the summary: the background model
  8. added
    owner/agent
    status/in-progress
    and removed
    status/new
    on Nov 9, 2026
  9. added a commit that references this issue on Nov 10, 2026
    3147a9e
  10. added
    status/in-review
    and removed
    status/in-progress
    on Nov 10, 2026
  11. removed
    status/in-review
    owner/agent
    on Nov 10, 2026
  12. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-10 01:00 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/reviewsource/agenttype/infravalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions