Skip to content

perf(roadmap): a settled item costs no body read or model call until its text changes, with refine judging it from the listing it already read #1539

Closed

Description

@dan-petty

Refreshed plan (2026-10-17, unblocking review)

This section supersedes any text below that conflicts with it.

Decisions

Scope

Delivery

Acceptance criteria

Current references (main 3dd7fa6)

  • src/devops_cli/roadmap/store.py:179-185 RefineRecordKey has no failure key.
  • src/devops_cli/roadmap/store.py:257-281 Item has no body, and store.py:318-340 IssueRecord carries body (line 331).
  • src/devops_cli/roadmap/store.py:730-742 join_items drops the body.
  • src/devops_cli/roadmap/github_store.py:1470-1483 items and backlog.
  • src/devops_cli/roadmap/memory_store.py:610-623 items and backlog.
  • src/devops_cli/roadmap/refine.py:697 is the single-item read, and refine.py:707-726 is _is_unrefined_ready and _refinable.
  • src/devops_cli/roadmap/refine.py:769-785 is _consider, with the read at line 770.
  • src/devops_cli/roadmap/refine.py:828 is refine_one_item's read.
  • src/devops_cli/roadmap/refine.py:878-890 is the oversize skip, which returns empty hashes, so nothing is recorded for it.
  • src/devops_cli/roadmap/refine.py:969-970 is plan_refine's failure path, which records nothing.
  • src/devops_cli/roadmap/refine.py:974 sets has_writes only for refined items with no skip reason, and the callers apply only when it is true (src/devops_cli/commands/roadmap.py:545, src/devops_cli/roadmap/run.py:605).
  • src/devops_cli/roadmap/refine.py:1025-1029 is apply_refine's skip and re-read, and refine.py:1046 writes needs_split.
  • src/devops_cli/ai/client/models.py:68-89 defines ReplyRejectedError and StructuredOutputValidationError.
  • src/devops_cli/roadmap/run.py:392-400 is _refine_due, and run.py:903 calls _record_success only after a job succeeds.
  • k8s/devops/roadmap-service/deployment.yaml:12 holds replicas: 0.

Dependencies and order


Requested by the owner, 2026-10-10:

there should be a ready state for tickets where it doesn't take any additional computation, not sure if we are blindly looking at all open tickets over and over

This item folds #1526 (refine records failed and oversize items), which covers the same functions and tests. Close #1526 as folded when this is filed.

Problem

Checked at release/v0.2.33, and at v0.2.32, which the Service runs today.

Today (v0.2.32), unchanged items are refined again every round. Refine skips an item whose body and section are unchanged, in both its batch and single-item paths. But v0.2.32 sanitizes the section after adding the end marker, so it writes the marker as [end-marker]. The next read finds no section, and the recorded refine.body_hash never matches.

#1470 fixes the marker in v0.2.33.

v0.2.33 already makes a Ready item free. _is_unrefined_ready and _refinable (src/devops_cli/roadmap/refine.py:707-726) leave out a Ready item with a recorded section hash before any read. It costs no body read and no model call.

What v0.2.33 still spends on an item nothing changed:

  1. One body read per settled New item, every hourly run.

    • _consider (refine.py:769-785) calls store.read_issue_body for every item it checks, before its unchanged check.
    • The round already holds that body. items(release=) and backlog() (src/devops_cli/roadmap/github_store.py:1470-1483) join REST issue records that carry body (IssueRecord, src/devops_cli/roadmap/store.py:316-338).
    • Item (store.py:255-279) has no body field, so join_items (store.py:728-740) drops it.
    • On today's board that is about 48 REST requests per hourly run in this repository, for items that need no model call.
    • Items waiting on a person stay in that set every hour: needs split, open questions, or a section a person edited.
  2. Failed and oversize items are spent again (fix(roadmap): refine records an item whose model call failed or whose body would exceed the size limit, so it waits for a body change instead of being retried every poll #1526).

    • An item whose new body would exceed 65,536 characters is skipped after its model call, and nothing is recorded (refine.py:878-890).
    • A failed model call records nothing either (refine.py:969-971).
    • The job then fails. _record_success runs only on success (src/devops_cli/roadmap/run.py:900), and _refine_due (run.py:391-399) stays true. So the round reruns at every poll, with the same item first.
    • On 2026-10-10, feat(cli): sandbox enforcement audit declared vs engine vs enforced (devops sandbox audit) #698's call ran about 18 minutes per attempt. The gateway's timeout for the background tier counts time in the queue, and the client retries a 408 up to four times. The gateway logged 31 such 408s from the Service in two hours.
  3. Intake embeds its whole comparison set again on every run that checks a candidate.

    • _embed (src/devops_cli/roadmap/intake.py:1095-1107) embeds every item, open and closed, and every issue closed as not planned. That is about 650 texts, sent in about 21 requests, to decide one to five candidates.
    • build_intake_model() runs on every run (run.py:463-472). Its _embedder (src/devops_cli/roadmap/intake_model.py:155-160) is a new EmbeddingsEngine, whose in-memory cache (src/devops_cli/ai/rag/embeddings.py:96-108) starts empty.
    • The engine's Valkey layer (embeddings.py:412-437, 497-500) would keep vectors between runs, but the Service never reaches a Valkey:
      • the ConfigMap template (k8s/devops/configmap.example.yaml) has no valkey section, so the host defaults to localhost (src/devops_cli/config/defaults.py:631);
      • k8s/devops/networkpolicy.yaml allows egress to namespace llm only on the gateway's port;
      • k8s/llm/networkpolicy.yaml admits only pods of its own namespace.
    • Over 24 hours, the Service's devops_cli_embedding_cache_hits_total rose by 0, against about 3,500 misses.
    • While more than five fresh candidates wait, _intake_due (run.py:374-382) makes intake due on every poll, and each batch of five embeds the whole set again.
    • The embedding model shares the background tier's backend, so these requests queue behind refine's calls. On 2026-10-10 an intake run failed on an embedding timeout, and its retry embedded the whole set again.

refine.needs_split is written (refine.py:1046) but never read when items are selected. Once point 1 is fixed it does not need to be: an unchanged needs-split item already reads as unchanged.

Owner decisions (proposed)

  1. No new Status or field. An item is settled when the refine record in its Job record (refine.body_hash, refine.section_hash) matches the body the round already listed.
    • Two kinds of item are settled: Ready with a recorded section, and New waiting on a person (needs split, open questions, or a section a person edited).
    • Any edit to the body unsettles the item, and refine runs on it once more.
    • refine.needs_split stays a record for reprioritize, not a selection rule.
  2. Fold fix(roadmap): refine records an item whose model call failed or whose body would exceed the size limit, so it waits for a body change instead of being retried every poll #1526 here.
  3. Embeddings are cached in the existing in-cluster Valkey cache (k8s/llm/valkey.yaml), through the embedder's existing Valkey layer.
  4. The sections v0.2.32 stacked are cleaned up by hand once v0.2.33 is live, not in code. Before 1.0 there is no shim that reads [end-marker].
  5. Out of scope:

Proposed design

Refine (src/devops_cli/roadmap/store.py, refine.py):

  • Item gains body: str = "". join_items already passes the body from the listing. _consider hashes it.body instead of calling read_issue_body.
  • refine_one_item keeps its own read for the items it selects, and apply_refine keeps its re-read before writing. A body edited after the listing is still caught before any model call or write.
  • When the size guard skips an item, apply_refine records refine.body_hash and refine.section_hash for the body refine saw, and writes no body. The item then reads as unchanged until its body changes.
  • When a model call fails, apply_refine records the body hash it saw under a new RefineRecordKey.FAILED_BODY_HASH.
    • A second failure on the same hash records the item as unchanged, the way the size guard does.
    • A success clears the key.
    • plan_refine stays write-free.

Intake (configuration only):

With #1535: the check sits in selection, ahead of the background enhancement lane's per-item workflows, so a settled item never becomes a Workflow. The Valkey cache serves every task pod.

Acceptance criteria

Feasibility

Fits one pull request because:

  • The refine part is small. It is one field on Item, one line in _consider, and two record writes in apply_refine, all tested on the in-memory store with a fake model.
  • The intake part is configuration only. It is the ConfigMap template and two policy rules, using cache code that already exists and is tested (tests/test_embedding_cache.py).
  • Little new surface. No new module; the only schema change is one Job record key.

It needs v0.2.33 (#1470, #1515) to ship first, and lands before #1535's background enhancement lane.

Related: #1470, #1515, #1526 (folded), #1533, #1534, #1535, #1113.

Activity

  1. added
    type/bug
    scope/ai
    scope/roadmap
    on Oct 10, 2026
  2. dan-petty-bot commented on Oct 10, 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: P2-Medium. The owner explicitly requested it and it eliminates repeated model calls and ~48 REST reads per hour, but the system still functions correctly without it.
    • Value: Medium. It saves significant compute (model calls, API requests, embedding calls) and reduces latency for the refine and intake jobs, but does not change user-visible output.
    • Effort: Medium. It touches refine.py, store.py, intake.py, config defaults, and Kubernetes network policies, but each change is well-scoped and the code paths are already identified.
  3. added
    status/blocked
    on Oct 11, 2026
  4. dan-petty commented on Oct 11, 2026

    @dan-petty
    OwnerAuthor

    Blocked by #1562: the roadmap Service's machine account is suspended, and the Service is held at 0 replicas. This item develops the Service or can only be checked on it, so it waits until the account is reinstated or the jobs act as a GitHub App.


    Generated by Claude Code

  5. added this to the v0.2.38 milestone on Oct 17, 2026
  6. changed the title [-]perf(roadmap): a settled item costs no body read, model call or embedding until its text changes, with refine judging it from the listing it already read and intake's embeddings cached in Valkey[/-] [+]perf(roadmap): a settled item costs no body read or model call until its text changes, with refine judging it from the listing it already read[/+] on Oct 18, 2026
  7. added
    priority/p0-critical
    on Oct 18, 2026
  8. modified the milestones: v0.2.38, v0.2.39 on Oct 21, 2026
  9. added
    status/in-progress
    and removed
    status/blocked
    on Oct 22, 2026
  10. added a commit that references this issue on Oct 22, 2026
    7db9819
  11. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1824, merged into release/v0.2.39 as 7db9819.

    Cause: Refine read the body of every item it checked, one uncached REST request per item at every hourly run, even when nothing had changed, because Item carried no body and the listing the round had already read was thrown away. Two kinds of item were also spent again in every round: an item whose refined body would pass the 65,536-character limit was skipped after its model call with empty hashes, and an item whose model reply never fit the schema recorded nothing. In both cases apply_refine had nothing to write, and has_writes only counted refined items, so a round whose only selected item was one of these never reached apply_refine at all.

    Change: Item gains body, taken from the issue listing both stores already read through join_items, and RefineRecordKey gains FAILED_BODY_HASH. Selection hashes the listed body, so an item whose recorded hashes match it costs no body read and no model call. refine_one_item's own read and apply_refine's re-read before each write stay, so a body edited after the listing is still caught, and the --item path keeps its one read. An item too big to refine now returns the hashes of the body it saw, marked record_only. apply_refine re-reads the body and records those hashes without writing a body, so the item reads as unchanged until its text changes. A StructuredOutputValidationError or ReplyRejectedError is recorded as an item-caused failure: the first failure on a body sets refine.failed_body_hash, a second on the same body records the body…

    9 file(s) changed.

    How it was verified

    Check runs at 3cce4b6:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Changed-Test Independence: pass
    • Analyze (actions): pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • Rule Pack Tests: pass
    • Fail-to-Pass Check: pass
    • Fail-to-Pass Self-Check: pass
    • Static Analysis: pass
    • Dependency Freshness: skipping
    • Service Image: skipping
    • DevContainer Image: skipping

    Acceptance Criteria of docs/agent/tasks/task-1539-settled-items-cost-no-body-read-or-model-call.md:

    • A refine round makes no read_issue_body call and no model call when every New item's recorded hashes match its body and every Ready item has a recorded section (tests/test_roadmap_refine.py::test_a_round_after_refine_left_items_new_skips_them_reading_no_body_and_calling_no_model).
    • Editing one New item's body outside the section selects only that item, with one body read and one model call, and writes nothing in the planning round; the needs-split items left unchanged are skipped as unchanged (test_editing_one_settled_items_body_selects_only_it_with_one_body_read_and_one_model_call).
    • An item whose refined body would exceed 65,536 characters is selected once, then skipped as unchanged until its body changes, and its body is never written (test_an_item_whose_refined_body_is_too_big_is_selected_once_and_its_body_never_written).
    • An item whose model reply fails the schema twice in a row on the same body is skipped as unchanged until its body changes (test_two_replies_that_never_validate_on_the_same_body_settle_the_item). One failure followed by a success refines it and leaves no refine.failed_body_hash (test_a_failure_followed_by_a_success_refines_the_item_and_clears_the_failure).
    • A StructuredOutputValidationError and a ReplyRejectedError are recorded, and a plain AIClientError is not (test_only_a_failure_the_items_own_text_caused_is_recorded). An item whose model call fails twice with a gateway timeout records nothing, and the next round selects it again (test_a_gateway_failure_records_nothing_and_the_next_round_selects_the_item_again).
    • A round whose only selected item is too big, or fails on its own text, still writes its record through the plan-then-apply path of devops roadmap refine --confirm (test_a_round_whose_only_item_is_too_big_or_fails_still_records_it_through_the_cli) and of the refine job of devops roadmap run (test_the_runs_refine_job_records_an_item_too_big_to_refine).
    • plan_refine writes no body and no record in these cases (test_planning_a_round_writes_no_body_and_no_record_for_an_item_too_big_or_failing), and a body that changed between the plan and the apply is left unrecorded with the existing warning (test_a_body_edited_between_the_plan_and_the_apply_is_recorded_as_neither_too_big_nor_failed).
    • Both stores return Item.body from the listing: the in-memory store from items(), items(release=), backlog() and item() (tests/test_roadmap_store_contract.py::test_an_item_carries_the_body_of_the_issue_listing_it_was_read_from), and the GitHub store from items(release=) and backlog() with only the listing requests sent, none per issue (tests/test_roadmap_github_store.py::test_items_carry_the_body_of_the_listing_they_were_read_from_with_no_request_per_issue).
    • changelog.d/1539.md lists the settled items under ### Changed and fix(roadmap): refine records an item whose model call failed or whose body would exceed the size limit, so it waits for a body change instead of being retried every poll #1526's part under ### Fixed.
    • uv run devops ci is the pull request's gate.
    • Pending a person: with this change checked out, run devops roadmap refine --repo dan-petty/devops-cli --confirm, then devops roadmap refine --repo dan-petty/devops-cli --dry-run, and edit no issue in between. The second run selects none of the items the first round refined or found unchanged: it lists each under ## Skipped Items as unchanged and sends no model request for it.
    • Pending a person: delete feat(cli): sandbox enforcement audit declared vs engine vs enforced (devops sandbox audit) #698's 6 stacked blocks, each running from a refine start marker (<!-- devops-roadmap-refine:start -->) to a literal [end-marker] line; the body is 57,664 characters, near the 65,536 cap. Do the same in the managed repositories' items that hold such blocks. This does not gate the change.
  12. added 2 commits that reference this issue on Oct 23, 2026
    f209f6c
    0a2bfe1
  13. removed
    status/in-progress
    on Oct 30, 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/p0-criticalscope/aiscope/roadmaptype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions