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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-30
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Design

## Context

See proposal.md for motivation. `FindingState.CONFIRMED` and `Finding.confirmed_by` exist in `src/devops_cli/review/finding.py` and `src/devops_cli/review/state.py`. However, session storage relies on `SavedFinding` in `src/devops_cli/ai/review_schema.py`, which currently omits these lifecycle fields. In addition, `_VALID_TRANSITIONS` permits CONFIRMED findings to transition only to FIXED, preventing adjudicators from overturning a verdict back to OPEN.

## Goals / Non-Goals

**Goals:**
- Store finding lifecycle state (`FindingState`) and confirmation adjudicator (`confirmed_by`) on `SavedFinding`.
- Update finding state to CONFIRMED when a person records a VERIFIED or MITIGATED verdict on an admitted finding with a fingerprint v2.
- Reset finding state to OPEN and clear `confirmed_by` when a later verdict invalidates or resets the finding.
- Allow CONFIRMED to transition to OPEN in `_VALID_TRANSITIONS`.
- Mirror `state` and `confirmed_by` between `findings.json` and `candidates.json`.
- Display finding state in `devops review findings --details`.

**Non-Goals:**
- Machine-originated verdicts setting CONFIRMED: only human verdicts or replayed observations confirm findings.
- Custom state values beyond canonical `FindingState` enum members.

## Decisions

### Decision: Add `state` and `confirmed_by` directly to `SavedFinding`
- **Choice**: Add `state: FindingState = FindingState.OPEN` and `confirmed_by: str | None = None` to `SavedFinding` in `src/devops_cli/ai/review_schema.py`.
- **Alternative considered**: Store state in `findings.sarif` property bags.
- *Evidence for rejection*: `SavedFinding` is the authoritative session payload persisted in `findings.json` and `candidates.json` read by `devops review verify` and `devops review findings`.

### Decision: Allow transition from CONFIRMED to OPEN
- **Choice**: Add `FindingState.OPEN` to `_VALID_TRANSITIONS[FindingState.CONFIRMED]` in `src/devops_cli/review/state.py`.
- **Alternative considered**: Disallow overturning a CONFIRMED finding.
- *Evidence for rejection*: A human reviewer can re-evaluate and mark a previously verified finding as `INVALIDATED` or `UNVERIFIED`. Refusing the transition would break `devops review verify`.

### Decision: Update state in `apply_verdict`
- **Choice**: In `src/devops_cli/ai/review/verdicts.py`, check if the finding has a valid fingerprint v2 and `by == "human"`. Set `state = FindingState.CONFIRMED` and `confirmed_by = "human"` on VERIFIED/MITIGATED. Set `state = FindingState.OPEN` and `confirmed_by = None` on UNVERIFIED/INVALIDATED.
- **Alternative considered**: Adding a separate command to change lifecycle state.
- *Evidence for rejection*: `apply_verdict` is the unified entrypoint for adjudication across `devops review verify`. Automatic alignment avoids state drift between verdict status and lifecycle state.

### Decision: Include state fields in adjudication mirroring
- **Choice**: Add `"state"` and `"confirmed_by"` to `_VERDICT_FIELDS` in `src/devops_cli/ai/review/adjudication.py`.
- **Alternative considered**: Only writing state to `findings.json`.
- *Evidence for rejection*: Adjudication mirrors verdicts between `candidates.json` and `findings.json`. Omitting state fields would cause the two files to diverge.

## Risks / Trade-offs

- [Risk] Historical sessions lack `state` and `confirmed_by` in their JSON files.
→ Mitigation: `SavedFinding` assigns defaults `FindingState.OPEN` and `None`. A pre-validation normalizer handles string values gracefully.
- [Risk] Invariant checks fail if `state == CONFIRMED` without `confirmed_by`.
→ Mitigation: `_validate_finding_state_fields` and `assert_finding_state_invariants` require non-empty `confirmed_by` for CONFIRMED findings; `apply_verdict` sets both atomically.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Proposal

## Why

Issue #2414: A person's VERIFIED or MITIGATED verdict on an admitted finding does not set the finding's stored state to CONFIRMED. CONTEXT.md and the review redesign (#1137, child P2-10, #877) state that a valid verdict sets CONFIRMED. The session files hold no state field, and `apply_verdict` updates no state.

## What Changes

- Add `state` (default `FindingState.OPEN`) and `confirmed_by` (default `None`) fields to `SavedFinding`.
- Update `apply_verdict` so a person's VERIFIED or MITIGATED verdict on an admitted finding with a fingerprint v2 sets `state` to `FindingState.CONFIRMED` and `confirmed_by` to `"human"`.
- Update `apply_verdict` so a later verdict of UNVERIFIED or INVALIDATED on a CONFIRMED finding resets `state` to `FindingState.OPEN` and clears `confirmed_by`.
- Allow the transition from `FindingState.CONFIRMED` to `FindingState.OPEN` in `_VALID_TRANSITIONS` in `src/devops_cli/review/state.py`.
- Include `state` and `confirmed_by` in `_VERDICT_FIELDS` in `src/devops_cli/ai/review/adjudication.py` so mirroring keeps `findings.json` and `candidates.json` in step.
- Update `_build_finding_panel_lines` in `src/devops_cli/commands/review.py` to display the finding's state in `devops review findings --details`.
- This change fits one pull request.

## Capabilities

### New Capabilities
- `review-finding-state`: Stores and transitions review finding lifecycle states when human verdicts are recorded.

### Modified Capabilities

## Impact

- `src/devops_cli/ai/review_schema.py`: `SavedFinding` model fields.
- `src/devops_cli/ai/review/verdicts.py`: `apply_verdict` logic.
- `src/devops_cli/review/state.py`: `_VALID_TRANSITIONS` table.
- `src/devops_cli/ai/review/adjudication.py`: `_VERDICT_FIELDS` set.
- `src/devops_cli/commands/review.py`: `devops review findings --details` display.
- `tests/test_review_adjudication.py`, `tests/test_review.py`: unit tests.

## Feasibility

Checked on `origin/main` at commit 6c502854:

- `FindingState.CONFIRMED` and `Finding.confirmed_by` exist in `src/devops_cli/review/state.py` and `src/devops_cli/review/finding.py`.
- `SavedFinding` in `src/devops_cli/ai/review_schema.py` lacks `state` and `confirmed_by`.
- `_VALID_TRANSITIONS` in `src/devops_cli/review/state.py:27-36` allows CONFIRMED to transition only to FIXED, which rejects changing an overturned human verdict back to OPEN.
- `apply_verdict` in `src/devops_cli/ai/review/verdicts.py` updates `status`, `verified`, and `verified_by`, but does not touch `state` or `confirmed_by`.
- The premise is confirmed by code inspection and existing test output.

## Existing Tool Considered

SARIF 2.1.0 does not specify a CONFIRMED state for findings. The repository already contains `FindingState.CONFIRMED` and `FindingState.OPEN` in `src/devops_cli/review/state.py`. This change uses existing domain models and extends `SavedFinding` and `apply_verdict` with no new dependencies or outside tools. The change deletes no internal code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Spec Delta

## Purpose

Stores, validates and displays the lifecycle state and confirmation adjudicator of admitted review findings across session files and CLI reports.

## ADDED Requirements

### Requirement: Human valid verdict confirms admitted finding
When a person records a VERIFIED or MITIGATED verdict on an admitted finding that has a fingerprint v2, the system SHALL store its lifecycle state as CONFIRMED and record its confirmation adjudicator as human.

#### Scenario: Person records VERIFIED verdict
- **WHEN** A person records a VERIFIED verdict on an admitted finding with a fingerprint v2
- **THEN** The finding lifecycle state is CONFIRMED and confirmed_by is set to "human" in session files

#### Scenario: Person records MITIGATED verdict
- **WHEN** A person records a MITIGATED verdict on an admitted finding with a fingerprint v2
- **THEN** The finding lifecycle state is CONFIRMED and confirmed_by is set to "human" in session files

### Requirement: Overturning verdict moves finding back to OPEN
When a person records an UNVERIFIED or INVALIDATED verdict on a CONFIRMED finding, the system SHALL set its lifecycle state to OPEN and clear the confirmation adjudicator.

#### Scenario: Person invalidates confirmed finding
- **WHEN** A person records an INVALIDATED verdict on a CONFIRMED finding
- **THEN** The finding lifecycle state moves to OPEN and confirmed_by is cleared to None

#### Scenario: Person resets confirmed finding to UNVERIFIED
- **WHEN** A person records an UNVERIFIED verdict on a CONFIRMED finding
- **THEN** The finding lifecycle state moves to OPEN and confirmed_by is cleared to None

### Requirement: Lifecycle state transitions allow CONFIRMED to OPEN
The finding lifecycle state transition table SHALL allow transition from CONFIRMED to OPEN when a human verdict changes.

#### Scenario: Transition check allows CONFIRMED to OPEN
- **WHEN** can_transition is evaluated from FindingState.CONFIRMED to FindingState.OPEN
- **THEN** It returns True

### Requirement: Findings command displays finding state
`devops review findings --details` SHALL display the finding lifecycle state in finding detail panels.

#### Scenario: User inspects finding details
- **WHEN** A user runs `devops review findings --details` on a session containing findings
- **THEN** The output panel contains the finding lifecycle state
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Tasks

## 1. Lifecycle state transitions and models

- [x] 1.1 Write failing unit tests for `can_transition(FindingState.CONFIRMED, FindingState.OPEN)` and `SavedFinding` state fields. Verify with `uv run pytest tests/test_review_state.py`.
- [x] 1.2 Add `FindingState.OPEN` to `_VALID_TRANSITIONS[FindingState.CONFIRMED]` in `src/devops_cli/review/state.py`. Verify with `uv run pytest tests/test_review_state.py`.
- [x] 1.3 Add `state: FindingState` and `confirmed_by: str | None` fields to `SavedFinding` in `src/devops_cli/ai/review_schema.py`. Verify with `uv run pytest tests/test_resource_schemas.py`.

## 2. Adjudication verdict updates and mirroring

- [x] 2.1 Write failing unit tests for `apply_verdict` updating `state` and `confirmed_by` on human VERIFIED/MITIGATED and UNVERIFIED/INVALIDATED verdicts, and session mirroring. Verify with `uv run pytest tests/test_review_adjudication.py`.
- [x] 2.2 Update `apply_verdict` in `src/devops_cli/ai/review/verdicts.py` to set `state` and `confirmed_by` on human verdicts for findings with fingerprint v2, and reset on UNVERIFIED/INVALIDATED. Verify with `uv run pytest tests/test_review_adjudication.py`.
- [x] 2.3 Include `"state"` and `"confirmed_by"` in `_VERDICT_FIELDS` in `src/devops_cli/ai/review/adjudication.py`. Verify with `uv run pytest tests/test_review_adjudication.py`.
- [x] 2.4 Update `_sanitize_admitted_candidate` in `src/devops_cli/ai/review/pipeline.py` to copy `admitted.state` and `admitted.confirmed_by` to `sf`. Verify with `uv run pytest tests/test_review_adjudication.py`.

## 3. CLI reader and documentation

- [x] 3.1 Write failing test asserting `devops review findings --details` outputs finding lifecycle state for CONFIRMED findings. Verify with `uv run pytest tests/test_review.py`.
- [x] 3.2 Update `_build_finding_panel_lines` in `src/devops_cli/commands/review.py` to display finding lifecycle state and confirmed_by in detail panels. Verify with `uv run pytest tests/test_review.py`.
- [x] 3.3 Regenerate documentation with `uv run devops docs generate --sync-readme`. Verify with `git diff --exit-code docs/`.

## Workflow follow-up

- Archive the change after the project's review requirements are satisfied.
- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).
42 changes: 42 additions & 0 deletions openspec/specs/review-finding-state/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# review-finding-state Specification

## Purpose
Stores, validates and displays the lifecycle state and confirmation adjudicator of admitted review findings across session files and CLI reports.

## Requirements

### Requirement: Human valid verdict confirms admitted finding
When a person records a VERIFIED or MITIGATED verdict on an admitted finding that has a fingerprint v2, the system SHALL store its lifecycle state as CONFIRMED and record its confirmation adjudicator as human.

#### Scenario: Person records VERIFIED verdict
- **WHEN** A person records a VERIFIED verdict on an admitted finding with a fingerprint v2
- **THEN** The finding lifecycle state is CONFIRMED and confirmed_by is set to "human" in session files

#### Scenario: Person records MITIGATED verdict
- **WHEN** A person records a MITIGATED verdict on an admitted finding with a fingerprint v2
- **THEN** The finding lifecycle state is CONFIRMED and confirmed_by is set to "human" in session files

### Requirement: Overturning verdict moves finding back to OPEN
When a person records an UNVERIFIED or INVALIDATED verdict on a CONFIRMED finding, the system SHALL set its lifecycle state to OPEN and clear the confirmation adjudicator.

#### Scenario: Person invalidates confirmed finding
- **WHEN** A person records an INVALIDATED verdict on a CONFIRMED finding
- **THEN** The finding lifecycle state moves to OPEN and confirmed_by is cleared to None

#### Scenario: Person resets confirmed finding to UNVERIFIED
- **WHEN** A person records an UNVERIFIED verdict on a CONFIRMED finding
- **THEN** The finding lifecycle state moves to OPEN and confirmed_by is cleared to None

### Requirement: Lifecycle state transitions allow CONFIRMED to OPEN
The finding lifecycle state transition table SHALL allow transition from CONFIRMED to OPEN when a human verdict changes.

#### Scenario: Transition check allows CONFIRMED to OPEN
- **WHEN** can_transition is evaluated from FindingState.CONFIRMED to FindingState.OPEN
- **THEN** It returns True

### Requirement: Findings command displays finding state
`devops review findings --details` SHALL display the finding lifecycle state in finding detail panels.

#### Scenario: User inspects finding details
- **WHEN** A user runs `devops review findings --details` on a session containing findings
- **THEN** The output panel contains the finding lifecycle state
2 changes: 2 additions & 0 deletions src/devops_cli/ai/review/adjudication.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"invalidation_reason",
"citation_line",
"mitigating_mechanism",
"state",
"confirmed_by",
}
)

Expand Down
4 changes: 4 additions & 0 deletions src/devops_cli/ai/review/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ def _sanitize_admitted_candidate(
sf.location = format_location(admitted.path, admitted.line, admitted.end_line)
sf.fingerprint = getattr(admitted, "fingerprint_v2", "") or getattr(admitted, "fingerprint", "")
sf.producer = getattr(admitted, "tool", "")
if hasattr(admitted, "state"):
sf.state = admitted.state
if hasattr(admitted, "confirmed_by"):
sf.confirmed_by = admitted.confirmed_by
desc, title = sf.description, sf.title
if raw_path and raw_path != admitted.path:
desc = desc.replace(raw_path, admitted.path)
Expand Down
22 changes: 22 additions & 0 deletions src/devops_cli/ai/review/verdicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from typing import Any, Literal

from devops_cli.ai.review_schema import Finding, SavedFinding
from devops_cli.config.constants import CONST_VERIFIED_BY_HUMAN
from devops_cli.review.fingerprint import is_fingerprint_v2
from devops_cli.review.state import FindingState, assert_finding_state_invariants

# The labels a finding's status is settled under: a person's verdict, a vulnerability scan's
# match and a dry run's placeholder (#1150). `Finding.verified_by` is plain text, so a session
Expand Down Expand Up @@ -145,6 +148,21 @@ def _build_verdict_updates(
}


def _resolve_finding_state_updates(
finding: Any, norm_status: str, by: str | None
) -> dict[str, Any]:
"""Determine lifecycle state and confirmed_by updates for an adjudicated finding."""
fp = getattr(finding, "fingerprint_v2", None) or getattr(finding, "fingerprint", None)
has_fp_v2 = bool(fp and is_fingerprint_v2(str(fp)))
if norm_status in ("VERIFIED", "MITIGATED") and by == CONST_VERIFIED_BY_HUMAN and has_fp_v2:
return {"state": FindingState.CONFIRMED, "confirmed_by": "human"}
if norm_status in ("UNVERIFIED", "INVALIDATED") and (
hasattr(finding, "state") or hasattr(finding, "confirmed_by")
):
return {"state": FindingState.OPEN, "confirmed_by": None}
return {}


def apply_verdict[T: (Finding, SavedFinding)](
finding: T,
status: str,
Expand Down Expand Up @@ -177,6 +195,8 @@ def apply_verdict[T: (Finding, SavedFinding)](
# but an update does not, and criteria that passed twice once stored 2.0.
updates["confidence_score"] = min(1.0, max(0.0, confidence_score))

updates.update(_resolve_finding_state_updates(finding, norm_status, by))

for key, val in extra_updates.items():
if val is not None:
updates[key] = val
Expand All @@ -186,4 +206,6 @@ def apply_verdict[T: (Finding, SavedFinding)](
setattr(finding, key, val)

assert_verdict_invariants([finding])
if hasattr(finding, "state"):
assert_finding_state_invariants([finding])
return finding
14 changes: 14 additions & 0 deletions src/devops_cli/ai/review_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
NetworkReputationRecord,
VulnerabilityRecord,
)
from devops_cli.review.state import FindingState

# Constants & Configuration
_SEVERITY_RANK: dict[str, int] = {
Expand Down Expand Up @@ -970,10 +971,23 @@ class CitedCode(BaseModel):


class SavedFinding(Finding):
state: FindingState = FindingState.OPEN
confirmed_by: str | None = None
fingerprint: str = ""
producer: str = Field(default="", validation_alias=AliasChoices("producer", "persona"))
recommendation: str = "REQUEST CHANGES"

@field_validator("state", mode="before")
@classmethod
def _coerce_state(cls, v: Any) -> Any:
if v is None:
return FindingState.OPEN
if isinstance(v, str):
clean = v.upper().strip()
if clean in FindingState.__members__:
return FindingState(clean)
return v

@property
def persona(self) -> str:
return self.producer
Expand Down
5 changes: 5 additions & 0 deletions src/devops_cli/commands/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,11 @@ def _build_finding_panel_lines(f: Any) -> list[str]:
lines = [
f"[bold]Location:[/bold] [cyan]{escape_text(f.location)}[/cyan]{persona_badge}",
]
state = getattr(f, "state", None)
if state:
confirmed_by = getattr(f, "confirmed_by", None)
state_str = f"{state} (by {confirmed_by})" if confirmed_by else str(state)
lines.append(f"[bold]State:[/bold] [yellow]{escape_text(state_str)}[/yellow]")
if f.description:
clean_desc = escape_text(format_clean_text_field(f.description).strip())
lines.extend(["", "[bold]Description:[/bold]", clean_desc])
Expand Down
2 changes: 1 addition & 1 deletion src/devops_cli/review/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FindingState(StrEnum):
{FindingState.OPEN, FindingState.FIXED, FindingState.CONFIRMED}
),
FindingState.FIXED: frozenset({FindingState.OPEN}),
FindingState.CONFIRMED: frozenset({FindingState.FIXED}),
FindingState.CONFIRMED: frozenset({FindingState.FIXED, FindingState.OPEN}),
}


Expand Down
Loading
Loading