Skip to content

fix(security): bandit reports failed on every review of more than 50 python files #1009

Closed

Description

@dan-petty

Problem

Every branch review since session 20261002-163203 reports ! Failed during execution: Bandit. Bandit ran in 20261002-142541 and has failed in 20261002-163203, 20261002-180320 and 20261002-200610. Nothing reaches the report but | Bandit | failed |, so a gating scanner has silently stopped contributing to reviews of release/v0.2.25.

The cause is Bandit's progress bar. bandit/core/manager.py:29 sets PROGRESS_THRESHOLD = 50, and manager.py:269-273 wraps the file list in rich.progress.track when there are more than 50 files and the log level is INFO or lower. The bar is written to stdout ahead of the JSON report. The branch diff now holds 220 Python files. At e4ea2e0, running the review's own command (BanditScanner().build_command(<220 changed .py files>)) gives exit code 1, and stdout starts Working... ━━━━ 100% 0:00:20\n{\n "errors": [] .... _parse_json_or_ndjson (src/devops_cli/security/base.py:33-53) cannot parse it, so _handle_non_json_output (base.py:137-163) returns failed, and the 1-exit that only meant "issues found" is reported as a failure. Session 1 got clean JSON because its diff had fewer than 51 Python files.

BanditScanner.build_command (src/devops_cli/security/bandit.py:56-88) is the only Bandit caller without -q. config/commands.py:128 and ai/tools/builtin_tools.py:321 pass it. -q sets the log level to WARN, which suppresses the bar. The gate (commands/ci.py:431, 984) does not parse JSON, so it is unaffected. The same defect hits any BanditScanner scan of a directory with more than 50 Python files (-r <dir>).

The failure was hard to diagnose for two reasons:

  • _handle_non_json_output reports Scanner exited with code 1: <first 256 chars of stderr>, which here is Bandit's INFO log ("profile include tests: None ..."), and says nothing about the output not being JSON.
  • _static_analyzer_states (src/devops_cli/ai/review/pipeline.py:1085-1099) keeps only each analyzer's state. The reason is dropped, so the terminal line (pipeline.py:1120) and the report's Static Analyzers table (pipeline.py:3250) show failed with no cause.

Acceptance criteria

  • BanditScanner.build_command passes -q in all three command shapes (file list, single file, -r directory).
  • A test drives BanditScanner.scan over more than 50 Python files through a fake subprocess that behaves like Bandit 1.9: without -q it prefixes stdout with a progress bar, and it exits 1 when it reports results. The scan returns status ran with the findings. The test fails on the current code.
  • When a scanner exits non-zero and its stdout is non-empty but not JSON, the failed reason says the output was not JSON and quotes the start of stdout, not only stderr. A test pins the reason.
  • A failed analyzer's reason reaches the report's Static Analyzers table (for example failed: exited with code 1; output was not JSON ...), with Markdown pipes escaped, and the terminal line names the analyzer and points to the report. A test pins the table row.
  • Tests run no real scanner and no network, and each runs well under 1 s.
  • changelog.d/1009.md records the fix under ### Fixed. CHANGELOG.md is not edited.
  • uv run devops ci passes.
  • (person-run) uv run devops ai review branch --persona devsecops release/v0.2.25 reports Bandit as ran.

Key questions

  • -q, or read the report from -o <file>? (proposed) -q. The other two callers already use it, it is the documented way to silence Bandit's INFO output, and it keeps the shared stdout-JSON path. -o would add a temporary file for one scanner.
  • Should the JSON parser skip leading non-JSON lines instead? (proposed) No. Guessing where JSON starts would hide the next tool that writes noise to stdout. The scanner should ask for clean output, and the failure reason should say when it did not get it.
  • Is this a critical fix for the current release? (proposed) Yes. A gating security scanner has not run on any branch review of the release since 2026-10-02, and the fix is small.

Depends on: none.
Order: touches security/bandit.py, security/base.py (_handle_non_json_output only) and the analyzer-state reporting in ai/review/pipeline.py. #987 edits other parts of pipeline.py's terminal output; whichever lands second rebases.
Related: #708 (scanner outcome failed is not clean), #516, #963 (scanner timeout and cwd), #987 (terminal output).

Activity

  1. added this to the v0.2.25 milestone on Oct 2, 2026
  2. added
    type/bug
    scope/security
    scope/review
    priority/p1-high
    on Oct 2, 2026
  3. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1012, merged into release/v0.2.25.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  4. added a commit that references this issue on Oct 3, 2026
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

    priority/p1-highscope/reviewscope/securitytype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions