Skip to content

refactor(security): Remove the unused fallback path from the scanner base class #2713

Done

Description

@dan-petty

Problem

After the change of #2427 (pull request #2712), no scanner of the registry has a hand-written fallback. The scanner base class in src/devops_cli/security/base.py still has the machinery for one:

  • BaseSecurityScanner.fallback_scan and the class variable has_builtin_patterns.
  • _has_builtin_patterns and the branches that call scanner.fallback_scan(...) in _handle_non_json_output, _handle_json_output and the missing-binary path of scan.
  • The scan status built-in patterns, which CONST_SCAN_NO_RESULT_STATUSES, _RAN_STATUSES in security/pipeline.py and the status words of config/constants.py name.
  • has_builtin_patterns: ClassVar[bool] = False in the adapters that set it (trivy, mypy, golangci_lint, gitleaks, osv_scanner, kubelinter, semgrep).

No scanner overrides fallback_scan and none sets has_builtin_patterns to True (checked with grep -rn "has_builtin_patterns\|fallback_scan" src/devops_cli). So each of these branches is dead code, and a status that no scan can give is still in the reports.

Proposed remedy

Delete the fallback path from the base class, the status built-in patterns and every reference, with their tests. Write no shim. A test that fails when a scanner of the registry has built-in patterns already exists in tests/test_scanner_contract.py; adapt it to check that the class has no such attribute.

Existing Tool Considered

None needed: the change deletes code and builds nothing.

Acceptance criteria

  • grep -rn "fallback_scan\|has_builtin_patterns\|built-in patterns" src/devops_cli finds nothing.
  • The scanner base tests, the pipeline tests and the SARIF tests pass with no status built-in patterns.

Related: #2427, #2214.

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

Proposed design

Problem statement

After #2427 every scanner in the registry runs its pinned binary, so no scanner has a hand-written fallback. The scanner base class in src/devops_cli/security/base.py still carries the fallback: fallback_scan, has_builtin_patterns, _has_builtin_patterns, the branches in _evaluate_preflight, _handle_non_json_output, _handle_json_output and _failed_run, and the built-in patterns status in CONST_SCAN_STATUS_PRECEDENCE and _RAN_STATUSES. The status also feeds a dead built-in patterns analyzer state in the AI review report, and 11 adapters, not the 7 the body names, still declare the class variable. This change deletes the fallback, the status and every reference, with no shim, and adapts the tests that exercise them.

Acceptance criteria

Requirement: No fallback code in source

Every file under src/devops_cli, including the knowledge-base Markdown, SHALL hold no occurrence of fallback_scan, has_builtin_patterns, _has_builtin_patterns, built-in patterns or built-in fallback.

Scenario: Source search finds no match

  • WHEN A test reads every file under src/devops_cli and searches for the five names
  • THEN The search finds no occurrence.

Requirement: Failed run gives failed outcome

The scanner base class SHALL return a failed outcome with the error or timeout reason when the tool run raises or times out.

Scenario: Timeout and exception give failed

  • WHEN A scanner run with a fake tool executor reports a timeout or raises an exception
  • THEN The outcome status is failed and its reason holds no text about built-in patterns.

Requirement: Non-zero exit gives failed outcome

The scanner base class SHALL return a failed outcome when the tool exits with a non-zero code and gives no finding.

Scenario: Non-JSON output with exit code 2

  • WHEN A fake tool executor returns exit code 2 and output that is not JSON
  • THEN The outcome status is failed and the reason names the exit code.

Requirement: Missing binary is unavailable

The scanner base class SHALL return the status unavailable with no finding when the binary of the scanner is not on PATH.

Scenario: Binary not found

  • WHEN A scan runs and the binary check returns false
  • THEN The outcome status is unavailable and the reason names the binary.

Requirement: Status constants have no removed status

CONST_SCAN_STATUS_PRECEDENCE and _RAN_STATUSES SHALL contain no status built-in patterns.

Scenario: Status constants checked

  • WHEN A test reads both constants
  • THEN Neither holds built-in patterns, and _RAN_STATUSES equals ("ran",).

Requirement: Review report has no built-in patterns state

The AI review pipeline SHALL hold no analyzer state, constant or report label for built-in patterns, and SHALL name an analyzer with no binary not installed.

Scenario: Missing analyzer is not installed

  • WHEN static_analyzer_states runs for an analyzer whose binary is absent and no outcome is observed
  • THEN The state is not installed, and the module defines no ANALYZER_BUILTIN_PATTERNS.

Requirement: Contract test guards against return

The scanner contract test SHALL fail when a scanner class of the registry has the attribute has_builtin_patterns or defines fallback_scan.

Scenario: Registry scanners have no fallback attribute

  • WHEN The test iterates over every scanner class of the registry
  • THEN No class of the registry has either name, and a class that adds either makes the test fail.

Requirement: SDLC doc names no removed status

docs/SDLC.md SHALL describe the static analysis line without the status built-in patterns.

Scenario: Documentation search

  • WHEN A test reads docs/SDLC.md
  • THEN The file names no built-in patterns.

Existing Tool Considered

None adopted. The alternatives check of 2026-11-04 returned not-applicable for the class refactor, so no tool was proposed. The open, maintained tool for this job is vulture (https://github.com/jendrikseipp/vulture), and the project tried it and rejected it (CHANGELOG.md:2374): on src it left 720 findings, and a functions-and-methods-only check left 26 with two live framework hooks, needing 12 decorator patterns and 7 name patterns first. It also cannot see fallback_scan, which the base class still calls, or has_builtin_patterns, which getattr reads, and it cannot delete the branches, the adapters' class variables or the status. The change therefore deletes by hand, roughly 150 lines across security/base.py, config/constants.py, security/pipeline.py, ai/review/pipeline.py, ai/review/runner.py, ai/review/profile.py, the knowledge base, docs/SDLC.md, 11 adapters and the tests that exercise the fallback.

Key questions

  • Does the issue's premise hold at the commit: does the fallback machinery still exist, and does any scanner set it to True?: Yes. _has_builtin_patterns is at base.py:43, the base class declares has_builtin_patterns at base.py:532 and fallback_scan at base.py:640, and the branches call them at base.py:390, 440, 450, 469 and 788. Every adapter that declares the variable sets it False, and no module under src overrides fallback_scan; the only fallback_scan definitions are the base one and a test fake. [sources: src/devops_cli/security/base.py:43, src/devops_cli/security/base.py:532, src/devops_cli/security/base.py:640, src/devops_cli/security/base.py:390, src/devops_cli/security/base.py:788, src/devops_cli/security/trivy.py:145]
  • Does the fallback path exist in more places than the body lists?: Yes. _failed_run calls _has_builtin_patterns and returns the status built-in patterns (base.py:783-790); _run_scanner_command passes a Scanner error: ...; used built-in patterns text for exceptions (base.py:755-760); _outcome_of passes a timed out ...; used built-in patterns text for timeouts (base.py:772-774). The body lists only the missing-binary branch of scan, _handle_non_json_output and _handle_json_output, so its plan missed _failed_run and both reason texts. [sources: src/devops_cli/security/base.py:756, src/devops_cli/security/base.py:774, src/devops_cli/security/base.py:783, src/devops_cli/security/base.py:390, src/devops_cli/security/base.py:440, src/devops_cli/security/base.py:469]
  • Which constant holds the status built-in patterns, and which one does not?: CONST_SCAN_STATUS_PRECEDENCE holds it at constants.py:679; CONST_SCAN_NO_RESULT_STATUSES (constants.py:686-688) does not, so the body names the wrong constant for the no-result set. _RAN_STATUSES in security/pipeline.py:203 holds it too. CONST_AGENT_SCAN_STATUS_WORDS (constants.py:692-696) names only ran, clean and unavailable, so it needs no change. [sources: src/devops_cli/config/constants.py:673, src/devops_cli/config/constants.py:679, src/devops_cli/config/constants.py:686, src/devops_cli/config/constants.py:692, src/devops_cli/security/pipeline.py:203]
  • Which adapter files still declare has_builtin_patterns, and does the body name them all?: No. Eleven adapters declare it, all as False: bandit, gitleaks, golangci_lint, kubelinter, mypy, osv_scanner, pluto, popeye, ruff, semgrep and trivy. The body names seven and omits bandit.py, pluto.py, popeye.py and ruff.py; base.py:532 is the base declaration. [sources: src/devops_cli/security/bandit.py:95, src/devops_cli/security/gitleaks.py:115, src/devops_cli/security/golangci_lint.py:121, src/devops_cli/security/kubelinter.py:114, src/devops_cli/security/mypy.py:101, src/devops_cli/security/osv_scanner.py:296, src/devops_cli/security/pluto.py:69, src/devops_cli/security/popeye.py:69, src/devops_cli/security/ruff.py:233, src/devops_cli/security/semgrep.py:251, src/devops_cli/security/trivy.py:145, src/devops_cli/security/base.py:532]
  • Does anything outside the security package read the built-in patterns status?: Yes. ai/review/pipeline.py maps a ScanOutcome status to a review analyzer state: ANALYZER_BUILTIN_PATTERNS = "built-in patterns" at line 1018, the branch at 1045, the empty _ANALYZERS_WITH_BUILTIN_PATTERNS at 1035 with its branch at 1064, and the report lines at 1153, 1272, 1274, 1301, 1330 and 2704. ai/review/runner.py:399 counts the state as ran, ai/review/profile.py:152 names it, and src/devops_cli/ai/knowledge_base/devops_cli/tasks/ai_code_review.md:48 and docs/SDLC.md:268 describe it. The body's grep over src/devops_cli cannot pass without removing this state too. [sources: src/devops_cli/ai/review/pipeline.py:1018, src/devops_cli/ai/review/pipeline.py:1035, src/devops_cli/ai/review/pipeline.py:1045, src/devops_cli/ai/review/pipeline.py:1301, src/devops_cli/ai/review/runner.py:399, src/devops_cli/ai/review/profile.py:152, src/devops_cli/ai/knowledge_base/devops_cli/tasks/ai_code_review.md:48, docs/SDLC.md:268]
  • Does the change also remove the built-in patterns analyzer state from the AI review pipeline?: Yes. Remove ANALYZER_BUILTIN_PATTERNS, its branch in _static_analyzer_state_from_outcome, the empty _ANALYZERS_WITH_BUILTIN_PATTERNS and its branch in _predict_analyzer_state, the state's entries in the reason, summary, line-list and canary code, and the runner.py tuple. No scan can produce the status, and a missing analyzer then predicts not installed. (best practice) [sources: src/devops_cli/ai/review/pipeline.py:1018, src/devops_cli/ai/review/pipeline.py:1035, src/devops_cli/ai/review/pipeline.py:1064, src/devops_cli/ai/review/pipeline.py:1301, src/devops_cli/ai/review/pipeline.py:1330, src/devops_cli/ai/review/pipeline.py:2704, src/devops_cli/ai/review/runner.py:399, tests/ai/review/test_review_report_integrity.py:232, tests/ai/review/test_review_report_summary.py:210]
    • Chosen: Remove the review analyzer state with the status. No ScanOutcome can carry the status after the deletion, _ANALYZERS_WITH_BUILTIN_PATTERNS is already empty, and the body's grep over src/devops_cli requires every reference gone.
    • Rejected: Keep the review state as an unreachable branch. It leaves a state that no scan can produce, which is the dead code the issue removes, and it keeps the status string in source.
    • Rejected: Defer the review state to a separate issue. The removal is mechanical and needs no outside input; deferring it would leave the status string in src and the grep criterion failing.
  • What happens to _failed_run after the removal?: Drop the fallen_back parameter and keep the method, which returns only the failed outcome. Update both callers: the exception path passes Scanner execution failed: {exc} and the timeout path passes timed out after {timeout:g} s. (best practice) [sources: src/devops_cli/security/base.py:756, src/devops_cli/security/base.py:774, src/devops_cli/security/base.py:783]
    • Chosen: Delete the fallen_back parameter and keep _failed_run. The method keeps its single job and its log line, and both callers become shorter.
    • Rejected: Inline _failed_run into its callers. It spreads the log line and the failure text over two places.
  • Should the change keep a shim or a deprecation for the removed names?: No. AGENTS.md says the project is pre-1.0 and removes the old path without a shim; ADR 0005 records Deleted, not kept behind flags (pre-1.0); docs/TESTING.md:185 says a line that no public behaviour reaches is dead code and is deleted. The body also says to write no shim. (best practice) [sources: AGENTS.md:3, docs/adr/0005-review-findings-come-from-tools-not-models.md:49, docs/TESTING.md:185, CONTRIBUTING.md:30]
    • Chosen: Delete with no shim. It follows AGENTS.md, ADR 0005 and the body, and no outside consumer exists.
    • Rejected: Keep a deprecated fallback_scan. It keeps dead code and adds a warning that nobody can act on.
  • How does the contract test change?: The body's path is wrong: the test is tests/security/test_scanner_contract.py:113, not tests/test_scanner_contract.py. Adapt it to iterate the registry and assert that no scanner class has has_builtin_patterns or defines fallback_scan, and keep the missing-program behaviour check that every pinned scanner is unavailable with no finding. Also update the fakes and tests at tests/security/test_scanner_base_and_registry.py:58, 90 and 101 and tests/commands/test_scan_outcomes_and_gating.py:370 and 493. (best practice) [sources: tests/security/test_scanner_contract.py:113, tests/security/test_scanner_contract.py:134, tests/security/test_scanner_base_and_registry.py:58, tests/security/test_scanner_base_and_registry.py:90, tests/security/test_scanner_base_and_registry.py:101, tests/commands/test_scan_outcomes_and_gating.py:493]
    • Chosen: Adapt the contract test to assert the names are absent and a missing program is unavailable. It follows the body, keeps a guard against a later return, and keeps the missing-program behaviour the test protected.
    • Rejected: Delete the test. The guard against a return of the machinery and the missing-program check would be lost.
    • Rejected: Check only the attribute absence. It loses the check that a pinned program missing from PATH gives unavailable with no finding.
  • Which open tool covers the dead-code removal, and does the project adopt it?: No tool is adopted. vulture is the open, maintained dead-code finder, but the project tried it and rejected it: on src it left 720 findings, and a functions-and-methods-only check left 26 with two live framework hooks, needing 12 decorator patterns and 7 name patterns first. It also cannot see a method the base class calls or a class variable read through getattr. The change deletes by hand, as docs/TESTING.md:185 requires. (best practice) [sources: CHANGELOG.md:2374, docs/TESTING.md:185]
    • Chosen: Delete by hand. The project's trial of vulture rejected it, and the fallback names are reached through calls and getattr, which it cannot see.
    • Rejected: Adopt vulture as a dead-code check. The recorded trial left 720 findings on src, and even a functions-and-methods check needed 12 decorator patterns and 7 name patterns and still flagged live framework hooks.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/refactor
    status/new
    value/low
    effort/medium
    on Oct 29, 2026
  2. dan-petty commented on Oct 29, 2026

    @dan-petty
    OwnerAuthor

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

    • Type: type/refactor. The change deletes dead code from the base class and related files without altering behaviour.
    • Priority: P3-Low. Dead code removal has no user-facing impact and no time-sensitive risk.
    • Value: Low. Users see no change; the value is code clarity and reduced maintenance surface.
    • Effort: Medium. Deletion spans base.py, pipeline.py, constants.py, seven adapter files, and their tests, but no new logic is written.
    • Related: fix(security): tflint and dive are pinned in tools.lock, or their adapters and the tflint fallback go #2427, which asks for a different change. Both work on the security scanner fallback path; #2427 removes the tflint and dive adapters that used it, while this candidate removes the now-dead base-class infrastructure.
  3. added
    priority/p3-low
    scope/security
    on Oct 29, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 30, 2026
  5. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 18a6e2b (see proposed design in issue body).

  6. devops-cli-service commented on Nov 3, 2026

    @devops-cli-service
    Contributor

    The stage job returned the item to New. The premise of the issue does not hold at the staging commit, so the job planned no change and opened no pull request.

    Evidence:

    placeholder

  7. added
    status/new
    and removed
    status/ready
    on Nov 3, 2026
  8. devops-cli-service commented on Nov 4, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

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

    Tool: none found

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

  9. changed the title [-]refactor(security): the scanner base class keeps a fallback path that no scanner uses[/-] [+]refactor(security): Remove the unused fallback path from the scanner base class[/+] on Nov 6, 2026
  10. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

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

    • Before: refactor(security): the scanner base class keeps a fallback path that no scanner uses
    • After: refactor(security): Remove the unused fallback path from the scanner base class
    • Source of the summary: the background model
  11. added
    status/ready
    and removed
    status/new
    on Nov 9, 2026
  12. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 2f20244 (see proposed design in issue body).

  13. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  14. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  15. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 17:56 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/p3-lowscope/securitysource/agenttype/refactorvalue/low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions