Skip to content

feat(ai): item refinement to ready with proposed decisions (devops roadmap refine) #744

Closed

Description

@dan-petty

Problem Statement

Refinement is done by hand today. Items reach implementation with open questions, and the gaps show up later as review findings: three remediation PRs merged into release/v0.2.24 on three consecutive days (#683 on 2026-09-28, #719 on 09-29, #736 on 09-30), each fixing findings from a review session. On 2026-10-01 an assessment refined the v0.2.25 and v0.2.26 items one at a time with agents. This item turns that manual pass into a roadmap job, so the next planned release reaches 12 Ready items without it. CONTEXT.md defines Ready as a problem statement, acceptance criteria and an answer to every key question. This item adds the rule that proposed answers count, and a person can override one before the item starts.

What exists at 9c879ae (release/v0.2.25):

Security. The repository is public, so anyone can write issue text. The roadmap must also work for any repository devops-cli manages (ADR 0001, line 3). In the service, the job acts as the machine account, whose classic token has the repo and project scopes (ADR 0002). In a terminal it acts as the person's gh login (#767). Refinement reads untrusted text (issue bodies and search results) and writes to GitHub. Prompt injection targets exactly that setup.

  • Willison, "The lethal trifecta for AI agents" (2025-06-16): the trifecta is private data, untrusted content and a way to send data out. Markdown images are a known way to send data out. GitHub fetches every image URL in an issue body or comment through its image proxy.
  • Beurer-Kellner et al., "Design Patterns for Securing LLM Agents against Prompt Injections" (arXiv 2506.08837). This item uses its plan-then-execute and context-minimization patterns.
  • OWASP Top 10 for Agentic Applications 2026 (published 2025-12-09), ASI01.

So neither model step holds a tool, and deterministic code decides every write. The text the job writes can't carry any link, image or mention the run didn't produce.

Proposed Solution

devops roadmap refine: a roadmap job that reads one New item's body, the checkout's docs and code slices, and (for public repos) web search results, asks the analysis model for a RefinementProposal in two tool-less structured calls, validates every source deterministically, writes its own marked section into the item's body, and moves Status New → Ready when the deterministic Ready check passes.

Command

devops roadmap refine takes the --dry-run and --confirm every roadmap subcommand takes (#739), --repo OWNER/NAME and --ref as migrate and render take them (commands/roadmap.py:43-44; --ref selects the .github/roadmap.toml read through _open_roadmap, default the default branch, independent of --source's HEAD SHA), plus --item N, --limit (default 3) and --source PATH (default: the current directory). --repo defaults to the --source checkout's origin, so refine resolves the origin from --source, not from the current directory as _open_roadmap does at :59. It gets a read-only MCP mirror roadmap_refine that runs the dry run only, built like roadmap_migrate (ai/mcp/server.py:643-657).

Selection

Without --item, refine works only on New items.

  • It takes the New items in the next planned release first, by priority. A person placed them there, so the cap doesn't stop this step.
  • Then it takes backlog items by priority, until the Ready items in the next planned release and the backlog together reach the release cap (release_cap, 12).
  • It skips an item when neither its body outside the section nor the section has changed since refine last ran on it. The store's job record holds both hashes. A person's edit, such as an answer or an "## Owner decisions" block, makes the item eligible again.
  • It stops after --limit items.
  • It never touches an item that is Ready, Blocked or started. With --item, such an item is reported and left alone.

Triggers

Inputs (context minimization)

  • The issue body only, not its comments.
  • CONTEXT.md and docs/adr/*.md from the checkout, when present.
  • Code from the checkout at --source:
    • Refine checks that the checkout's origin is the --repo. If it isn't, refine makes no model call, writes nothing and exits non-zero. It records the HEAD SHA and the branch.
    • It reads file content at the recorded SHA through git (git show <sha>:<path>, git grep ... <sha>), as argv with no shell (the _git pattern in ai/review/samples.py:136), so untracked files, paths outside the checkout and symlink targets are never read:
      • the paths and path:line ranges the body cites;
      • git grep -n -F -w -e <identifier> <sha> -- hits for backticked identifiers, with the number of hits capped;
      • the repo map of the cited directories, limited to the files git ls-files lists.
    • All of this is cut to the analysis model's context budget (for_task("analysis").context_window/num_ctx, via truncate_to_token_limit).

Two model steps (plan-then-execute)

Both go through chat_structured with ai.for_task("analysis"), and neither holds a tool.

  1. Research plan. Sees the issue body only and returns at most 3 search queries.
    • Deterministic code runs each query through Tavily (5 results each), but only when the store reports the repo as public and the Tavily key is set. If the visibility can't be read, refine runs no search.
    • A failed search is recorded as "research failed: ", where the category is the HTTP status, "timeout" or "malformed reply". No exception text is written to the body or passed to the model.
  2. Proposal. Sees the body, the docs, the code slices and the search results. Returns a RefinementProposal, a Pydantic model with extra="forbid", holding:
    • a problem statement;
    • acceptance criteria, each with how it is verified;
    • key questions: the body's own, plus any a builder would hit. Each answer is marked as fact or decision and lists its sources;
    • whether the item fits one PR, with draft split-offs if it doesn't;
    • a suspected block, if any;
    • dependencies, as issue numbers.

Validation (deterministic)

  • A path:line source must exist at the recorded SHA.
  • A URL source must be one of this run's search results.
  • An #N must be an issue in the repo (store.issues()).
  • Invalid sources are dropped.
  • A fact answer left with no valid source becomes an open question.
  • Deterministic code collects the body's own key questions: the list items under a "Key questions" label. A body question the proposal doesn't answer, matched after normalizing whitespace and emphasis, becomes an open question.
  • A decision answer is marked "(proposed)". It is marked "(owner decision)" instead only when it quotes a line that appears in the body's "## Owner decisions" block.

Ready check (deterministic, over the validated proposal)

The item passes when it has a problem statement; at least one acceptance criterion with how it is verified; no open question; a fit in one PR; and no suspected block.

Writes

These are the only writes refine makes, and all go to the item being refined.

  • The section between <!-- devops-roadmap-refine:start --> and <!-- devops-roadmap-refine:end --> at the end of the body. It records the SHA and branch it was checked at.
    • The renderer builds it from the proposal as plain text. It removes images (inline and reference-style), raw HTML and links. It wraps @ handles, #N references that failed validation, and bare URLs not in this run's search results in code spans.
    • URLs come only from this run's search results.
    • Everything outside the markers stays byte-identical.
  • Status New → Ready, when the Ready check passes. Refine makes no other status change.
  • One reason comment on the item, when its Status changes or when it needs splitting. A fixed template with no model text: the change ("New → Ready" or "needs splitting into N items"), the SHA, and a pointer to the section.
  • Too big for one PR: Status stays New; the section lists the proposed split-offs and refine never files them; the store's job record for the item gets needs_split. This item makes reprioritization's descoping (feat(github): current release admission, cap, descoping and stall rules (devops roadmap reprioritize) #740) read that record, never the body. Descoping applies only to the current release, so this matters for an admitted critical fix. An item in the next planned release stays New, and feat(github): current release admission, cap, descoping and stall rules (devops roadmap reprioritize) #740's release start returns it to the backlog.

Store (this item adds, to both adapters, the contract suite and the GitHub adapter's tests)

None of these exist at 9c879ae:

  • an issue body read for one number (today only issues() returns bodies) and an issue body write;
  • a stand-alone comment write (today only close_issue comments);
  • a repository visibility read (the GraphQL client already fetches isPrivate, github/graphql.py:107, :371, :838; the store exposes it);
  • refine's per-item record values in the job record, as the body already decides (Selection and Writes above): refine.body_hash, refine.section_hash and refine.needs_split. They are a second key kind, a StrEnum alongside ItemField in JobRecord (store.py:83), so _JOB_RECORD (github_store.py:323) validates them and encode_job_record (:377-379) writes their .value into the same board text field; BOARD_FIELDS (store.py:54) stays derived from ItemField alone, so require_board_field and the field writes are untouched. A person's edit (as_actor, memory_store.py:131) never writes them;
  • a recorded-writes list in the in-memory adapter covering body writes and comments, so tests can assert "nothing else was written".

Tavily

  • Add tavily_search(query, *, api_key, max_results) -> list[TavilySearchResult] to ai/common_tools.py. It raises on an HTTP error or a malformed reply. tavily_search_tool wraps it and keeps its current text output. Discovery (feat(ai): roadmap discovery from advisories, alerts, repo signals and web research (devops roadmap discover) #745) can reuse it.
  • Add a tavily.api_key option, read from DEVOPS_CLI_TAVILY_API_KEY. It follows qdrant.api_key: config/options.py:65, SECRET_CONFIG_OPTIONS (:220) and KEYRING_KEYS (:236-243), config/env.py:67, :153 and the secret EnvVarSpec at :475-480, plus the row in build_secret_registry (security/secrets.py:408-424) that every secret option carries.

Scope

In this item's one pull request:

Effort: high. It fits one pull request: #739 shipped as one PR of 57 files (git show --stat 6948e1c: 57 files changed, 4396 insertions), and this item's surface is of the same order.

Key Questions

Answered (decision marks follow the item's own convention; "proposed" answers count toward Ready and a person can override one before the item starts):

Acceptance Criteria

Unless marked otherwise, each criterion is a test in tests/test_roadmap_refine.py, run with uv run pytest tests/test_roadmap_refine.py. The tests use the roadmap_store fixture (tests/conftest.py:324) over InMemoryRoadmapStore, a scripted chat_structured and a fake search function.

  • Dry run. devops roadmap refine --item N --dry-run prints the rendered section and the planned writes, and the adapter's recorded writes stay empty. A CliRunner test, as in tests/test_roadmap_render.py:144 (test_dry_run_prints_the_file_and_writes_nothing).
  • Body write. After --confirm: the body outside the markers is byte-identical to the body before; the section equals the rendered proposal; a second run with the same proposal writes nothing.
  • Ready check. A complete proposal moves Status from New to Ready and posts one comment on that item. Each of these leaves Status at New, one parametrized case each: an open question; a fact answer whose only source is a path:line past the end of the file at the SHA; a body key question the proposal leaves out; a proposal that doesn't fit one PR; a suspected block; no acceptance criterion.
  • Decision marks. In the rendered section: a decision answer ends with "(proposed)"; a decision answer that quotes a line of the body's "## Owner decisions" block ends with "(owner decision)"; a decision answer that claims an owner decision the block doesn't hold ends with "(proposed)".
  • Injection. The test body tells the model to add a label, raise the priority, set a milestone, close another issue and comment on another issue; a scripted model obeys all of it in its answer text. The recorded writes then hold only the section write, at most the Status change and one comment, all on that item. A reply with extra fields (labels, close) fails RefinementProposal validation; the scripted chat_structured then raises AIClientError, as the real one does after its retries (structured.py:284-290), and nothing is written. No backoff sleep runs in the test.
  • Rendering. The renderer is fed model text containing ![x](https://example.invalid/?q=secret); a reference-style image ![x][r] with [r]: https://example.invalid/?q=secret; [a](https://example.invalid); a bare https://example.invalid/?q=secret and an autolink <https://example.invalid>; <img src="https://example.invalid">; @someone and #999999; and the end marker. The rendered section has no image, no HTML tag, and no link or bare URL outside this run's search results; the handle and the unknown #N are inside code spans; the section has exactly one start marker and one end marker.
  • Comment. For the Ready and the needs-splitting cases, the comment equals the template. Model text with an image or a handle never appears in it.
  • Reading. With a temporary git repo (tmp_path): a body that cites ../outside.txt:1, an absolute path to a sentinel file outside the checkout, an untracked file, and a tracked symlink pointing outside the checkout reads none of them, and no sentinel text reaches either prompt; a backticked identifier that starts with - never reaches git grep as an option; a checkout whose origin is another repo makes refine exit non-zero with no model call and no write.
  • Research isolation. The research-plan prompt holds the body and no code slice. With a private repo, an unreadable visibility or no key, refine makes no search call. When a search raises, the section records "research failed: ", and no exception text reaches the proposal prompt or the section.
  • Person edits. Refine writes nothing and reports why when: the section's hash differs from the one refine last recorded; the body holds a section refine has no record of; the body changed between the read and the write.
  • Selection. With the store filled with New, Ready, Blocked and started items in the next planned release and in the backlog, refine picks next-release New items by priority, then backlog items by priority; skips the Ready, Blocked and started items; skips a New item whose body and section are unchanged since its last run, and picks it again after its body changes; stops at --limit, or once the next planned release and the backlog hold 12 Ready items.
  • Too big. A proposal that doesn't fit one PR leaves Status at New, records needs_split in the job record and posts one comment. With that record set on a current-release item that hasn't started, devops roadmap reprioritize descopes it, tested against feat(github): current release admission, cap, descoping and stall rules (devops roadmap reprioritize) #740's job (feat(github): current release admission, cap, descoping and stall rules (devops roadmap reprioritize) #740 lands before this item; see Dependencies).
  • Intake hook. When intake admits a critical fix or places a P0 feature, it calls refine for that item in the same run. A test with a spy on feat(github): single-entry item intake with duplicate detection and placement (devops roadmap intake) #742's job (feat(github): single-entry item intake with duplicate detection and placement (devops roadmap intake) #742 lands before this item; see Dependencies).
  • MCP. roadmap_refine returns the dry-run result and accepts no confirm argument: a test in tests/test_fastmcp_contracts.py (where roadmap_migrate and roadmap_render are checked) asserting the argv it builds ends with --dry-run and never holds --confirm.
  • Size. If the section would push the body past GitHub's 65,536-character limit, refine writes nothing and reports it.
  • Store contract. tests/test_roadmap_store_contract.py (in-memory adapter, store fixture at :52) gains cases for the body read, the body write, the comment write, the visibility read and the refine record keys, including that a write through as_actor leaves the job record untouched; tests/test_roadmap_github_store.py gains the matching argv cases for the GitHub adapter, in the style of test_close_issue_comments_then_closes_for_its_reason (:870).
  • Tavily (mocked HTTP client, in tests/test_common_tools.py): tavily_search raises on an HTTP error and on a reply that has no results list; tavily_search_tool still returns formatted text on success; tavily.api_key is in SECRET_CONFIG_OPTIONS and build_secret_registry (a case in the existing secrets tests); feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's push table has the optional DEVOPS_CLI_TAVILY_API_KEY entry with its env name from OPTION_TO_ENV_VAR (tests/test_k8s_push_secrets.py).
  • Gate budget. uv run pytest tests/test_roadmap_refine.py --durations=0 shows no test above 1 s, and no test opens a socket (the session-wide network guard in tests/conftest.py:98-113 raises RuntimeError for any non-loopback connect).
  • Gate. uv run devops ci passes.
  • Pending a person (live model and live GitHub): run DEVOPS_CLI_TAVILY_API_KEY=<key> uv run devops roadmap refine --repo dan-petty/devops-cli --item <a New item> --source . --dry-run; confirm every printed path:line resolves with sed -n '<line>p' <path> and every printed URL appears in the printed search results. Run the same command with --confirm; confirm uv run devops gh api repos/dan-petty/devops-cli/issues/<N> --jq .body shows the section and uv run devops gh api repos/dan-petty/devops-cli/issues/<N>/timeline --paginate --jq '.[].event' (commands/gh.py:1249-1273) shows no labeled, milestoned, closed or assigned event from the run.

Out of Scope

Constraints that bind the implementation:

  • Issue text and search results are untrusted data, and neither model step holds a tool.
  • Refine writes only to the item it refines: its own section of the body, Status New → Ready, and one fixed-template reason comment. It never writes labels, priority, Value, Effort, the milestone or blocked-by links; never writes to or comments on other issues; never files split-offs.
  • It reads only git-tracked file content at the recorded SHA, and it runs no shell.
  • Tests never touch the network, a cluster or a live model. Each new in-gate test costs at most 1 s.
  • Tests use structural tuple assertions until test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851 settles that.
  • No new dependency: Tavily is called through the existing new_http_client (src/devops_cli/http/client.py:55), and validation uses Pydantic.
  • CHANGELOG.md and docs/ROADMAP.md are not edited; the entry goes in changelog.d/744.md.

Dependencies

Order: #740 (v0.2.25) and #742 (v0.2.26, starts first) before this item and #981; inside v0.2.26, #741 before this item's Tavily row, #982, then #743, then this item, then #981 last.

Activity

  1. added this to the v0.2.26 milestone on Sep 30, 2026
  2. added
    type/feature
    scope/ai
    priority/p1-high
    on Sep 30, 2026
  3. added a commit that references this issue on Oct 1, 2026
  4. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    #741 lands right after #753 in v0.2.26, so this item adds the DEVOPS_CLI_TAVILY_API_KEY row to devops k8s push-secrets. #742 is now in v0.2.26 (starts first) and still lands before this item.

  5. dan-petty commented on Oct 4, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1177, merged into release/v0.2.26 as d3a2088.

    Summary

    Delivers devops roadmap refine (#744), enabling automated item refinement to Ready status with proposed design, tasks, and acceptance criteria.

    • Selection: Selects New items from the next planned release by priority rank, then New backlog items up to the release cap (12 Ready items). Skips Ready, Blocked, started, or unchanged items (refine.body_hash, refine.section_hash).
    • Context Minimization: Bounded extraction of CONTEXT.md, ADRs, cited files/lines, and identifiers using git argv without shell invocation.
    • Model Research & Proposal: Two structured steps via chat_structured with ai.for_task("analysis") for research queries (Tavily search for public repos) and structured RefinementProposal.
    • Deterministic Validation & Sanitization: Validates paths/lines at target SHA, URLs, and #N references. Plain-text markdown rendering between <!-- devops-roadmap-refine:start --> and <!-- devops-roadmap-refine:end --> markers with person edit guards and 65k character size cap.
    • Ready Transition & Split Management: Complete items move to Ready with reason comments referencing the commit SHA; oversized items remain New with refine.needs_split="true" and are descoped by reprioritization.
    • Due Table, MCP & Intake Integration: Added refine row to DEFAULT_DUE_TABLE, FastMCP mirror roadmap_refine, and intake hook on admitted critical fixes and P0 features.

    Closes #744.

    37 file(s) changed.

    How it was verified

    Check runs at f78e588:

    • 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-744-item-refinement-to-ready.md:

    • Command options & validation: tests/test_roadmap_refine.py::test_inspect_checkout_origin_match_and_mismatch and test_cli_refine_dry_run_and_confirm verify --repo, --ref, --source, --item, --limit, --dry-run, and --confirm. Exits non-zero without model calls or writes when checkout origin doesn't match --repo.
    • Selection: tests/test_roadmap_refine.py::test_selection_next_release_backlog_priorities_and_cap and test_selection_skips_unchanged_items_and_picks_on_change verify selection by priority, cap enforcement (12 Ready items), skipping Ready/Blocked/started items, and skipping unchanged body hashes.
    • Context minimization: tests/test_roadmap_refine.py::test_collect_context_and_truncation verifies gathering CONTEXT.md, ADRs, cited files/lines, grep identifiers, and truncation to context budget.
    • Research step: tests/test_roadmap_refine.py::test_research_plan_public_vs_private_and_errors verifies Tavily queries run only for public repositories with API keys, and records error categories on failure.
    • Proposal validation: tests/test_roadmap_refine.py::test_validate_proposal_sources_and_questions verifies path/line citations, fact answers without sources converting to open questions, owner decision quotation, and body key questions.
    • Ready check: tests/test_roadmap_refine.py::test_check_ready_matrix verifies completeness rules (problem statement, criteria with verification, zero open questions, fits one PR, no block).
    • Plain-text markdown renderer & sanitization: tests/test_roadmap_refine.py::test_sanitize_text_markdown verifies stripping HTML tags and images, wrapping handles and unallowed URLs in code spans, and marker boundary preservation.
    • Person edits guard: tests/test_roadmap_refine.py::test_person_edits_guards verifies refusal to overwrite when section hash differs or untracked section exists.
    • Size limit guard: tests/test_roadmap_refine.py::test_size_limit_guard verifies refusal and skip when body would exceed 65,536 characters.
    • Too big item splitting & reprioritization: tests/test_roadmap_refine.py::test_too_big_needs_split_and_reprioritize_descopes verifies refine.needs_split="true", split comments, and reprioritization descoping.
    • Intake hook: tests/test_roadmap_refine.py::test_intake_hook_calls_refine verifies hook trigger on admitted critical fixes and P0 features.
    • Due table & MCP mirror: tests/test_roadmap_refine.py::test_run_due_table_refine_adapter and tests/test_fastmcp_contracts.py verify due table runner integration and FastMCP tool contract.
    • CI Quality Gate: uv run devops ci completes with all quality checks passing.
      • Pending a person: devops roadmap refine --repo <owner>/<repo> --item <N> --dry-run to inspect proposed refinement plan against a live issue.
      • Pending a person: devops roadmap refine --repo <owner>/<repo> --item <N> --confirm to apply refinement and observe issue body update and status transition to Ready on the GitHub board.
  6. added a commit that references this issue on Oct 4, 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

    priority/p1-highscope/aitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions