Skip to content

refactor(review): delete the legacy segment engine so the orchestrator is the only review engine #995

Closed

Description

@dan-petty

Context & Rationale

ai/review/runner.py holds two review engines. _execute_review_workflow (:2193-2289) forks at :2240 on type(clients.analysis).__name__ == "LLMClient": production goes to ReviewPipelineOrchestrator through 5 runner functions (150 lines); any other client, or a page with no file header, goes to _run_persona_loop (:1267-1349) and its helpers (_run_review :1165-1217, _execute_review_segments :920-988, _execute_findings_validation :1031-1115, _execute_final_recompose :1118-1162, _save_findings_json :427-472): 35 functions and 1,016 lines reachable only from that branch. Checked at 9c879ae (release/v0.2.25 tip).

  • Six test files build ReviewClients(analysis=DummyClient()) or a MagicMock and so test the legacy engine, not the one production runs: tests/test_review_path.py, test_review_history.py, test_review_project_conventions.py, test_review_symbol_delta.py, test_review_verification_task.py, test_review_runner.py.
  • Two modules write findings.json (pipeline.py:3701, runner.py:427), so history.py has to rank duplicate sessions.
  • The orchestrator is typed Any in the runner, and the runner reaches into orchestrator._get_server_info().
  • pipeline.py and runner.py co-change in 22 of runner's 23 commits.

Deletion test: the legacy engine is a second implementation of one concept. Deleting it makes the complexity vanish rather than move.

Scope & Deliverables

  • Deliverable: one review engine. _execute_review_workflow resolves the session subject and hands it to the orchestrator. The orchestrator takes the model client through a small chat protocol, so a fake adapter runs the real path in tests. The legacy functions, the class-name check and the second findings.json writer are deleted, not wrapped.
  • Tests: the six files above re-point at the orchestrator with a fake chat adapter. The 8 patches of _run_persona_loop, _run_review, _print_review and _load_shared_metadata_for_pages go with the code they patched.
  • Key questions (open):
    • What is the smallest chat protocol the orchestrator needs, and does tests/llm_stream_fakes.route_client already satisfy it?
    • Which legacy-only behaviours (pages with no file header) must the orchestrator absorb, and which are dead?
  • Constraint: no shims (pre-1.0 policy). refactor(review): review session store that owns layout, fingerprints and verdicts #771 and feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772 edit the same files; sequence the three to avoid rebases.

Strategic Alignment

Scope added 2026-10-02: checked at 38517a8. Production reaches the legacy engine in one case: no review page has a diff --git or ### File: header, so all_files is empty (ai/review/runner.py:2230), _run_profiled_session returns None after pre-analysis (:2102-2103) and the workflow falls through to _run_persona_loop (:2287). A branch or PR diff that changes only files in CONST_REVIEW_GENERATED_FILES (uv.lock and the other lockfiles, config/constants.py:582) gives one empty page (ai/review/chunker.py:431-432), and so does an empty PR diff, which _prepare_pr_content does not refuse (runner.py:1895-1937; a branch review exits at :1883-1885). The engine then sends that empty page to the model as "segment 1/1" for each persona, writes its own session, and review pr --post posts the result. An offline probe of _execute_review_workflow with a lockfile-only diff reached _run_persona_loop. The class-name check never fails in production: _make_review_clients (runner.py:1543-1584) is the only ReviewClients constructor in src and always builds LLMClient, which has no subclass; the gateway, Copilot and OpenAI-compatible backends are provider branches inside it (ai/client/unified.py:925). review path (with --watch and review benchmark), review branch, review pr, the devops ai review alias and the MCP review_path, review_branch and review_pr tools (ai/mcp/server.py:136-181, dispatched in-process to the same commands) all use it. The same fork hides a second defect: --summary ("Show segment metadata without running a full review", lang/en/help.py:951) is read only after the LLMClient branch returns (runner.py:2240-2276), so with any file header it runs a full review. Corrections: history.py ranks repeat reviews of one subject (#607, ai/review/history.py:1-15), not copies from two writers, so that ranking stays. The issue's 35 functions and 1,016 lines were counted at 9c879ae. At 38517a8, 35 functions (1,043 lines) are reachable only from _run_persona_loop: 32 in runner.py (975 lines) and _merge_segment_results, _reconcile_single_finding and _reconcile_verified in ai/review/verification.py (:2143-2151, :2170-2230). The 32 include runner's own _resolve_ollama_urls (runner.py:137-152), which only legacy functions call; the orchestrator uses its own copy (ai/review/pipeline.py:197). _collect_files (called only by tests) and _resolve_static_analyzer_states are already dead. tests/test_review_symbol_delta.py builds a real LLMClient and already runs the orchestrator. The legacy engine is the only reader of the compose task (ai.tasks.compose, ReviewClients.compose, PersonaDefinition.compose_prompt, ai/tasks/compose.md), of three task prompts (paginated_review_protocol.md, review_output_instruction.md, path_review_prompt.md), and of the prompt_builder and agents_md arguments, whose _load_agents_md still runs on every review (runner.py:1708, :1891, :1935). #987 (b1fddd0, after the baseline) added full_output to the same function and left the fork as it was. #1009 (79e1e93) did not touch runner.py. #789 (P3, backlog) reports a defect in the legacy recompose (runner.py:1149, verification.py:2207-2230). Production never reaches the recompose, because a header-less diff gives one page, and this item deletes it, so #789 closes with this item.

Acceptance criteria

  • _execute_review_workflow has no class-name check and one engine. _run_persona_loop and every function only it reaches are deleted (35 functions, 1,043 lines at 38517a8: 32 in runner.py, runner's _resolve_ollama_urls among them, and 3 in verification.py; the PR lists them), with the dead _collect_files and _resolve_static_analyzer_states. rg '_run_persona_loop|__name__ == "LLMClient"' src tests finds nothing.
  • When no review page names a file, the review sends no model request, runs no pre-analysis, writes no session and posts no PR comment. It prints one line saying the diff has no reviewable file and exits 0. One test covers a branch diff that changes only uv.lock, and one covers an empty PR diff with --post. Both use a fake client that fails the test on any call, and both fail at 38517a8, where the legacy engine calls the client and the orchestrator's constructor has already made a session directory (ai/review/pipeline.py:1482).
  • --summary prints the analysis metadata of the files the pages name and returns before the orchestrator is built. A test runs review path <tmp dir> --summary with a fake client and asserts no model call and no new session directory. It fails at 38517a8.
  • ReviewPipelineOrchestrator types llm_client and verification_client with one typing.Protocol that names what the review calls: chat (ai/review/verification.py:2128), chat_messages (ai/agents/agent.py:887, ai/analyze/outlines.py:119), get_context_window (ai/review/pipeline.py:2285) and backend_info. LLMClient satisfies it under mypy, and so do the parameters the orchestrator hands the client to: PydanticAgent(client=...), _execute_pre_analysis_batch (pipeline.py:892-895, typed LLMClient | None today) and the verifier. The orchestrator's getattr(..., "_config", None) reads (pipeline.py:1520, :1600, :2497, :2798) work with a fake that has no config. The runner calls no underscored orchestrator member (_get_server_info today, runner.py:2241), and no runner parameter for the orchestrator is typed Any.
  • The tests that drove the legacy engine drive _execute_review_workflow through the orchestrator with a fake that implements the protocol, or are deleted with the code they covered: test_review_path.py, test_review_runner.py, test_review_history.py, test_review_project_conventions.py, test_review_verification_task.py, test_review_prompt_guardrails.py, test_review_prompt_consistency.py and test_review_page_line_numbers.py, and the _merge_segment_results and _reconcile_verified tests in test_review_verification.py. test_category_metrics.py writes its sessions through the pipeline's writer, not _save_findings_json. No test patches a deleted name.
  • generate_consolidated_report is the only code that creates findings.json. devops review verify still rewrites it to record a person's verdict (ai/review/adjudication.py:190-204).
  • The compose task is deleted: the ai.tasks.compose field, the four AI_TASK_COMPOSE_* keys (config/options.py:48-51), the four DEVOPS_CLI_AI_TASK_COMPOSE_* variables (config/env.py:52-55), "compose" in commands/ai.py:170, ReviewClients.compose, PersonaDefinition.compose_prompt and ai/tasks/compose.md. So are the three legacy task prompts, sanitization._build_prompt, runner._build_path_prompt, _load_agents_md, and every _execute_review_workflow parameter that only the legacy engine read, with the callers' arguments. test_custom_personas.py, test_telemetry_instruments.py and test_ai_gateway_base_url.py stop naming the compose prompt or task.
  • Generated docs (docs/CONFIGURATION.md, docs/ENV_VARS.md, the CLI reference) are regenerated and name no compose task.
  • The new and changed tests run offline, with no model, network or scanner.
  • changelog.d/995.md records the lockfile-only and --summary fixes under ### Fixed, and the compose task and its variables under ### Removed. CHANGELOG.md is not edited.
  • uv run devops ci passes.
  • (person-run) On a branch whose only change is uv.lock, devops review branch prints the no-reviewable-file line and exits 0. devops review path src/devops_cli/ai/review --summary prints the metadata table, and the gateway shows no request from it.

Key questions

Consolidated from #789

Problem (added). #789 reports that the legacy multi-page recompose sets reportable=False on every UNVERIFIED finding (ai/review/verification.py _reconcile_verified, reached from runner.py). So a multi-page review can drop an unverified HIGH finding and flip REQUEST CHANGES to APPROVE. This item deletes that recompose, and its body already says #789 closes with it. #789's placement note (2026-10-01) says it is "best closed with #772", and #772 moved the deletion here on 2026-10-02.

Acceptance criteria (added).

Placement. P2 stays (#789 was P3). In the review redesign (#1137), this item is #1151's legacy-engine piece and lands first, as a child of #1151, so that runner.py is not deleted by two items.

Update 2026-10-08: refinement

Production no longer reaches the legacy engine: #948 returns no-file reviews first (ai/review/runner.py:2245-2266, :2355-2356). The criterion 'writes no session and posts no PR comment' contradicts #948.

  • The no-file path stays _review_routed_files_only with no model call (tests/test_review_path_routing.py:253).
    The --summary defect holds (runner.py:2392); the PR recounts the counts.

Activity

  1. added
    type/refactor
    scope/review
    priority/p2-medium
    on Oct 2, 2026
  2. added this to the v0.2.34 milestone on Oct 10, 2026
  3. dan-petty-bot commented on Oct 10, 2026

    @dan-petty-bot
    Collaborator

    Moved to v0.2.34: v0.2.34 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)

  4. dan-petty commented on Oct 11, 2026

    @dan-petty
    OwnerAuthor

    Merged

  5. added a commit that references this issue on Oct 11, 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/reviewtype/refactor

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions