Skip to content

fix(roadmap): refine sends the model the proposal schema and never caches a reply that fails it, and one failed item skips only that item #1363

Closed

Description

@dan-petty

Problem

devops roadmap refine has not written a single proposal since it shipped in v0.2.26 (#744, PR #1177). In the roadmap service, every refine round that reached the model failed with StructuredOutputValidationError after 3 attempts. There are three causes. Neither prompt asks for JSON or names a field, so the model answers with a Markdown document. The response cache replays that document to later rounds. And the first failed item stops the whole job. Checked on 2026-10-08 at 910b823 (service image v0.2.28).

The model is never told what to return.

  • The proposal prompt is "Generate a structured RefinementProposal for this issue." followed by the issue, the context and the search results (src/devops_cli/roadmap/refine.py:785-791). The system prompt is one sentence (:793). Neither contains the word JSON or names a field. The research step is built the same way (:338-347). Both prompts are inline strings, which AGENTS.md:439 forbids: prompts live under src/devops_cli/ai/ and load through load_task_prompt().
  • chat_structured sends only those messages (src/devops_cli/ai/client/structured.py:188-195). The request body holds model, messages and sampling settings, with no response_format (src/devops_cli/ai/client/openai.py:81-105). The ollama provider's payload sets no format (src/devops_cli/ai/client/ollama.py:276-303). No request in src sets either one.
  • All the proposal models set extra="forbid". Each criterion requires description and verification, and each key question requires question, answer and kind (refine.py:64-91). The schema is small: 1,510 characters of JSON Schema with 7 top-level fields.
  • The first reply is a Markdown document. The service's response cache holds 36 first-attempt replies to the proposal prompt, from 2026-10-05 02:26Z to 2026-10-07 20:52Z. All 36 are Markdown or YAML documents, for example a # RefinementProposal — Issue #… heading followed by tables, and none starts as a JSON object. 12 came from devops-review and 24 from devops-background, so both model routes answered the same way.
  • Only the retries return JSON, and its shape is a guess. The reflection asks for "ONLY the valid JSON object matching the schema" but never shows the schema, and it lists at most 5 violations (structured.py:127-138; CONST_MAX_SCHEMA_REFLECTION_ERRORS, config/constants.py:3676). The logged last errors carry 7 to 111 violations:
    • acceptance_criteria[n].id (an extra key)
    • criterion in place of description
    • verification missing
    • criteria given as plain strings ("Input should be a valid dictionary or instance of AcceptanceCriterion")
    • top-level issue and title keys
  • The test double returns a RefinementProposal directly (tests/test_roadmap_refine.py:136-140), so no test sees what the model is sent.
  • Control: intake. Intake uses the same client, gateway and analysis model. Its prompt file lists every key and says to return one JSON object and nothing else (src/devops_cli/ai/tasks/roadmap_intake_system.md:5-18). All 115 intake replies in the same cache parse as JSON objects with exactly those keys; 114 of them came from devops-background. 3 add one stray key, which ModelProposal's extra="ignore" drops (roadmap/intake_model.py:44-47).

The cache replays the invalid first reply.

  • chat_structured's first attempt reads and writes the response cache with no validator (structured.py:252; ai/client/unified.py:567-588 and :606-607). The cache keeps any non-empty reply. So the Markdown document is cached and served again to every later round whose prompt is unchanged.
  • The 36 cached replies were served 113 times. The one cached at 2026-10-05 15:44Z was served 14 times, and another 13 times. In those rounds the first attempt made no model call and could not succeed, so only 2 real attempts were left.
  • Passing the schema check to chat_messages as its validator does not fix this by itself. chat_structured calls it with max_retries=0, so a rejected reply raises AIClientError (unified.py:633-637, :654-656) before the reflection retry runs.

Loki, roadmap service, 2026-10-01 to 2026-10-08.

One failed item fails the whole job, and refine retries the same item every round.

  • feat(ai): item refinement to ready with proposed decisions (devops roadmap refine) #744 specifies: "What if a model call fails or returns an invalid proposal? Refine writes nothing for that item and reports it. The run moves on to the next item and exits non-zero at the end." But plan_refine catches nothing (refine.py:880-892), so the job stops at the first failing candidate.
  • plan_refine plans every candidate before apply_refine runs (roadmap/run.py:456-458). A failure on a later candidate therefore also discards the proposals already made for earlier ones.
  • A failed item gets no job record, so select_candidates picks the same top New item again (refine.py:705-715). Refine runs after every reprioritization and after intake places a P0 item (run.py:303-310).
  • Cost. Fresh first replies took 5 to 40 s until about 18:00Z on 2026-10-05. They took 165 to 480 s from then until 2026-10-06, and 866 to 1,608 s on 10-07.
    • The round that failed at 2026-10-07 20:59:08Z made its first request at about 20:27:18Z. The gateway timed it out after 1,100 s (logged at 20:45:38Z), and the transport retried it. The reply arrived at 20:52:25Z, and the two retries followed at 20:55:33Z and 20:59:08Z. That round held this repository's worker for about 32 minutes.
    • Intake's proposals wait for the same background tier (k8s/llm/gateway/configmap.yaml:66-73).
    • In total, the 145 failures made about 435 attempts. 113 of them replayed a cached reply, so about 325 reached a model.

Why the release start depends on it. Refine is the only job that moves an item from New to Ready (#744, last key question). A release start sends the starting release's New items to the backlog (roadmap/reprioritize.py:352). It tops the release up only with Ready items (:356; _candidates at :1595-1615). On 2026-10-08 the planned releases after v0.2.29 hold 1, 0 and 0 open items.

The stack can already constrain the reply.

  • The gateway's LiteLLM (v1.103.0, k8s/llm/gateway/deployment.yaml:32) maps an OpenAI response_format of type json_schema to Ollama's format for ollama_chat deployments (litellm/llms/ollama/chat/transformation.py:171-173 in the running gateway). It does not pass strict on.
  • Every chat deployment behind the gateway is ollama_chat today.
  • The gateway runs with drop_params: true (configmap.yaml:171).
  • devops-cli never sends the parameter.

Acceptance criteria

  • chat_structured tells the model the schema it validates against, for every caller: intake, refine's research plan and refine's proposal.
    • The system message ends with the schema's JSON Schema (schema.model_json_schema()). Text from a prompt file under src/devops_cli/ai/tasks/ introduces it and asks for one JSON object and nothing else.
    • On the gateway provider only, the request body also carries response_format: {"type": "json_schema", "json_schema": {"name": <schema class name>, "schema": <that schema>}}, with no strict key.
    • On the ollama provider, the request body carries format: <that schema>.
    • The openai and copilot payloads stay unchanged. They come from the same _build_compat_payload (unified.py:433).
    • A test captures the request body at the HTTP edge for RefinementProposal on the gateway, ollama and openai providers. It asserts each body as one structural value. Verified by a mutation in review: dropping the response_format entry, or adding it to the openai payload, must make the test fail.
  • Refine's prompts move to src/devops_cli/ai/tasks/roadmap_refine_research.md and roadmap_refine_proposal.md, loaded with load_task_prompt().
    • The proposal prompt names every RefinementProposal field and what goes in it, as roadmap_intake_system.md does for intake. Criteria are objects with description and verification, kind is fact or decision, and no other key is allowed.
    • roadmap/refine.py holds no multi-line prompt string.
  • RefinementProposal keeps extra="forbid", and feat(ai): item refinement to ready with proposed decisions (devops roadmap refine) #744's injection test passes unchanged.
  • A reply that fails the schema is never written to the response cache and never served from it. The next attempt still gets the reflection message, and a valid first reply is still cached and served. The tests use a tmp cache and a fake transport:
    • The transport first answers with a Markdown document, then with valid JSON. The second request carries the Markdown reply and the reflection message, and the call returns the proposal. No cache file holds the Markdown reply.
    • With a Markdown reply seeded in the cache at the first attempt's key, the call reaches the transport and never returns the seeded text.
  • A failed model call skips only its item, as feat(ai): item refinement to ready with proposed decisions (devops roadmap refine) #744 specifies. A test runs a scripted client over three candidates:
    • When candidate 1 raises StructuredOutputValidationError, candidates 2 and 3 are refined and written. Candidate 1 is reported as skipped, with the error class and the violation count but no model text, and nothing is written to it.
    • When candidate 2 raises AIClientError (which a gateway timeout becomes), candidate 1's section and Status are still applied.
    • In both cases the job fails at the end: devops roadmap refine --confirm exits non-zero, and in run_due_jobs the RoadmapRunError's failed_jobs names refine.
    • AICredentialsError still stops the job at the first item.
  • Intake's tests pass unchanged.
  • No test reaches the network. The request-body and cache tests use a fake transport and a tmp cache directory, and the retry tests set the backoff to 0. Each new test's call phase stays under 1 s (uv run pytest tests/test_roadmap_refine.py tests/test_ai_client_structured.py --durations=10).
  • uv run devops ci passes within its 5-minute budget.
  • changelog.d/<n>.md records the fix under ### Fixed. CHANGELOG.md and docs/ROADMAP.md are untouched, and uv run devops pr check-readiness passes.
  • Pending a person, after merge, once the service runs a release image with this fix:

Key questions

Strategic alignment

Update 2026-10-08: delivered scope

Implemented on fix/1363-refine-structured-output against release/v0.2.29 at 05e9388. Line references in the body moved because of #816 and #898; the code is the reference now.

Amendments to the acceptance criteria:

  • "feat(ai): item refinement to ready with proposed decisions (devops roadmap refine) #744's injection test passes unchanged" had no test behind it: none existed. A new test adds feat(ai): item refinement to ready with proposed decisions (devops roadmap refine) #744's injection case: a scripted reply carrying labels and close fails RefinementProposal validation, the item is reported skipped with nothing written, and the other candidates still refine. RefinementProposal keeps extra="forbid".
  • Cache criterion: a validator rejection raises ReplyRejectedError, an AIClientError subclass carrying the rejected reply with the message unchanged. That reply reaches the reflection, and the rejection is never logged. It is recorded on the ai.llm.chat span, which is marked ERROR even when the retry recovers.
  • The retry sends the SchemaReflectionReport's prescriptive reflection prompt and names every violation, not only the first five. The validation helpers return that report, extracted with every violation, and format_schema_validation_error is removed (task-437's file names what replaced it).
  • StructuredOutputValidationError carries a structured violation count (violations, 0 when no JSON was found). Its message keeps only that count and the pydantic error types, never a field path, because a path can be a key the model invented and the message reaches the ai.client.chat_structured span, logs and intake's skip reason.
  • devops roadmap refine exits 1 when an item failed in a preview too (--dry-run or no --confirm), so the MCP roadmap_refine mirror ends in a ToolError that carries the plan.
  • refine_item raises RoadmapRefineError after applying the successful items, so intake's P0 refine hook keeps reporting a failed refine.
  • Refine's research step no longer catches every exception: it re-raises AICredentialsError, which stops the run before any proposal call, catches AIClientError, and logs only the error class, then refines without search results.

Corrected post-merge check (the original search already returns #1363 and #744, which quote the marker):
uv run devops gh api 'search/issues?q=repo:dan-petty/devops-cli+is:issue+"devops-roadmap-refine:start"+in:body' --jq '[.items[].number] - [744, 1363]' lists at least one number. For one listed number N, its body holds both refine markers on their own lines (grep -cx prints 2), and its board Status is Ready or it carries refine's reason comment. The Loki check stands: a failed item's log line and RoadmapRefineError name the error class, and a round that recovers on retry logs neither.

Out of scope, unchanged: devops roadmap refine --dry-run still makes GitHub and model requests (#412). #1400 should treat RoadmapRefineError as a non-rate-limit failure, and #1365 should carry it unchanged. Follow-ups: #1419, #1420, #1421.

Activity

  1. added
    type/bug
    scope/ai
    scope/github
    priority/p1-high
    on Oct 8, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P1-High. A shipped feature is 100% non-functional—every refine round fails—so users get zero value from a core roadmap workflow.
    • Effort: Medium. Three distinct fixes are needed (inject schema into prompt, validate before caching, isolate per-item failures) across a handful of identified files, but none requires a redesign.
  3. added
    source/agent
    and removed
    priority/p1-high
    on Oct 8, 2026
  4. added this to the v0.2.29 milestone on Oct 8, 2026
  5. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Placed in v0.2.29 by the owner on 2026-10-08. The owner's instruction was to pull every issue that keeps the roadmap service from working into the current milestone and complete them. This is a person's placement and should stay in the release (#1349). Implementation started the same day, so the board Status is In Progress.

  6. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1424, merged into release/v0.2.29 as 5b0e93b.

    Closes #1363

    31 file(s) changed.

    How it was verified

    Check runs at 9a92145:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Static Analysis: pass
    • Tests & Coverage: pass
    • Analyze (actions): pass
    • Analyze (python): pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1363-refine-structured-output.md:

    • chat_structured tells the model the schema for every caller: the system message ends with the instruction from structured_output_schema.md and the schema's JSON Schema; the gateway body alone carries response_format (type json_schema, no strict), the ollama body alone carries format, and the openai body has neither. test_each_provider_is_sent_the_schema_and_only_its_own_constraint captures the three bodies at the HTTP edge and asserts each as one structural value; dropping the response_format entry, or sending it on the openai payload, makes it fail.
    • Refine's prompts live in src/devops_cli/ai/tasks/roadmap_refine_research.md and roadmap_refine_proposal.md, loaded with load_task_prompt(); the proposal prompt names every key the schema allows (test_refines_prompts_load_and_the_proposal_prompt_names_every_field), and roadmap/refine.py holds no multi-line prompt string.
    • RefinementProposal keeps extra="forbid". A new test adds feat(ai): item refinement to ready with proposed decisions (devops roadmap refine) #744's injection case: a reply carrying labels and close fails validation, the item is reported skipped with nothing written to it, and the other candidates still refine (test_a_reply_asking_for_labels_or_a_close_is_refused_and_writes_nothing).
    • A reply that fails the schema is never written to the response cache or served from it, the next attempt still gets the reflection, and a valid first reply is cached and served: test_a_reply_that_fails_the_schema_gets_the_reflection_and_is_never_cached, test_a_cached_reply_that_fails_the_schema_is_never_served, test_a_valid_first_reply_is_cached_and_served. A validator rejection raises ReplyRejectedError carrying the reply with the unchanged message, while an empty reply or an error payload stays a plain AIClientError (test_a_reply_the_validator_refuses_comes_back_on_the_error).
    • StructuredOutputValidationError carries the last reply's violation count, 0 when it held no JSON (test_the_validation_error_counts_the_last_replys_schema_violations). Its message holds the count and error types alone: a key the model invented appears in neither the message, the ai.client.chat_structured span nor any log record (test_the_validation_error_holds_no_key_the_model_invented). The retry prompt names every violation's field path, seven in the test, not only the first five (test_the_retry_prompt_names_every_violation_of_the_last_reply).
    • A failed model call skips only its item, over three candidates answered by a scripted gateway at the HTTP edge: candidate 1's StructuredOutputValidationError leaves candidates 2 and 3 refined and written and reports candidate 1 with its class and count but no model text (test_a_proposal_that_never_fits_the_schema_skips_only_its_item); a 504 on candidate 2 still applies candidate 1's section and Ready Status (test_a_gateway_timeout_on_candidate_2_still_applies_candidate_1); devops roadmap refine exits 1 under --confirm, --dry-run and the default preview (test_the_cli_exits_1_after_reporting_a_failed_item); run_due_jobs' RoadmapRunError.failed_jobs is ("refine",) and its logged record names the class with none of the reply, for a schema miss and for a gateway 504 (test_a_failed_item_fails_the_refine_job_of_a_run_without_its_model_text); AICredentialsError stops the job at the first item (test_rejected_credentials_still_stop_the_job_at_the_first_item), and on a public repository it stops the job in the research step, before any proposal call (test_rejected_credentials_in_the_research_step_stop_the_job_before_the_proposal); intake's refine hook still logs a failed refine (test_intakes_refine_hook_still_reports_a_failed_refine); a research plan that fails its schema is logged by class alone and the item still refines (test_a_research_plan_that_never_fits_its_schema_refines_without_search_results).
    • Intake's tests pass unchanged.
    • No test reaches the network: the request-body and cache tests use httpx2.MockTransport through route_client / route_llm_clients and the autouse tmp response cache, refine's tests run on a private repository (or fail the research plan before any search), and retries wait no time. Each new test's call phase stays under 1 s.
    • uv run devops ci passes. changelog.d/1363.md records the fix under ### Fixed; CHANGELOG.md and docs/ROADMAP.md are untouched. The help text, docs/commands/roadmap.md, docs/CLI_REFERENCE.md, README.md, docs/ERRORS.md and docs/MCP_TOOLS.md are regenerated.
    • Pending a person, after merge, once the service runs a release image with this fix (Argo CD rolls it):
      • 24 h after the rollout, this Loki query in Grafana Explore returns nothing or 0: sum(count_over_time({namespace="devops", container="service"} |~ "Response validation failed|StructuredOutputValidationError" [24h])). A failed refine item logs its error class (Refine skipped #N: its model call failed (StructuredOutputValidationError, …)) and RoadmapRefineError's message names it too; a round that recovers on a retry logs neither.
      • uv run devops gh api 'search/issues?q=repo:dan-petty/devops-cli+is:issue+"devops-roadmap-refine:start"+in:body' --jq '[.items[].number] - [744, 1363]' lists at least one number (feat(ai): item refinement to ready with proposed decisions (devops roadmap refine) #744 and fix(roadmap): refine sends the model the proposal schema and never caches a reply that fails it, and one failed item skips only that item #1363 only quote the marker). For one listed number N, uv run devops gh api repos/dan-petty/devops-cli/issues/N --jq .body | grep -cx -e '<!-- devops-roadmap-refine:start -->' -e '<!-- devops-roadmap-refine:end -->' prints 2, and N's board Status is Ready or the item carries refine's reason comment.
      • The refine entry in the service's schedule.json for dan-petty/devops-cli is later than the rollout time.
  7. added a commit that references this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope/aiscope/githubsource/agenttype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions