Skip to content

Bug: Empty / zero-result runs exit 0 and read as a CI "pass" #116

Closed

Description

@trevor-vaughan
  • Severity: Medium
  • Status: Confirmed — reproduced first-hand on 2026-06-08
  • Component: cmd/gaze/main.go (analyze and crap zero-result paths)
  • Affected commands: gaze analyze, gaze crap (and report, quality zero-function paths)
  • Audited commit: 1a06131 (main)
  • Target codebase: complytime-labs/crosscodex @ dae5cc4
  • Evaluation model: Claude Opus 4.6 (1M context) — claude-opus-4-6 (analysis and parallel audit subagents)

Summary

When a command analyzes nothing — a package with no exported functions, or a
mistyped/zero-matching pattern — gaze exits 0 and the output looks like a pass.
For the threshold-bearing commands this means a CI gate "passes" on a package
that contains no analyzable code, masking misconfiguration.

Reproduction

# Package with only an unexported function (no exported API):
$ gaze analyze ./empty ; echo "exit=$?"
# WARN no functions found
exit=0

# Threshold gate on a package with no functions:
$ gaze crap --max-crapload=1 ./empty ; echo "exit=$?"
No functions analyzed.
exit=0                      # gate "passes" with nothing to measure

A mistyped package path or a package that matches nothing therefore sails
through a --max-crapload / --max-gaze-crapload gate as a pass.

Expected vs Actual

  • Expected: A gate command (one given a --max-* threshold) that finds zero
    analyzable functions should warn and/or fail, distinguishing "0 violations" in
    real code from "nothing was analyzed."
  • Actual: Zero-result runs print an informational line and exit 0, identical
    to a genuine pass.

Impact

Combined with BUG_007 (silent single-package truncation) and BUG_003 (silent
empty quality output), this makes it easy to wire a green CI gate that is in fact
measuring nothing. The recurring theme across BUG_001/002/003/008/016 is that
"could not analyze" is reported as a passing empty result.

Suggested fix

When a command was given a threshold flag (or a ./...-style pattern) but
produced zero analyzable functions/tests, emit a clear warning and exit
non-zero (or a documented "no-data" exit code), so empty results cannot be
mistaken for a pass.

Activity

  1. added
    bug
    on Jun 8, 2026
  2. jflowers commented on Jun 16, 2026

    @jflowers
    Collaborator

    Review Council Analysis

    Five divisor agents (Adversary, Architect, Guard, SRE, Testing) reviewed this issue against the codebase and constitution. Unanimous verdict: VALID, CRITICAL.


    Confirmed Code Paths

    Every zero-result exit path was traced through the source:

    Command Code Location Zero-Result Behavior
    gaze analyze main.go:218-223 return nil (exit 0) with warning
    gaze crap --max-crapload=5 main.go:665-676 0 > 5 = false → exit 0
    gaze quality --min-contract-coverage=50 main.go:877-880 Returns nil before threshold check is reached
    gaze report --max-crapload=5 threshold.go:20-67 0 <= 5 → pass
    gaze report --min-contract-coverage=1 threshold.go:20-67 0 >= 1 → FAIL (coincidentally correct, not by design)

    Constitution Violations

    • Principle I (Accuracy): A vacuous pass is a false negative — the tool reports "quality is fine" when nothing was measured.
    • Principle III (Actionable Output): CRAPload=0 from zero functions is semantically meaningless but indistinguishable from CRAPload=0 from healthy code. Metrics are not comparable across runs.

    Critical Assessment of the Suggested Fix

    The suggestion — "exit non-zero when threshold flags are set and zero functions are analyzed" — is directionally correct but incomplete. Issues identified:

    1. The ./... pattern clause is too broad

    The trigger should be threshold flags only, not pattern shape. gaze analyze ./... without thresholds is legitimate exploratory use.

    2. gaze quality has a deeper control flow bug

    At main.go:877-880, runQuality returns nil on zero results before threshold evaluation at line 941. --min-contract-coverage is dead code in this path. The fix must restructure the control flow, not just add a check.

    3. gaze report pipeline masks total failure

    All four pipeline steps capture errors non-fatally (runner.go:253-289). If ALL steps fail, ReportSummary is zero-valued, and max thresholds pass. Needs a "total failure" check.

    4. ReportSummary lacks TotalFunctions

    aireport.ReportSummary cannot distinguish "CRAPload=0 because code is clean" from "CRAPload=0 because nothing was analyzed." A TotalFunctions int field must be added and propagated from crap.Summary.TotalFunctions.

    5. Threshold API inconsistency between commands

    gaze crap uses int with > 0 guard (0 disables the check), while gaze report uses *int + cmd.Flags().Changed() (nil disables, *0 is a live threshold). These should be unified.

    6. An existing test documents the bug as correct

    TestEvaluateThresholds_NilPayload at threshold_test.go:235 asserts that a nil payload with MaxCrapload=5 passes. This test enshrines the broken behavior.

    7. An escape hatch is needed

    Legitimate zero-result scenarios exist (monorepo with mixed languages). --allow-empty (opt-out of the safety check) is better than --fail-on-empty (opt-in), because the safe default should be "fail on empty when thresholds are active."


    Recommended Exit Code Design

    Exit Code Meaning
    0 Analysis ran, all thresholds passed (or no thresholds set)
    1 Analysis ran, thresholds exceeded
    2 No data — zero functions analyzed when thresholds were set

    Exit code 2 follows Unix convention (grep, diff) and all CI systems treat it as failure. Alternatively, exit 1 with a clear stderr message is acceptable.


    Recommended Scope

    Must Fix Should Fix Don't Fix
    checkCIThresholds — add TotalFunctions == 0 guard Unify int vs *int threshold API gaze analyze without thresholds (exit 0 is correct)
    EvaluateThresholds — add TotalFunctions == 0 guard Add --allow-empty flag gaze docscan (not a quality gate)
    runQuality — restructure early return so thresholds are evaluated Actionable warning messages with hints Individual empty packages in ./...
    ReportSummary — add TotalFunctions field Add injection points to analyzeParams/qualityParams for testability
    Pipeline total-failure check in runProductionPipeline JSON no_data indicator

    Required Tests (~10 new cases)

    • Zero scores + active threshold → error (for crap, quality, report)
    • Zero scores + no threshold → nil (preserved behavior)
    • Zero scores + --allow-empty → nil (escape hatch)
    • Non-zero scores + threshold → existing behavior preserved
    • Update TestEvaluateThresholds_NilPayload (currently asserts the bug)

    Backward Compatibility

    This is a bug fix, not a feature change. Users whose pipelines break were getting false confidence. Recommendation: no deprecation period, document in release notes, minor version bump, --allow-empty as escape hatch.


    Bottom Line

    The issue is valid and correctly diagnosed. The suggested fix needs refinement: scope to threshold-bearing invocations only, address the gaze quality early return bypass, propagate TotalFunctions to ReportSummary, add --allow-empty, and unify threshold APIs. This requires a spec given it touches multiple commands, the threshold evaluation logic, and the report pipeline data model.

  3. moved this from Backlog to Ready 🚀 in Unbound Force Planningon Jun 16, 2026
  4. moved this from Ready 🚀 to In Progress 📋 in Unbound Force Planningon Jun 16, 2026
  5. self-assigned this
    on Jun 16, 2026
  6. moved this from In Progress 📋 to Done ✔️ in Unbound Force Planningon Jul 16, 2026
  7. added 2 commits that reference this issue on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions