Skip to content

feat(review): group analysis is profiled as its own stage, and analysis.json counts dispatched, replayed and failed jobs apart #482

Closed

Description

@dan-petty

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

This section supersedes any text below that conflicts with it.

Decisions

Scope

Delivery

  1. PR 1 (M), Closes feat(review): group analysis is profiled as its own stage, and analysis.json counts dispatched, replayed and failed jobs apart #482. Tests come first.

Acceptance criteria

  • Group analysis runs inside review_stage("group_analysis"). profile.json credits its model calls and replays to that stage, with none to report or unstaged, and report's wall time leaves out group analysis.
  • analysis.json holds dispatched, replayed and failed in place of model_calls, and they sum to the number of jobs.
  • review.md's Model Analysis section prints the three counts in place of Model Calls.
  • The terminal profile line shows each stage's replayed count next to its calls, and it lists a stage that only replayed.
  • Two-run test: the review's report step runs twice with the real LLMClient over an httpx2 MockTransport, with the response cache in tmp_path. On the second run the transport sees no request, the group_analysis stage shows llm_calls 0 and cached_calls equal to the number of groups, and analysis.json shows replayed equal to the number of groups, with dispatched and failed both 0.
  • Failure test: a fake client that raises for one of N groups gives failed 1 and dispatched N-1.
  • With --no-cache, replayed is 0.
  • Tests run offline, with no network and no model, and each runs in under 1 s.
  • uv run devops ci passes.

Current references

  • model_calls field: src/devops_cli/review/analysis.py:209. It starts at 0 at :792, is set to len(jobs) at :810 and is written into the report at :860. The exception path at :812-830 records model-call-error, and review.md prints the count at :917.
  • Group job: src/devops_cli/review/analysis.py:689-750, with the chat call at :700-706. The static system prompt is loaded at :795, and the job JSON is the user prompt at :699.
  • Cache-hit flag: src/devops_cli/ai/client/models.py:121, set at src/devops_cli/ai/client/unified.py:569-575.
  • Validator refusal: ReplyRejectedError at src/devops_cli/ai/client/models.py:68-77 carries the reply and is never cached.
  • Profiler: cached_calls at src/devops_cli/ai/review/profile.py:94, credited to the active stage at :245-250. review_stage is at :411-423.
  • Stage wrap point: src/devops_cli/ai/review/pipeline.py:4854, inside the runner's report stage at src/devops_cli/ai/review/runner.py:1070-1071.
  • Terminal profile line: src/devops_cli/ai/review/runner.py:949-958. It prints only llm_calls and hides a stage that runs under 1 s with no llm_calls.
  • Tests to update: tests/test_review_group_analysis.py:287, :509, :515 and :648.
  • Test patterns: tests/llm_stream_fakes.py:105-128 (route_llm_clients) sends every request from an LLMClient built inside the code under test to an httpx2 MockTransport. tests/test_ai_client_structured.py:423-438 shows a cached reply served with no second request, under the public_dns fixture (tests/conftest.py:191-192).
  • inject_prompt_cache_points: src/devops_cli/ai/pydantic_ai_bridge.py:378. Only tests/test_pydantic_ai_workflows.py:108-130 calls it.

Dependencies and order


Context & Rationale

Two caches can save review work: devops-cli's LLM response cache (devops ai cache status) and Anthropic/OpenAI prompt caching (the target of inject_prompt_cache_points), which can skip reprocessing a persona's static system prompt on every page. Neither is measured during reviews. Before vLLM was removed in #734, the tuner showed how much prefix reuse matters: identical prompts made vLLM's prompt processing nearly free.

Scope & Deliverables

  • Context & Rationale*: Two caches can save review work: devops-cli's LLM response cache (devops ai cache status) and Anthropic/OpenAI prompt caching (the target of inject_prompt_cache_points), which can skip reprocessing a persona's static system prompt on every page. Neither is measured during reviews. Before vLLM was removed in feat(k8s): modernize monitoring stack, llm profiles, traefik routing, and remove squid proxy #734, the tuner showed how much prefix reuse matters: identical prompts made vLLM's prompt processing nearly free.
  • Deliverable*: Report response-cache hit rates per review run. vLLM was removed in feat(k8s): modernize monitoring stack, llm profiles, traefik routing, and remove squid proxy #734 and the Ollama nodes that replaced it export no metrics, so there is no per-backend prefix-cache hit rate (vllm:prefix_cache_*) to report. Check that persona prompts keep static text ahead of page content so the prefix is shared, and fix any ordering that defeats it.

Strategic Alignment

Scope added 2026-10-02: the release review evaluation could count cache replays only by subtracting dispatched calls from persona pages, because profile.json cached_calls is 0 in every session (#816). Persona review replayed 192 of 268 replies in session 20261002-163203, 238 of 319 in 20261002-180320 and 301 of 341 in 20261002-200610. Verification replayed 3 of 76 and 6 of 99 in the first two. One hit rate per run would hide that split. Verification is now the larger cost (63%, 67% and 82% of those runs' prompt tokens), and it almost never replays. StageProfile already has a per-stage cached_calls field (ai/review/profile.py:92, counted at :216-218). Once #816 sends hits through the call observers, the figures exist, and this item reports them. Depends on #816.

  • The terminal summary and review.md state, for persona review and for verification, how many replies were generated and how many were replayed from the response cache.
  • A test runs the same review twice with the response cache on, using the real client over a fake HTTP transport, on findings with no executable criteria. The second run's profile shows verification cached_calls equal to its verifier calls and llm_calls 0 for that stage, and the summary prints both rates. The test runs offline.

Scope added 2026-10-02 from review session 20261002-214641 (.data/review-evaluation-20261002-s6.md, section 7): 9 of S6's 10 VERIFIED findings were verdicts replayed from the previous session's cache, stamped with S6's time.

  • A finding whose verdict came from a cached verifier reply says so in findings.json and review.md.

Proposed design

Problem statement

The review process currently counts all LLM model calls under a single 'model_calls' field in analysis.json and review.md, without distinguishing between dispatched jobs (which actually called the model), replayed jobs (which used cached responses) and failed jobs (which raised errors). Additionally, group analysis is not profiled as its own stage, and the wall time of group analysis overlaps with the report stage, leading to inaccurate timing data.

Acceptance criteria

  • Criterion 1: Group analysis runs inside review_stage("group_analysis")
    Verification: Verify that all group analysis code execution is wrapped within a review_stage("group_analysis") context manager.
  • Criterion 2: Profile.json credits model calls and replays to the 'group_analysis' stage, with none to 'report' or 'unstaged'
    Verification: Check that profile.json shows non-zero 'llm_calls' and 'cached_calls' in the 'group_analysis' stage, and zero in 'report' and 'unstaged' stages.
  • Criterion 3: Analysis.json holds 'dispatched', 'replayed' and 'failed' in place of 'model_calls'
    Verification: Validate that analysis.json contains 'dispatched', 'replayed', and 'failed' fields instead of 'model_calls', and that these sum to the number of jobs.
  • Criterion 4: Review.md's Model Analysis section prints the three counts in place of 'Model Calls'
    Verification: Confirm that review.md shows 'dispatched', 'replayed', and 'failed' counts instead of a single 'Model Calls' count.
  • Criterion 5: Terminal profile line shows replayed count next to calls for each stage
    Verification: Run a review and check the terminal output shows 'stage_name duration (calls, cached_calls)' format.
  • Criterion 6: Two-run test: second run uses cache with no new requests
    Verification: Execute two identical reviews with caching enabled, verify second run has 0 LLM calls and cached_calls equal to number of groups in group_analysis stage.
  • Criterion 7: Failure test: one job raises error results in 'failed' count
    Verification: Create a fake client that raises an error for one of N jobs and verify analysis.json shows 'failed': 1 and 'dispatched': N-1.
  • Criterion 8: With --no-cache, 'replayed' is 0
    Verification: Run review with --no-cache flag and verify 'replayed' count in analysis.json is 0.

Key questions

  • What are the specific changes needed to split dispatched, replayed, and failed job counts?: The model_calls field needs to be removed from AnalysisReport and replaced with dispatched, replayed, and failed counts. Each job execution must distinguish between these three states: dispatched (normal call), replayed (cached), and failed (error). [sources: src/devops_cli/review/analysis.py:209, src/devops_cli/review/analysis.py:810, src/devops_cli/review/analysis.py:860]
  • How does the profiler track cached calls?: The profiler tracks cached calls in StageProfile.cached_calls and credits them to the active stage through the observe method in ReviewProfiler, which is called from the LLM client's observation system. [sources: src/devops_cli/ai/review/profile.py:94, src/devops_cli/ai/review/profile.py:245, src/devops_cli/ai/review/profile.py:250]
  • Where is group analysis currently executed in the review pipeline?: Group analysis is currently executed as part of the 'report' stage in the review pipeline, which causes its timing to overlap with report generation and makes it difficult to isolate its performance. [sources: src/devops_cli/ai/review/pipeline.py:4854, src/devops_cli/ai/review/runner.py:1070, src/devops_cli/ai/review/runner.py:1071]
  • Should the group analysis stage be moved out of the report stage?: Yes, to properly isolate its timing and resource usage, the group analysis should run as its own dedicated stage separate from the report stage. (proposed) [sources: src/devops_cli/ai/review/pipeline.py:4854, src/devops_cli/ai/review/runner.py:1070, src/devops_cli/ai/review/runner.py:1071]
  • How should the terminal profile line be updated to show replayed counts?: The terminal profile line in runner.py needs to be modified to display cached_calls alongside llm_calls for each stage, and it should list stages that only replayed. [sources: src/devops_cli/ai/review/runner.py:949, src/devops_cli/ai/review/runner.py:958]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#876

Activity

  1. added this to the v0.2.23 milestone on Sep 24, 2026
  2. added
    type/feature
    scope/ai
    priority/p2-medium
    on Sep 24, 2026
  3. modified the milestones: v0.2.23, v0.2.24 on Sep 28, 2026
  4. added a commit that references this issue on Sep 28, 2026
  5. modified the milestones: v0.2.24, v0.2.23 on Sep 30, 2026
  6. removed this from the v0.2.23 milestone on Oct 1, 2026
  7. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from the shipped v0.2.23 to the backlog. It is still valid (checked 2026-10-01), and P2 items don't displace P1 work in the planned releases.

  8. added
    scope/review
    on Oct 2, 2026
  9. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Frozen by the evidence-first review redesign (#1137, owner direction of 2026-10-03): patches to the model generator and verifier stop, and tool-layer fixes continue. The review's use of ai/response_cache.py and its page-retry loop are replaced in phase P3 by content-addressed review jobs (P3-1 in #1137, filed when that phase starts). This item stays open, labelled status/blocked, and closes when P3-1 lands. Chat and analysis cache effectiveness is #816's and #1014's.

  10. added
    status/blocked
    on Oct 3, 2026
  11. changed the title [-]feat(ai): llm cache effectiveness during reviews response cache and prefix cache[/-] [+]feat(review): group analysis is profiled as its own stage, and analysis.json counts dispatched, replayed and failed jobs apart[/+] on Oct 18, 2026
  12. removed
    status/blocked
    on Oct 18, 2026
  13. added this to the milestone on Oct 20, 2026
  14. dan-petty commented on Oct 20, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 2954109 (see proposed design in issue body).

  15. removed this from the milestone on Oct 23, 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/p2-mediumscope/aiscope/reviewtype/feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions