Repository navigation
Description
Problem or Motivation
The project review needs prose for the functional change, the lead paragraph and the incident summary. A model can put wrong numbers or invented issues into prose.
Proposed Solution & Architectural Design
- A pydantic-ai Agent with the output type
list[Statement{text, fact_ids, issue_refs}]. - Validators: no digit in the text; each fact id exists in
data.json; each issue number exists indata.json. Code puts in every number. - Calls: the functional change by capability, and the lead. The incident draft runs only when an incident trigger fires.
- Input projections: headings and change titles for large windows.
- One retry, then the data-only sentences and
devops_cli_project_review_narrative_total{result}. - The model is the DeepSeek flash route through the gateway (owner decision of 2026-11-11; Sonnet is on hold).
- A cap of 0.05 USD for each run: the run refuses a call whose estimate goes over the cap. Spend goes under the row
project_review. - The model timeout is shorter than the run deadline of the job.
- Prompt files under
src/devops_cli/ai/tasks/. - A "model-written" label with the model name on each paragraph.
Target Subsystem
SDLC, Git & PR Governance (src/devops_cli/roadmap/project_review/), with AI prompts in src/devops_cli/ai/tasks/.
Existing Tool Considered
pydantic-ai (in use) gives structured output and output validators. The gateway (in use) routes the model and counts the spend. The custom code is the validators and the fallback. Cost (estimate): about 150-250 lines with tests, one issue-size item, about 0.33-0.50 USD on the DeepSeek implement path and 1-2 days elapsed. Run cost: about 0.004 USD for each weekly run (about 44 K tokens in and 3.8 K out at 0.0784 and 0.2352 USD for each million tokens).
Acceptance Criteria
Tests with a stub model:
- a digit, an unknown fact id and an unknown issue number are refused;
- the fallback runs after 1 retry.
A golden test on the range v0.111.0..v0.112.1 with a recorded reply.
A weekly run costs 0.01 USD or less on the DeepSeek route, measured in the gateway counter, and records its spend under the row project_review.
Dependencies
- feat(roadmap): render the project review as an HTML page #4720 feat(roadmap): render the project review as an HTML page.
Source: #4679
Alternatives check of 2026-11-29: in-use.
The repository already uses this tool.
Tool: pydantic-ai (https://github.com/pydantic/pydantic-ai), MIT, last activity 2026-11-29, maintained.
Reason: Searches found no library that grounds model prose in verified fact ids; pydantic-ai gives the typed statement output and the output-validator retry path, while the digit/fact-id checks, fallback, metric and cost cap stay project code.
Covers:
- Typed output as list[Statement] from a pydantic model
- Output validators that raise ModelRetry and retry once
- Agent built by the shared build_agent factory
- Prompt and settings plumbing already used by other tasks
Lacks:
- No digit-free text rule or fact-id and issue-number checks
- No data-only fallback after a refused retry
- No per-run cost cap or project_review spend row
- No narrative result metric or model-written label
- No input projection to headings and change titles
Proposed design
Problem statement
The project review needs prose for the functional change and the lead paragraph. A model can put a wrong number or an invented issue into that prose. This change adds a model-written narrative that cites checked facts and issue numbers, refuses a digit in the text and an unknown fact id or issue number, renders every number from the cited fact, and falls back to the data-only sentences after one retry. The incident summary and the weekly job are deferred to separate issues.
Acceptance criteria
Requirement: Structured statement output
The narrative agent SHALL return a list of statements, and each statement SHALL hold the text, the fact ids and the issue references.
Scenario: Stub model returns two valid statements
- WHEN the stub model returns two statements whose fact ids and issue numbers exist in the review data
- THEN the narrative holds two statements and each statement keeps its text, fact ids and issue references
Requirement: No digit in the text
The validator MUST refuse a statement whose text holds a digit.
Scenario: Statement text with a digit
- WHEN the stub model returns a statement whose text holds the digit 7
- THEN the validator refuses the reply and the agent makes one retry
Requirement: Fact id must exist
The validator MUST refuse a statement whose fact id is absent from the review data.
Scenario: Unknown fact id
- WHEN the stub model returns a statement with fact id
f-9999that the review data does not hold - THEN the validator refuses the reply
Requirement: Issue number must exist
The validator MUST refuse a statement whose issue number is absent from the review data.
Scenario: Unknown issue number
- WHEN the stub model returns a statement with issue number 999999 that the review data does not hold
- THEN the validator refuses the reply
Requirement: Code renders each number
The narrative SHALL put each number into the paragraph from the fact that the statement cites.
Scenario: Count rendered from the cited fact
- WHEN a statement cites a fact with the count 12 and its text holds no digit
- THEN the rendered paragraph holds 12 and the model text holds no digit
Requirement: Fallback after one retry
The narrative MUST use the data-only sentences after one refused retry.
Scenario: Two refused replies
- WHEN the stub model returns a refused reply on the first and the second attempt
- THEN the narrative holds the data-only sentences and makes no third model call
Requirement: Narrative metric
The narrative SHALL count each run in devops_cli_project_review_narrative_total with the label result.
Scenario: Fallback counted
- WHEN the stub model returns a refused reply twice
- THEN the metric counts one with
result="fallback"and no count withresult="model"
Requirement: Large window projection
The narrative MUST project the input to the headings and the change titles when the projected input goes over the task's context window.
Scenario: Large window
- WHEN the projected input goes over the context window of the task
project_review - THEN the model input holds the headings and the change titles and no change body
Requirement: Cost cap
The run MUST refuse a model call whose cost estimate goes over the cap of 0.05 USD.
Scenario: Estimate over the cap
- WHEN the cost estimate of the call is 0.06 USD
- THEN the run makes no call and the narrative uses the data-only sentences
Requirement: Spend row
The run MUST record the spend of each accepted call under the stage project_review.
Scenario: Spend recorded on an accepted call
- WHEN the stub gateway accepts one call with the cost 0.004 USD
- THEN the spend ledger holds one record with the stage
project_reviewand the cost 0.004 USD
Requirement: Model-written label
The narrative SHALL label each model-written paragraph with model-written and the model name.
Scenario: Lead paragraph from the model
- WHEN the model writes the lead paragraph
- THEN the paragraph carries the label
model-writtenwith the model name
Requirement: Run cost
A run MUST cost 0.01 USD or less on the DeepSeek route.
Scenario: Cost from the recorded tokens
- WHEN a run uses 44 K input tokens and 3.8 K output tokens at 0.0784 and 0.2352 USD for each million
- THEN the cost is 0.0043 USD, at or below 0.01 USD
Requirement: Golden test
A golden test SHALL compare the narrative for the range v0.111.0..v0.112.1 with a recorded reply.
Scenario: Recorded reply replay
- WHEN the golden test replays the recorded reply for the range v0.111.0..v0.112.1
- THEN the narrative matches the recorded expected output
Requirement: Model route
The narrative MUST request the model that the settings of task project_review name.
Scenario: Stub gateway records the model
- WHEN the settings of task
project_reviewnamedeepseek-v4.1-flash-1017and the narrative sends a call - THEN the stub gateway records the model
deepseek-v4.1-flash-1017
Requirement: Prompt files
The narrative MUST load its prompt through load_task_prompt from a file under src/devops_cli/ai/tasks/.
Scenario: Prompt loaded from the task folder
- WHEN the narrative builds its prompt for the task
project_review - THEN the loader reads a prompt file under
src/devops_cli/ai/tasks/
Existing Tool Considered
pydantic-ai (https://github.com/pydantic/pydantic-ai) is in use; the alternatives check of 2026-11-23 in the issue body gives the verdict and lists what it covers and lacks. The proposal adds the missing project code. That code is the no-digit, fact-id and issue-number validators, the data-only fallback, the metric, the label and the cost cap. That code costs about 150-250 lines with tests, about 0.33-0.50 USD of tokens on the DeepSeek implement path, and 1-2 days elapsed. A run costs about 0.004 USD.
Key questions
- Which structured-output mechanism does the narrative use?: A pydantic-ai Agent built by
build_agentwith the output typelist[Statement]and anoutput_validatorthat raisesModelRetry.Statementholdstext,fact_idsandissue_refs. (best practice) [sources: src/devops_cli/ai/client/factory.py, src/devops_cli/roadmap/refine/refine_investigation.py, src/devops_cli/exceptions/ai_pydantic.py]- Chosen: pydantic-ai structured output. The repository already uses it, and it gives the typed output, the output validators and the retry path.
- Rejected: Guardrails AI output validators. It needs the same custom fact and digit validators and adds a dependency.
- Rejected: Hand-written JSON parsing of a free-text reply. It gives no typed output and no retry path, so the custom code grows.
- How does the narrative keep every number correct?: The validator refuses a statement whose text holds a digit. Code puts each number into the paragraph from the fact that the statement cites, so the model writes no number and cannot write a wrong one. (best practice) [sources: src/devops_cli/roadmap/project_review/data.py, src/devops_cli/roadmap/project_review/facts.py]
- Chosen: No-digit rule and code renders the numbers. The model cannot put a wrong number into the prose, because the model writes no number.
- Rejected: The model writes the numbers and a checker compares them. The checker must parse the prose, and each mismatch costs another call.
- Rejected: A post-edit pass removes the numbers. It leaves a sentence that lost its number, and the reader sees a gap.
- What does the narrative do after one refused retry?: It uses the data-only sentences and counts the run in the metric. The one-retry limit follows
_retry_onceof the refine investigation, which raisesModelRetryfor the first refused reply only. (best practice) [sources: src/devops_cli/roadmap/refine/refine_investigation.py, src/devops_cli/ai/client/factory.py, src/devops_cli/exceptions/ai_pydantic.py]- Chosen: One retry, then the data-only sentences. It bounds the calls and the spend, and the page still holds the checked facts.
- Rejected: No retry. A transient reply error loses the prose on every run.
- Rejected: Three retries. Each retry costs a call and can go over the 0.05 USD cap.
- Which values does the
resultlabel ofdevops_cli_project_review_narrative_totalhold?:modelfor a reply that passes, andfallbackfor the data-only sentences. One counter with oneresultlabel follows theresultlabel ofdevops_cli_roadmap_page_fetches_total. (best practice) [sources: src/devops_cli/telemetry/instruments.py, docs/TELEMETRY.md]- Chosen: One counter with the label
result. One metric name holds both paths, and a query divides one by the other. - Rejected: One counter for each path. Two metric names need two queries and drift apart.
- Chosen: One counter with the label
- Which model route does the narrative call?: The DeepSeek flash route through the gateway,
deepseek-v4.1-flash-1017. Sonnet stays on hold: the owner holdsclaude-sonnet-5-5since 2026-11-11. (best practice) [sources: SECURITY.md, k8s/devops/configmap.example.yaml]- Chosen: DeepSeek flash through the gateway. The owner decision of 2026-11-11 sets this route, and the gateway counts the spend.
- Rejected: Claude Sonnet through the gateway. The owner put Sonnet on hold.
- What cost cap and spend row does a run use?: A run refuses a call whose estimated cost goes over 0.05 USD. The estimate comes from
PricingRegistry.calculate_request_coston the token estimate. The spend goes under the stageproject_review, which the settings declare as the taskai.tasks.project_review. (best practice) [sources: src/devops_cli/ai/spend/pricing.py, src/devops_cli/ai/spend/stage.py, src/devops_cli/config/settings.py]- Chosen: A cap of 0.05 USD for each run and the stage
project_review. A large window cannot spend without limit, and the row separates this spend from the other AI spend. - Rejected: No cap. A long window can spend without limit on a weekly schedule.
- Chosen: A cap of 0.05 USD for each run and the stage
- Where do the prompt files live?: Under
src/devops_cli/ai/tasks/, loaded byload_task_prompt. The narrative adds its prompt files there beside the other task prompts. (best practice) [sources: src/devops_cli/ai/task_loader.py]- Chosen: Task prompt files under
src/devops_cli/ai/tasks/. The prompts sit with the other AI task prompts and stay out of the validator code. - Rejected: Inline prompts in the narrative module. It mixes prompt text with the validators and the fallback.
- Chosen: Task prompt files under
- What input does a large window send to the model?: The headings and the change titles only, when the projected input goes over the context window of the task
project_review. The facts are already aggregated, so the model needs no change body. (best practice) [sources: src/devops_cli/ai/context_packer.py, docs/CONFIGURATION.md, src/devops_cli/roadmap/project_review/facts.py]- Chosen: Headings and change titles. It keeps the input inside the window of the model.
- Rejected: The full change bodies. The input goes over the window and the call fails.
- How does a model-written paragraph carry the label?: Each model-written paragraph holds the label
model-writtenand the model name. The review's model analysis section already marks its textModel-Writtenand keeps it apart from the tool-verified findings. (best practice) [sources: src/devops_cli/review/analysis.py]- Chosen: A label field on each paragraph. A reader tells which paragraph the model wrote.
- Rejected: One footnote at the end of the page. A reader cannot tell which paragraph the model wrote.
Fit
Fits in one pull request.
Suspected block
None.
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
featprefix of the title gives the type.(roadmap)scope of the title gives the scope.Improves review narrative quality but is not critical and depends on #4720.Adds model-written narrative to project reviews but is not essential to core functionality.Estimated 150-250 lines with tests and 1-2 days of work.Both ground model output in verified facts, but the candidate writes roadmap project review prose while 1137 reviews code changes.dan-petty commentedon Nov 12, 2026
Scope change for #5219 (the self-improvement section of the project review):
self_improvementthat holds a digit. That acceptance criterion moves from feat(roadmap): report job grades and fix effects in the project review #5219 to this item.#5219 does not wait for this item.
devops-cli-service commentedon Nov 14, 2026
Alternatives check: in-use
Reason: Searches found no tool that grounds narrative prose in checked facts; the closest, pydantic-ai (already in use here), gives the structured Statement output, output validators and a retry path, so it covers the model call and refusal half of the item. The checks against data.json, the no-digit rule, the fallback after one retry, the metric and the cost cap remain custom code; Guardrails AI also offers output validators with re-asks but needs the same custom fact and digit validators.
The repository already uses this tool.
Tool: pydantic/pydantic-ai (https://github.com/pydantic/pydantic-ai)
Covers:
Lacks:
Tools considered:
Searches run:
Sources:
Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 15, 2026
Refine cannot set this item to Ready at a8a99cb while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.
devops-cli-service commentedon Nov 26, 2026
Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.