Repository navigation
Description
Problem or Motivation
Every live Jev path builds a DecisionRequest by hand and calls DecisionModel.decide() directly:
stage.verify_screenthroughsrc/devops_cli/roadmap/decision_step.py:137-207,- intake through
src/devops_cli/roadmap/intake/intake_jev.py:316-323, - the helpers in
src/devops_cli/ai/jev.py:165-219.
Around these calls, we keep our own event-loop glue: an anyio blocking portal (jev.py), asyncio.run with a client close for each request (decision_step.py), and asyncio.run for each call (intake). This glue failed three times: #4319, #4513, and item 2 of #5272 (asyncio.run inside a running loop).
A direct decide() call gets none of the parts that the pydantic-ai base class gives on the Agent path (pydantic_ai/models/decision.py:546-562,591-594,655-656 in 2.59.0; SystemOneModel.decide checks no limits):
- no
decidespan with the questions, answers, confidence, thresholds and usage, - no limit check before the request,
- no
RunUsage, so the spend hook ofbuild_agentdoes not see the call (feat(ai): record the cost of Jev calls that pass through the gateway #4296), - no check that every asked answer came back. fix(roadmap): a partial Jev reply stops the intake round #4450 found a partial reply that stops the intake round. The Agent path raises
UnexpectedModelBehaviorfor that case.
The documents name the Agent path as the normal integration:
- "Prefer an output type with fields to a bare output with its question in instructions: each field carries its own question" (https://pydantic.dev/docs/ai/models/decision/#where-the-wording-comes-from)
- For a backend, "the base class does everything else on this page" (https://pydantic.dev/docs/ai/models/decision/#implementing-a-decision-model)
- "a field whose bar you would want to vary per call is often better declared that way [float, ge=0, le=1], and compared in your own code" (https://pydantic.dev/docs/ai/models/decision/#what-true-has-to-mean)
- Every request that a decision model sends "gets a decide span" (https://pydantic.dev/docs/ai/models/decision/, Tracing)
Proposed Solution & Architectural Design
Move the live calls to Agent(SystemOneModel, output_type=...):
stage.verify_screen: an output model with one bounded float field (Field(ge=0, le=1)) for each question. The field description holds the question.band_ofkeeps the raw probabilities and compares them with the fitted cuts in our code.- Intake Value and Effort: an
IntEnumrubric for each field. - Intake type: an
EnumwithUseEnumMemberDocstrings, so that each member docstring is the option text. - Intake duplicates: a list field over the shortlist options.
devops ai ask-jev: the same path, with an output type that the kind of question selects.- Callers: an async caller uses
await agent.run(...). A sync caller usesagent.run_sync(...), which keeps one loop for each thread.run_syncstill fails inside a running loop, so a caller in a loop must use the async form. - Glue: delete the portal and the
asyncio.runglue that the move makes unused. - Telemetry: keep content off in the spans, under the telemetry privacy default (cluster OTel only, no prompt or tool content;
InstrumentationSettings(include_content=False)). The span keeps the names, the probabilities, the thresholds and the usage. - Refit: the field descriptions change the request text, so the cuts of
stage.verify_screenneed a new fit. Do this move with the question rewrite of feat(roadmap): ask the verify screen one atomic question each #5281, and fit one time (feat(roadmap): the verify screen records serious findings for a live fit #5273).
Files: src/devops_cli/ai/jev.py, src/devops_cli/ai/jev_ask.py, src/devops_cli/roadmap/decision_step.py, src/devops_cli/roadmap/decision_point.py, src/devops_cli/roadmap/intake/intake_jev.py, src/devops_cli/roadmap/stage/stage_jev_screen.py, tests/ai/, tests/roadmap/.
Target Subsystem
AI & Agentic Review Pipeline (src/devops_cli/ai/, and the decision points in src/devops_cli/roadmap/).
Existing Tool Considered
pydantic-ai's own decision-model support: Agent with SystemOneModel and an output_type (pinned 2.59.0). The project rule is to integrate open tools, not to keep custom glue. This item deletes glue and builds no new tool. Cost: about 0.8M tokens and 6 hours.
Acceptance Criteria
- A test with the
JevFaketransport:stage.verify_screenruns throughAgent.runand gives the band from the raw probabilities of the reply. - A test: a decision called inside a running event loop with the fake gives a decision, not
RuntimeError. - A test: a reply with one missing answer gives the fallback (intake: triage; decision point: band
none), notKeyError. - A test: one call adds its input and output tokens to
RunUsage, and the spend hook sees the call. - A test: the span of a call holds the probabilities, and no state text and no question text.
-
git grep -nE "asyncio\.run|blocking_portal|BlockingPortal" -- src/devops_cli/ai/jev.py src/devops_cli/roadmap/decision_step.py src/devops_cli/roadmap/intake/intake_jev.pyreturns nothing.
Related
- feat(roadmap): ask the verify screen one atomic question each #5281: the question rewrite. Do one refit after both items.
- feat(roadmap): the verify screen records serious findings for a live fit #5273: the live fit of the cuts.
- refactor(roadmap): put every decision point on one registry #5275: one registry for every decision point.
- fix(roadmap): decision points need cuts for shadow and run in async code #5272: item 2 (
asyncio.runin a running loop) goes away for the live paths. - fix(roadmap): a partial Jev reply stops the intake round #4450: a partial reply stops the intake round.
- feat(ai): record the cost of Jev calls that pass through the gateway #4296: the Agent path gives
RunUsagefor the spend record. - refactor(ai): remove the Jev helpers that nothing calls #5276: removes the helpers that nothing calls.
- chore(roadmap): track the decision model workflows #4408: the tracker of the decision model workflows.
Alternatives check of 2026-11-16: not-applicable.
Class: refactor, no search.
Tool: none found.
Proposed design
Problem statement
The live Jev paths build a DecisionRequest by hand and call DecisionModel.decide() directly. Each path keeps its own event-loop glue, and that glue failed three times (#4319, #4513, #5272 item 2). A direct call gets no decide span, no limit check, no RunUsage and no check that every asked answer came back; the decision points also record no Jev spend. This change moves the live calls to Agent with SystemOneModel and an output_type, uses build_agent so the spend hook sees each call, deletes the glue, and leaves the cut refit to #5273.
Acceptance criteria
Requirement: The screen answers through the Agent output
stage.verify_screen SHALL send its questions through the Agent path with one bounded float field for each question, and SHALL give the band from the raw probabilities and the fitted cuts.
Scenario: The fake reply gives the band
- WHEN A test runs the screen through
build_agentwith theJevFaketransport that answers 0.9 to the flag question and 0.1 to each other question. - THEN The record holds each raw probability of the reply, and its band equals the band that
band_ofgives for those probabilities and the cuts of the point.
Requirement: A decision inside a running loop
A decision point SHALL return its decision when a caller awaits it inside a running event loop, and SHALL NOT raise RuntimeError.
Scenario: Await inside a loop
- WHEN A test awaits
ResolverChain.adecideinside a running event loop with theJevFaketransport. - THEN The call returns a
DecisionRecordand raises noRuntimeError.
Requirement: A missing answer gives the fallback band
A reply that misses one asked answer SHALL give the fallback band (None, counted as none) with resolver fallback, not KeyError.
Scenario: Partial reply of a decision point
- WHEN The
JevFaketransport answers one of two asked questions. - THEN
ResolverChain.adeciderecords no band with resolverfallback, and raises noKeyError.
Requirement: A missing answer gives the intake fallback
A reply that misses one asked intake answer SHALL give the triage result, not KeyError.
Scenario: Partial reply of intake
- WHEN The
JevFaketransport answers one of the asked intake questions. - THEN Intake records
triageand raises noKeyError.
Requirement: The run usage reaches the spend hook
One Jev call SHALL add its input and output tokens to the run's RunUsage, and the spend hook of build_agent SHALL record the call.
Scenario: One call is spent
- WHEN A test runs one decision through
build_agentwith theJevFaketransport, which reports 64 input tokens and one output token for its one answer, and a spend ledger. - THEN The run's usage holds 64 input tokens and 1 output token, and the ledger holds one row for the call.
Requirement: The span keeps no content
The span of a Jev call SHALL hold the question names, the probabilities, the thresholds and the usage, and SHALL hold no state text and no question text.
Scenario: The span holds no text
- WHEN A test runs one decision with
InstrumentationSettings(include_content=False)and captures the span. - THEN The span attributes hold the question names, the probabilities, the thresholds and the usage, and no attribute holds the text of the digest or of a question.
Requirement: No event-loop glue stays
The live Jev modules SHALL NOT use asyncio.run, blocking_portal or BlockingPortal.
Scenario: The three modules hold no glue
- WHEN A test reads the source of
src/devops_cli/ai/jev.py,src/devops_cli/roadmap/decision_step.pyandsrc/devops_cli/roadmap/intake/intake_jev.py. - THEN No line of those modules holds
asyncio.run,blocking_portalorBlockingPortal.
Requirement: ask-jev answers each kind
devops ai ask-jev SHALL send its one question through the Agent path with an output type that the kind selects.
Scenario: Each kind gives its typed answer
- WHEN A test calls
ask_jevfor thechoice, thenouland thescorekind with theJevFaketransport. - THEN Each call returns a
JevAnswerthat holds the answer and the probabilities of the reply.
Requirement: Intake reads the enum answers
Intake SHALL read the Value, the Effort, the type and the duplicate answers from the enum and list fields of one output model.
Scenario: Enum and list answers
- WHEN The
JevFaketransport answers each enum field with one of its members and the duplicate list with one shortlist option. - THEN The intake record holds that member for each field and that option in the duplicate list.
Existing Tool Considered
pydantic-ai 2.75.0, pinned at pyproject.toml:40 and locked at uv.lock:3557-3558, covers the need. Agent with SystemOneModel and an output_type gives the decide span, the limit check, RunUsage and the missing-answer check, and build_agent adds the project's spend hook (src/devops_cli/ai/client/factory.py:183-250,253-300). It lacks no integration piece; the only follow-up is the cut refit of #5273 because the field descriptions change the request text. The change builds no tool of its own. Its written cost is about 0.8M tokens and 6 hours. The alternatives check of 2026-11-16 in the issue body gave not-applicable with Tool: none found; it is a refactor check and made no search.
Key questions
- How do the live Jev paths call the model now, and what does a direct
decide()call lack?:src/devops_cli/ai/jev.pysends each request through the blocking portal.src/devops_cli/roadmap/decision_step.pycloses the client on the loop of each request.src/devops_cli/roadmap/intake/intake_jev.pysends from a sync_decidewithasyncio.run. A direct call gets nodecidespan, no limit check, noRunUsageand no missing-answer check. [sources: src/devops_cli/ai/jev.py:125-143,189-210, src/devops_cli/roadmap/decision_step.py:188-223,244-277, src/devops_cli/roadmap/intake/intake_jev.py:259-269,321-328] - Which pydantic-ai version does the project pin?: 2.75.0.
pyproject.toml:40pinspydantic-ai[spec]==2.75.0, anduv.lock:3557-3558lockspydantic-ai2.75.0. The issue body's 2.59.0 is stale. [sources: pyproject.toml:40, uv.lock:3557-3558] - What does the spend ledger hold for a Jev decision point now?: The decision points record no Jev spend now.
_decide_closingand_decide_onecalldecider.decideand do not callrecord_jev_spend; onlydecide_with_jev(jev.py:209) and intake's_decide_in_context(intake_jev.py:268) call it. The template comment atk8s/devops/configmap.example.yaml:71-73says the client records each Jev decision call, which is false for these points. [sources: src/devops_cli/roadmap/decision_step.py:188-223, src/devops_cli/ai/jev.py:209, src/devops_cli/roadmap/intake/intake_jev.py:268, k8s/devops/configmap.example.yaml:71-73] - Does this item need the separate small fix for decision-point spend?: No. This item moves the decision points to the Agent spend hook, so the separate fix would be deleted. A small fix can come first only if this item waits. The spend test uses a fake that reports tokens; the live zero usage does not block the refactor. (best practice) [sources: src/devops_cli/roadmap/decision_step.py:188-223, src/devops_cli/ai/spend/ledger.py:1090-1094, k8s/devops/configmap.example.yaml:71-73]
- Chosen: Let this refactor record the spend through the Agent hook. It removes the direct call and records spend in one change. The small fix would be deleted by this refactor.
- Rejected: Add
record_jev_spendafterdecider.decideindecision_step.pynow. It is a second fix on a path that this refactor replaces. Use it only if this item waits.
- Does the Agent path carry a decision request, and what does it add?: Yes. The decision-model page says an agent runs on a decision model like any other model, each field of
output_typebecomes one question, and a Pydantic model with several fields extracts several values in one request. The project pins pydantic-ai 2.75.0, not the 2.59.0 of the issue body. The issue's cited library lines name thedecidespan, the limit check,RunUsageand theUnexpectedModelBehaviorerror for a missing answer;build_agentadds the project spend hook. [sources: pyproject.toml:40, uv.lock:3557-3558, src/devops_cli/ai/client/factory.py:183-250,253-300] - Which output type carries the
stage.verify_screenanswers?: One float field for each question, bounded withField(ge=0, le=1), with the question in the field description.band_ofkeeps the raw probabilities and compares them with the fitted cuts. (best practice) [sources: src/devops_cli/roadmap/stage/stage_jev_screen.py:63-88,172-183, src/devops_cli/roadmap/decision_step.py:163-176]- Chosen: Bounded float for each question. The cut of each question differs and the fit sets it. The page says a field whose bar varies per call is better as a float and compared in your own code.
- Rejected: IntEnum rubric for each question. A rubric gives a level.
band_ofneeds the probability that the cuts compare. - Rejected: Bare output with the question in the instructions. The page says each field carries its own question.
- Which output type carries the closed-label answers of intake?: One output model holds an
IntEnumfor Value and for Effort, anEnumwithUseEnumMemberDocstringsfor the type, and a list field over the shortlist options for the duplicates. Each member docstring is the option text. (best practice) [sources: src/devops_cli/roadmap/intake/intake_jev.py:133-158,232-249]- Chosen: Enum and IntEnum fields in one output model. Each field is a closed set of labels. The member is the answer and no cut is needed.
- Rejected: Bounded floats with fitted cuts. The fields are labels, not probabilities. No fit varies their bar.
- Rejected: Free-text strings. A label outside the set would reach the caller.
- How does a sync caller run a Jev decision without an event-loop conflict?: The live paths build the Agent with
build_agentso the spend hook is attached. An async caller awaitsagent.run(...). A sync caller callsagent.run_sync(...), which keeps one loop for each thread. A caller that already runs a loop uses the async form, becauserun_syncfails inside a running loop. The portal goes. (best practice) [sources: src/devops_cli/ai/jev.py:125-143,189-210, src/devops_cli/roadmap/decision_step.py:244-277, src/devops_cli/roadmap/decision_point.py:294-331, src/devops_cli/ai/client/factory.py:253-300]- Chosen:
run_syncfor a sync caller andawait runfor an async caller. It keeps the sync CLI commands sync and removes the portal. - Rejected: A blocking portal for each sync call. It is the glue that failed three times (fix(ai): a second Jev request on one model fails #4319, fix(roadmap): decide_all can hang a test worker for good #4513, fix(roadmap): decision points need cuts for shadow and run in async code #5272 item 2).
- Rejected:
asyncio.runfor each request. It fails inside a running loop, which is item 2 of fix(roadmap): decision points need cuts for shadow and run in async code #5272.
- Chosen:
- Which span content does a Jev call keep?:
InstrumentationSettings(include_content=False). The span keeps the question names, the probabilities, the thresholds and the usage. It keeps no state text and no question text. (best practice) [sources: src/devops_cli/telemetry/library_spans.py:126-133, tests/telemetry/test_library_spans.py:94-99]- Chosen: Content off. The telemetry privacy default keeps prompt and tool content out of the cluster OTel spans.
- Rejected: Content on. It puts item text and question text in the spans.
- What does a reply that misses an asked answer do?: The Agent path raises
UnexpectedModelBehavior. The chain catches it and gives the fallback: no band (counted asnone) for a decision point andtriagefor intake. The caller never seesKeyError. (best practice) [sources: src/devops_cli/roadmap/decision_step.py:91-119,188-223, src/devops_cli/roadmap/decision_point.py:294-331, src/devops_cli/roadmap/intake/intake_jev.py:347-354]- Chosen: Fallback on the missing answer. The chain already gives the fallback for a failed request and counts its class.
- Rejected: Retry the request. The spend rises, and the intake round already stops on a partial reply (fix(roadmap): a partial Jev reply stops the intake round #4450).
- Which output type does
devops ai ask-jevuse?: The Agent is built for each call from the kind and its inputs, over the shared model. Achoicequestion gets one field for each option, ascorequestion one field for each level, and anoulquestion one probability field. (best practice) [sources: src/devops_cli/ai/jev_ask.py:131-160,215-257, src/devops_cli/ai/jev_ask_models.py:23-43]- Chosen: One Agent for each call, from the kind and its inputs. The option labels and the level count come from the call, so the output type cannot be fixed at import.
- Rejected: One fixed output type with a map of probabilities. The page says each field carries its own question.
- Rejected: Keep the direct
decide()call for ask-jev. It keeps the glue and gets no span, no limit check and noRunUsage.
- Where does the refit of the
stage.verify_screencuts happen?: In feat(roadmap): the verify screen records serious findings for a live fit #5273, after feat(roadmap): ask the verify screen one atomic question each #5281 and this item. The field descriptions change the request text, and a fit needs live cases. This item changes no cut file, so the band of the screen stays fitted to the old request text until feat(roadmap): the verify screen records serious findings for a live fit #5273 lands. (best practice) [sources: src/devops_cli/roadmap/stage/stage_jev_screen.py:55,172-183, src/devops_cli/roadmap/decision_step.py:138-160]- Chosen: Refit in feat(roadmap): the verify screen records serious findings for a live fit #5273 after both prompt changes. The body names one fit for the two prompt changes, and a fit needs live cases.
- Rejected: Refit in this item. The rewrite of feat(roadmap): ask the verify screen one atomic question each #5281 is not in this item, so a fit now would fit a text that changes again.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 12, 2026
Both adopt the pydantic-ai Agent pattern, but #2489 covers the chat and pipeline path while this candidate covers the decision-model (Jev) path.devops-cli-service commentedon Nov 16, 2026
Alternatives check: not-applicable
Class: refactor. The check makes no search and no model call for an item of this class.
Tool: none found
Checked on 2026-11-16. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 17, 2026
Status set to Ready at e6f5718 (see proposed design in issue body).
dan-petty commentedon Nov 19, 2026
New evidence from the Service config review of 2026-11-19: the Jev calls of the decision points are not in the spend ledger now.
record_jev_spendhas two callers on origin/main:src/devops_cli/ai/jev.py:209andsrc/devops_cli/roadmap/intake/intake_jev.py:268. Intake Jev isoffin the cluster._decide_closingand_decide_one(src/devops_cli/roadmap/decision_step.py:182-217) calldecider.decideand record no spend.sum by (model)(increase(devops_cli_ai_spend_usd_total[7d]))and the same query ondevops_cli_ai_requests_totalgive no Jev series. Over the same 7 d,devops_cli_decision_point_totalcounts about 233stage.verify_screendecisions with the resolvermodel.typesafe/jev-1.14, because the pass-through gives no usage. So no source holds the Jev token volume now.k8s/devops/configmap.example.yaml:68-69says "The client records the tokens of each Jev decision call in the spend ledger". That is false for the decision points today.track_request_spendcallsrecord_attempt_ai(src/devops_cli/ai/spend/ledger.py:1090-1092), so after the fix themodel_calls=andtokens=of a stage result line include the Jev calls.If this refactor waits, a small fix can come first: call
record_jev_spend(response)afterdecider.decideindecision_step.py, with the model name of the call. The same change must make the template comment true.devops-cli-service commentedon Nov 27, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.