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-11-14
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Design

## Decisions
- **Remove dead guard instead of adding checked accessor**: The decision model (`SystemOneModel.decide`) already refuses a partial reply before intake reads it, and `FAILED` holds `UnexpectedModelBehavior`, so both modes fail open. Adding a checked accessor would serve an unreachable path (AGENTS.md rule 2). Removing the dead guard removes dead code.
- **Reference duplicate prefix only in `intake_jev.py`**: Do not repeat the `"duplicate_of_"` literal in `intake_jev_shadow.py`. `best_neighbour` already accesses the prefix defined in `intake_jev.py`.
- **Docstring accuracy**: Clarify in `observation_of` docstring that `ShadowError` applies to missing or wrong-kind choice and score answers, and that the underlying decision model refuses partial replies.

## Rejected alternatives
- **Add checked accessor**: Rejected because `SystemOneModel` already raises `UnexpectedModelBehavior` for partial replies, so intake never receives them.
- **Close as not planned**: Rejected because the dead guard and incorrect docstring would remain in the codebase.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Proposal: #4450 fix(roadmap): a partial Jev reply stops the intake round

## Why
A partial or wrong-kind Jev reply does not stop the intake round. The decision model raises `UnexpectedModelBehavior` before intake reads the reply, and `FAILED` holds that error, so both modes fail open. The shadow module still holds a guard that checks nothing: `_answer_of(response, f"duplicate_of_{each.number}", object)` cannot fail, because `isinstance(None, object)` is true. Its docstring also says that a missing answer raises `ShadowError`, but only the choice and score answers are checked. Closes #4450.

## What Changes
- Remove the no-op loop and dead guard `_answer_of(..., object)` from `_duplicate` in `src/devops_cli/roadmap/intake/intake_jev_shadow.py`.
- Remove the repeated `duplicate_of_` string literal from `intake_jev_shadow.py`.
- Update the docstring of `observation_of` to correctly state that `ShadowError` is raised for a missing or wrong-kind choice or score answer, and that the decision model refuses a partial reply.
- Add tests to verify that `_duplicate` holds no `duplicate_of_` literal or `_answer_of` call of kind `object`, that `observation_of` raises `ShadowError` on missing priority answer, and that the docstring matches the behavior.

## Capabilities
- `roadmap-intake-jev`: shadow duplicate check and answer error verification.

## Impact
- Eliminates dead guard code and misleading docstrings in `intake_jev_shadow.py`.
- No breaking API changes; internal implementation cleanup only.

## Feasibility
- Verified in `src/devops_cli/roadmap/intake/intake_jev_shadow.py`: `isinstance(None, object)` evaluates to True, making the guard a no-op.
- Verified that `SystemOneModel.decide` enforces complete answers and matching kinds, raising `UnexpectedModelBehavior` before intake processes the response.

## Existing Tool Considered
`pydantic-ai` covers the need: `SystemOneModel.decide` raises `UnexpectedModelBehavior` when answer names or kinds differ from questions. The project builds no new code beyond removing the 3-line dead guard and updating docstrings.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# roadmap-intake-jev Specification

## ADDED Requirements

### Requirement: Shadow duplicate check
The shadow duplicate check SHALL read the nearest item only through `best_neighbour` from `intake_jev.py`, and SHALL NOT hold a `duplicate_of_` literal or an answer guard of kind `object`.

#### Scenario: Shadow duplicate answer name
- **WHEN** A test reads `_duplicate` in `intake_jev_shadow.py`.
- **THEN** The function calls `best_neighbour`, holds no `duplicate_of_` literal, and holds no `_answer_of` call whose kind is `object`.

### Requirement: Shadow answer error
`observation_of` SHALL raise `ShadowError` when a choice or score answer is missing or has a wrong kind.

#### Scenario: Missing priority answer
- **WHEN** `observation_of` receives a response with no `priority` answer.
- **THEN** `observation_of` raises `ShadowError`.

### Requirement: Shadow docstring
The docstring of `observation_of` SHALL name `ShadowError` as the error of a missing or wrong-kind choice or score answer, and SHALL state that the decision model refuses a partial reply.

#### Scenario: Docstring names the error and the model check
- **WHEN** A test reads the docstring of `observation_of`.
- **THEN** The docstring names `ShadowError` and does not say that a missing duplicate answer raises it.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Tasks

## 1. Behavior

- [x] 1.1 Add tests for shadow duplicate check, missing choice answer error, and docstring
- Verification: `$ uv run pytest -n 0 tests/roadmap/intake/test_roadmap_intake_jev_shadow.py`
- [x] 1.2 Remove dead guard in `_duplicate` and update docstring in `observation_of` in `src/devops_cli/roadmap/intake/intake_jev_shadow.py`
- Verification: `$ uv run pytest -n 0 tests/roadmap/intake/test_roadmap_intake_jev_shadow.py`

## 2. Documents

- [x] 2.1 Verify OpenSpec change and docs
- Verification: `$ uv run devops ci docs`
21 changes: 21 additions & 0 deletions openspec/specs/roadmap-intake-jev/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,24 @@ Mode `shadow` SHALL count in the counter of mode `on`, `devops_cli_roadmap_intak
#### Scenario: A probability of 1
- **WHEN** a valid mark holds the probability 1.0
- **THEN** the report counts it in the last band

### Requirement: Shadow duplicate check
The shadow duplicate check SHALL read the nearest item only through `best_neighbour` from `intake_jev.py`, and SHALL NOT hold a `duplicate_of_` literal or an answer guard of kind `object`.

#### Scenario: Shadow duplicate answer name
- **WHEN** A test reads `_duplicate` in `intake_jev_shadow.py`.
- **THEN** The function calls `best_neighbour`, holds no `duplicate_of_` literal, and holds no `_answer_of` call whose kind is `object`.

### Requirement: Shadow answer error
`observation_of` SHALL raise `ShadowError` when a choice or score answer is missing or has a wrong kind.

#### Scenario: Missing priority answer
- **WHEN** `observation_of` receives a response with no `priority` answer.
- **THEN** `observation_of` raises `ShadowError`.

### Requirement: Shadow docstring
The docstring of `observation_of` SHALL name `ShadowError` as the error of a missing or wrong-kind choice or score answer, and SHALL state that the decision model refuses a partial reply.

#### Scenario: Docstring names the error and the model check
- **WHEN** A test reads the docstring of `observation_of`.
- **THEN** The docstring names `ShadowError` and does not say that a missing duplicate answer raises it.
5 changes: 2 additions & 3 deletions src/devops_cli/roadmap/intake/intake_jev_shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def _score(
def _duplicate(
request: ProposalRequest, response: DecisionResponse, original: int | None
) -> ShadowAnswer:
for each in request.shortlist:
_answer_of(response, f"duplicate_of_{each.number}", object)
near, probability = best_neighbour(request, response)
flagged = near is not None and probability >= CONST_ROADMAP_JEV_DUPLICATE_THRESHOLD
return ShadowAnswer(
Expand All @@ -141,7 +139,8 @@ def observation_of(
at: datetime,
) -> ShadowObservation:
"""The observation for the `response` of Jev and the `triage` reply, whose checked possible
original is `original`. A missing answer raises `ShadowError`."""
original is `original`. A missing or wrong-kind choice or score answer raises `ShadowError`;
the decision model refuses a partial reply."""
answers: dict[str, ShadowAnswer] = {}
if request.needs_type:
answers[JevField.TYPE] = _choice(response, JevField.TYPE, triage.type)
Expand Down
42 changes: 40 additions & 2 deletions tests/roadmap/intake/test_roadmap_intake_jev_shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

from __future__ import annotations

import inspect
from datetime import UTC, datetime
from typing import TYPE_CHECKING

import httpx2
import pytest
from pydantic import ValidationError
from pydantic_ai.models.decision import DecisionResponse

from devops_cli.config.constants import CONST_ROADMAP_JEV_DUPLICATE_THRESHOLD
from devops_cli.config.settings import (
Expand All @@ -20,8 +22,19 @@
from devops_cli.exceptions.security import SecurityError
from devops_cli.roadmap.intake.intake import NewCandidate, Outcome
from devops_cli.roadmap.intake.intake_jev import JevIntakeModel
from devops_cli.roadmap.intake.intake_jev_shadow import ShadowIntakeModel, ShadowObservation
from devops_cli.roadmap.intake.intake_model import GatewayIntakeModel, build_intake_model
from devops_cli.roadmap.intake.intake_jev_shadow import (
ShadowError,
ShadowIntakeModel,
ShadowObservation,
_duplicate,
observation_of,
)
from devops_cli.roadmap.intake.intake_model import (
GatewayIntakeModel,
ModelProposal,
ProposalRequest,
build_intake_model,
)
from devops_cli.roadmap.intake.intake_requests import SpendMeter
from devops_cli.roadmap.stores.store import IntakeRecordKey
from tests.support.roadmap_intake import FakeModel, Roadmap
Expand Down Expand Up @@ -322,3 +335,28 @@ def test_the_setting_is_off_by_default_and_refuses_the_old_bool() -> None:
RoadmapIntakeConfig(jev=True)

assert raised.value.errors()[0]["loc"] == ("jev",)


def test_shadow_duplicate_check_calls_best_neighbour_and_holds_no_dead_guard() -> None:
source = inspect.getsource(_duplicate)
assert "best_neighbour" in source
assert "duplicate_of_" not in source
assert "_answer_of" not in source


def test_observation_of_raises_shadow_error_on_missing_priority_answer() -> None:
request = ProposalRequest(
title="feat: cache", body="body", needs_type=False, shortlist=(), types=()
)
response = DecisionResponse(answers={}, model_name="mock")
triage = ModelProposal(type="type/feature", priority="P2-Medium", value="Medium", effort="Low")
with pytest.raises(ShadowError, match="priority"):
observation_of(request, response, triage, original=None, at=AT)


def test_the_docstring_of_observation_of_names_the_error_and_the_model_check() -> None:
doc = observation_of.__doc__ or ""
assert "ShadowError" in doc
assert "decision model refuses a partial reply" in doc
assert "missing duplicate answer" not in doc.lower()
assert "duplicate" not in doc.lower()