Skip to content
Merged
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 docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ High-density product roadmap, engineering milestones, and open-source integratio
- [x] **Defect Generator Injects Into Code Examples Inside Block Comments (P1 - High, Issue #537)**:
- *Context & Rationale*: The first sample validation (#505) found 9 of 78 brace-language injections inside multi-line comments, all dropped awaits in ky's JSDoc examples. The finders blanked one-line comments only, so documentation counted as code and the corpus scored reviewers on defects that do not exist.
- *Delivered*: Block comments spanning lines are blanked for every brace-language finder and the Terraform block tracker; a `/*` or `//` inside a string opens no comment. TLS, file-mode and Terraform substitutions apply only outside comments. On the pinned samples no site falls inside a comment. TypeScript `drop-await` sites fell from 99 to 44 and `drop-bounds-check` from 15 to 12; other languages are unchanged.
- [x] **Verifier Invalidates Findings Its Own Reason Confirms (P1 - High, Issue #536)**:
- *Context & Rationale*: The first sample validation (#505) found all three unpinned `:latest` image findings invalidated although the verifier's reason confirmed the defect: it filed the finding's own verification criterion, or its fix, as the invalidation it matched. They were 3 of the run's 6 found-then-dropped injections.
- *Delivered*: A matched invalidation criterion that restates the finding's claim or fix, or a reason that states the claimed condition without negating it, no longer invalidates; the finding stays unverified and reported. Genuine refutations still invalidate. The run's misread verdicts are regression cases in the #509 harness.
- [ ] **AST Support for C#, C/C++, Shell and Markdown (P2 - Medium, Issue #506)**:
- *Context & Rationale*: The AST engine maps Python, TypeScript, JavaScript, Go, Rust, Java and HCL. C#, C, C++, shell and Markdown files yield no symbols, so repomaps, context packing and review grounding see nothing in them.
- *Deliverable*: Tree-sitter grammars where a maintained package exists, and fallback extractors for functions, types and headings, each tested on its pinned sample repository.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Task 536: Verifier Invalidates Findings Its Own Reason Confirms

**Issue**: [#536](https://github.com/dan-petty/devops-cli/issues/536)
**Status**: Done
**Milestone**: `v0.2.23`
**Priority**: `priority/p1-high`
**Scope**: `type/bug`, `scope/review`, `priority/p1-high`

---

## 1. Description & Objectives

The first sample validation (#505) found all three unpinned `:latest` image findings INVALIDATED,
although the verifier's own reason confirmed the defect. It had filed the finding's verification
criterion, or its fix, as the invalidation criterion it matched:
- "Line 6 contains `FROM alpine:latest`, which uses the unpinned `latest` tag", matched as
"The FROM directive still uses 'latest' as the image tag.";
- "The Dockerfile contains a specific tag (e.g., `golang:1.22.3`) and a checksum", which is the
fix.

These were 3 of the run's 6 found-then-dropped injections.

### Key Deliverables Completed:

- [x] **Self-refutation withdrawn** (`_without_self_refutation` in `verification.py`):
- A matched invalidation criterion that restates the finding's verification criteria, title or
fix (60% or more of their words, and closer to them than to the finding's invalidation
criteria) is not a refutation.
- A reason that states the claimed condition without negating it confirms the finding.
- When the invalidation rests only on those, it is withdrawn, the INVALIDATED status included,
and the finding stays unverified and in the report.
- A genuine refutation still invalidates, even beside a restatement.
- [x] **Automated Tests & Quality Gates**:
- `tests/test_review_verifier_self_refutation.py`:
- the verification criterion, a reworded criterion, and the fix as the "invalidation";
- no criteria and a confirming reason;
- genuine refutations by digest, by test fixture, and beside a restatement;
- an untouched confirmation.
- `tests/test_review_regression_harness.py`: the run's two misread verdicts, in the golden set
(`misread_verdicts`).
- `tests/test_review_verification.py`: the invalidation case now matches a criterion the
finding names as invalidating it, not its own claim.
- 100% passing status across Gated CI validation suite (`uv run devops ci`).
67 changes: 66 additions & 1 deletion src/devops_cli/ai/review/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,71 @@ def _verdict_status(item: dict[str, Any], inv_matched: list[str]) -> tuple[str,
return "UNVERIFIED", True


# Words too common to tell one claim from another.
_CLAIM_STOPWORDS = frozenset(
{"the", "a", "an", "of", "to", "in", "is", "are", "as", "for", "with", "that", "this"}
| {"and", "or", "be", "it", "its", "on", "by", "at", "still", "which", "verify", "check"}
)
# A reason that negates what it quotes may be a refutation; one that does not only restates.
_NEGATION = re.compile(
r"\b(?:not|no|never|none|cannot|without|already|isn't|doesn't|don't|aren't|wasn't)\b|n't\b"
)
_RESTATEMENT_OVERLAP = 0.6


def _claim_words(text: str) -> set[str]:
return {w for w in re.findall(r"[a-z0-9]+", text.lower()) if w not in _CLAIM_STOPWORDS}


def _covers(text: str, claims: list[str]) -> float:
"""The largest share of any claim's words that the text contains."""
words = _claim_words(text)
shares = [len(cw & words) / len(cw) for claim in claims if (cw := _claim_words(claim))]
return max(shares, default=0.0)


def _restates_the_finding(criterion: str, f: Finding) -> bool:
"""Whether a "matched invalidation criterion" only restates the defect or its fix.

Models file the finding's own verification criterion, or the fix, as the invalidation they
matched: "The FROM directive still uses 'latest' as the image tag." That confirms the
defect. A criterion closer to the finding's invalidation criteria than to its claim and fix
is a refutation.
"""
claim = _covers(criterion, [*f.verification_criteria, f.title, f.fix])
refutation = _covers(criterion, list(f.invalidation_criteria))
return claim >= _RESTATEMENT_OVERLAP and claim > refutation


def _reason_confirms(reason: str, f: Finding) -> bool:
"""Whether the verdict's reason states the claimed condition without negating it."""
return (
bool(reason)
and not _NEGATION.search(reason.lower())
and _covers(reason, [*f.verification_criteria, f.title]) >= _RESTATEMENT_OVERLAP
)


def _without_self_refutation(f: Finding, item: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
"""The verdict with its invalidation withdrawn when it rests only on the finding's own claim.

An invalidation whose matched criteria all restate the defect or its fix, or whose reason
confirms the claimed condition, names no evidence against the finding; it leaves the
finding unverified and in the report.
"""
inv_matched = _verdict_list(item.get("invalidated_criteria_matched"))
genuine = [c for c in inv_matched if not _restates_the_finding(c, f)]
reason = str(item.get("reason") or "").strip()
if genuine and not _reason_confirms(reason, f):
return item, inv_matched
if not inv_matched and not _reason_confirms(reason, f):
return item, inv_matched
withdrawn = {**item, "invalidated": False}
if str(item.get("status") or "").strip().upper() == "INVALIDATED":
withdrawn["status"] = ""
return withdrawn, []


def _apply_single_finding_verification(
f: Finding, item: dict[str, Any] | None, now_iso: str
) -> Finding:
Expand All @@ -1256,7 +1321,7 @@ def _apply_single_finding_verification(
return f

ver_matched = _verdict_list(item.get("verified_criteria_matched"))
inv_matched = _verdict_list(item.get("invalidated_criteria_matched"))
item, inv_matched = _without_self_refutation(f, item)
status_val, is_rep = _verdict_status(item, inv_matched)
is_v = status_val == "VERIFIED"
# A model's invalidation does not teach the hallucinations catalog: it is the judgement
Expand Down
Loading
Loading