Repository navigation
Description
From the open-library audit of 2026-10-22 (ranked R02, about 4200 lines of source and tests; risk L). Merged ai-core-2, ai-core-5, ai-core-7 and core-5 (ai/exceptions.py is the same file in two reports; budget_diff_chunks moved to R05). Spot-checked: 0 src importers of ai.exceptions/profiles/result/run/ext_langchain; direct.py is reached only from unused LLMClient methods; get_provider has 0 callers outside ai/providers; 17 of 17 sampled helper names have 0 callers; 6 of 7 exception mirrors have 0 references outside their definitions. Sequence after R01 (same tests and conftest providers registry).
What the code is (ai-core-2): Modules whose body re-exports pydantic_ai.exceptions, pydantic_ai.profiles/, pydantic_ai.result, pydantic_ai.run and pydantic_ai.direct with thin wrappers. ext_langchain.py duplicates pydantic_ai.ext.langchain. None has an importer in src: ai/exceptions, profiles, result, run and ext_langchain have zero; ai/direct.py is reached only from LLMClient.direct_request/model_request(_sync) (unified.py lines 959-1085), which have no callers.
Files: src/devops_cli/ai/exceptions.py (175), src/devops_cli/ai/profiles/init.py (216), src/devops_cli/ai/result/init.py (110), src/devops_cli/ai/run/init.py (131), src/devops_cli/ai/ext_langchain.py (131), src/devops_cli/ai/direct.py (338), src/devops_cli/ai/client/unified.py (126)
Existing tool considered: Import from pydantic_ai directly where ever needed (pydantic_ai.exceptions, .profiles, .result, .run, .direct, .ext.langchain). All are already installed (pydantic-ai 2.54.0). Behaviour gap: None: no production caller. The wrappers add only defaults, tracing and name normalisation.
Evidence: /tmp/open-libs-audit-deadscan.py (module-level importer scan) plus grep for string/lazy imports; also re-checked relative and importlib imports (none for these modules).
Tests affected: tests/test_pydantic_ai_exceptions.py (441); tests/test_pydantic_ai_result.py (138); tests/test_pydantic_ai_run.py (114); tests/test_ext_langchain.py (103); tests/test_pydantic_ai_direct.py (239); tests/test_pydantic_ai_profiles_and_providers.py (profiles part); tests/test_model_contract.py; tests/test_ai_spend_dispatch.py; tests/test_review_backend_activity.py (model_request references); tests/test_runtime_security_and_ssrf_hardening.py (ext_langchain reference)
Risk (L): Zero src importers by AST and grep; only tests import them.
What the code is (ai-core-5): A second, hand-rolled httpx2 provider stack (get_provider/register_provider/reset_providers). Nothing in src calls get_provider; CopilotProvider.generate returns a stub dict. Only tests (and the test-only MockProvider) use it. The live code is create_pydantic_ai_provider in the same init, which returns native pydantic_ai providers.
Files: src/devops_cli/ai/providers/base.py (41), src/devops_cli/ai/providers/anthropic.py (84), src/devops_cli/ai/providers/copilot.py (35), src/devops_cli/ai/providers/ollama.py (69), src/devops_cli/ai/providers/openai.py (69), src/devops_cli/ai/providers/init.py (25)
Existing tool considered: pydantic_ai.providers.* via the existing create_pydantic_ai_provider (kept). Behaviour gap: None; legacy classes are never invoked in production.
Evidence: grep get_provider/register_provider/BaseLLMProvider/CopilotProvider across src: zero callers outside ai/providers.
Tests affected: tests/test_providers.py; tests/test_openai_auth.py; tests/mock_provider.py; tests/conftest.py (lines 86-107, 171-175); tests/test_rag_loopback_policy.py (OllamaProvider assertions); tests/test_security_sandbox_and_protection.py (OllamaProvider test); tests/test_pydantic_ai_profiles_and_providers.py (get_provider tests)
Risk (L): Dead in src; MockProvider registration in conftest must be removed.
What the code is (ai-core-7): Functions with zero src callers that wrap library calls: combine_toolsets/prefix_toolset/filter_toolset/rename_toolset/require_approval_toolset (native toolset .prefixed()/.filtered()/.renamed()/.approval_required()), normalize_thinking_level/service_tier/tool_choice, create_async_retry_transport, normalize_agent_retries, four of the six format_*_as_xml wrappers around pydantic_ai.format_as_xml, create_template_str, create_pydantic_ai_agent (no caller; includes an inspect.signature fallback to PydanticAgent), get_persona_pydantic_agent, execute_structured_workflow(_sync), inject_prompt_cache_points, budget_diff_chunks.
Files: src/devops_cli/ai/pydantic_ai_bridge.py (270), src/devops_cli/ai/tools/init.py (88), src/devops_cli/ai/format_prompt.py (74), src/devops_cli/ai/settings/init.py (52), src/devops_cli/ai/retries/init.py (50), src/devops_cli/ai/toolsets/init.py (40), src/devops_cli/ai/concurrency.py (22), src/devops_cli/ai/template/init.py (15), src/devops_cli/ai/output/init.py (16), src/devops_cli/ai/context_budget.py (67)
Existing tool considered: The pydantic_ai API each one wraps (call sites in tests become direct calls). Behaviour gap: None; no production caller.
Evidence: grep -w per name in src excluding definition and all: 0 references for each (28 names checked); tests reference each from exactly one file.
Tests affected: tests/test_pydantic_ai_workflows.py; tests/test_pydantic_ai_toolsets.py; tests/test_pydantic_ai_settings.py; tests/test_pydantic_ai_retries.py; tests/test_pydantic_ai_format_prompt.py; tests/test_pydantic_ai_template.py; tests/test_pydantic_ai_output.py; tests/test_pydantic_ai_concurrency.py; tests/test_pydantic_agent.py
Risk (L): Mechanical dead-symbol removal; test count is approximate (about 500 lines).
What the code is (core-5): ModelAPIError, ModelHTTPError, UsageLimitExceeded, ConcurrencyLimitExceeded, RunCancelled, IncompleteToolCall and SuspendedResponseExpired are dual-inheritance mirrors of pydantic_ai.exceptions. An AST scan finds 0 Load references to them anywhere in src outside the 3-layer re-export lists. ai/exceptions.py and concurrency.py use pydantic_ai.exceptions directly.
Files: src/devops_cli/exceptions/ai_pydantic.py (177), src/devops_cli/exceptions/ai.py (21), src/devops_cli/ai/exceptions.py (14)
Existing tool considered: pydantic_ai.exceptions itself, the library's public module that the code already imports. Behaviour gap: None in src. The other 8 wrappers are raised or caught by devops code and stay. Observation, not verified at runtime: except ModelRetry at ai/agents/runner.py:146 and :510 catches the wrapper subclass, so it misses a pydantic-ai ModelRetry raised by the library itself.
Evidence: AST scan over src and tests, listing every Name Load per wrapper (/tmp/open-libs-audit/core is not needed: the scan was run inline).
Tests affected: tests/test_pydantic_ai_concurrency.py; tests/test_pydantic_ai_workflows.py
Risk (L): No src caller. The only references are 4 in tests/test_pydantic_ai_concurrency.py and tests/test_pydantic_ai_workflows.py.
Land after the harness deletion (#1836), which shares the tests, conftest registry and invariants lists.
Acceptance criteria:
- The listed modules, symbols and their tests are deleted; none is skipped or xfailed; a grep of src, tests, AGENTS.md and docs (outside docs/agent history and CHANGELOG) for the deleted paths and names returns nothing.
- Every shared list is updated (CONST_ lists, invariants, ceilings fixture, conftest, generated docs) and
devops docs checkis clean. devops cipasses with coverage at or above 90%.
Proposed design
Problem statement
The devops-cli project contains dead code in the AI subsystem that re-exports pydantic_ai components, legacy provider layers, and unused exception mirrors. These components are not used by any production code but still exist in the codebase, increasing maintenance burden and reducing clarity.
Acceptance criteria
- Criterion 1: All dead pydantic_ai re-export facades (ai/exceptions.py, profiles/, result/, run/, ext_langchain.py, direct.py) are deleted from the codebase
Verification: A grep of src directory for any of these files returns no matches - Criterion 2: All legacy provider layer modules (ai/providers/base.py, anthropic.py, copilot.py, ollama.py, openai.py, init.py) are deleted from the codebase
Verification: A grep of src directory for any of these files returns no matches - Criterion 3: All unused exception mirrors (ai_pydantic.py, ai.py, exceptions.py) are deleted from the codebase
Verification: A grep of src directory for any of these files returns no matches - Criterion 4: All dead functions and symbols wrapped by pydantic_ai API are removed from their respective modules
Verification: A grep of src directory for function names like combine_toolsets, prefix_toolset, normalize_thinking_level, etc. returns no matches - Criterion 5: Tests referencing the deleted code are updated to directly import from pydantic_ai instead of the dead wrappers
Verification: All tests pass with coverage at or above 90% - Criterion 6: devops docs check passes without errors after the deletion
Verification: Runningdevops docs checkproduces no output
Key questions
- Are there any production callers of the deleted pydantic_ai re-export facades?: No, the audit states that 'Zero src importers by AST and grep; only tests import them.' [sources: src/devops_cli/ai/exceptions.py, src/devops_cli/ai/profiles/init.py, src/devops_cli/ai/result/init.py, src/devops_cli/ai/run/init.py, src/devops_cli/ai/ext_langchain.py, src/devops_cli/ai/direct.py]
- Are there any production callers of the legacy provider layer?: No, the audit states that 'Nothing in src calls get_provider; CopilotProvider.generate returns a stub dict. Only tests (and the test-only MockProvider) use it.' [sources: src/devops_cli/ai/providers/base.py, src/devops_cli/ai/providers/anthropic.py, src/devops_cli/ai/providers/copilot.py, src/devops_cli/ai/providers/ollama.py, src/devops_cli/ai/providers/openai.py, src/devops_cli/ai/providers/init.py]
- Are there any production callers of the functions wrapped by pydantic_ai API?: No, the audit states that 'Functions with zero src callers that wrap library calls: combine_toolsets/prefix_toolset/filter_toolset/rename_toolset/require_approval_toolset (native toolset .prefixed()/.filtered()/.renamed()/.approval_required()), normalize_thinking_level/service_tier/tool_choice, create_async_retry_transport, normalize_agent_retries, four of the six format_*_as_xml wrappers around pydantic_ai.format_as_xml, create_template_str, create_pydantic_ai_agent (no caller; includes an inspect.signature fallback to PydanticAgent), get_persona_pydantic_agent, execute_structured_workflow(_sync), inject_prompt_cache_points, budget_diff_chunks. Evidence: grep -w per name in src excluding definition and all: 0 references for each.' [sources: src/devops_cli/ai/pydantic_ai_bridge.py, src/devops_cli/ai/tools/init.py, src/devops_cli/ai/format_prompt.py, src/devops_cli/ai/settings/init.py, src/devops_cli/ai/retries/init.py, src/devops_cli/ai/toolsets/init.py, src/devops_cli/ai/concurrency.py, src/devops_cli/ai/template/init.py, src/devops_cli/ai/output/init.py, src/devops_cli/ai/context_budget.py]
- Are there any production callers of the exception mirrors?: No, the audit states that 'AST scan finds 0 Load references to them anywhere in src outside the 3-layer re-export lists. The only references are 4 in tests/test_pydantic_ai_concurrency.py and tests/test_pydantic_ai_workflows.py.' [sources: src/devops_cli/exceptions/ai_pydantic.py, src/devops_cli/exceptions/ai.py, src/devops_cli/ai/exceptions.py]
- What is the expected behavior after deletion of these components?: None; no production caller. The wrappers add only defaults, tracing and name normalisation. [sources: src/devops_cli/ai/exceptions.py, src/devops_cli/ai/profiles/init.py, src/devops_cli/ai/result/init.py, src/devops_cli/ai/run/init.py, src/devops_cli/ai/ext_langchain.py, src/devops_cli/ai/direct.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 22, 2026
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.
The candidate proposes deleting dead code and refactoring AI-related modules, which fits the refactor type.This is a medium-priority refactor as it removes dead code without affecting functionality or security.The change improves code hygiene and reduces maintenance overhead but doesn't directly benefit end users.The effort is low because all the code being removed has no source callers, making it straightforward to delete.dan-petty commentedon Oct 22, 2026
Status set to Ready at ae8c2d9 (see proposed design in issue body).
refactor(ai): delete the dead pydantic_ai facades, the legacy provide…
dan-petty commentedon Oct 22, 2026
What changed
#1869, merged into
release/v0.2.39as ab595c1.80 file(s) changed.
How it was verified
Check runs at 05c4a14:
Acceptance Criteria of
docs/agent/tasks/task-1852-dead-pydantic-ai-facades.md:src,tests,AGENTS.md,README.mdanddocs(outsidedocs/agent/tasks,docs/agent/archiveandCHANGELOG.md) for the deleted module paths and names finds nothing.commands/,server/andmainreaches no deleted module, no top-level symbol or class method insrclost its last reference to the deletion without being deleted, and everyfrom devops_cli... importinsrcandtestsresolves.DEFAULT_*andCONST_*constants and thedevops_cli.configexports, the generateddocs/ERRORS.mdanddocs/TELEMETRY.md) anduv run devops docs checkreports every file up to date.ruff check,ruff format --checkandmypypass oversrcandtests, the swallowed-failure and suppression ceilings equal the counts measured on this tree, and the touched test modules, the architectural-invariant, export-surface,AGENTS.mdclaim and startup-import tests, and every test that imports a touched module pass.uv run devops cipasses on the delivering tree. This change ran the targeted tests and two coverage runs of the tests that import the touched modules, not the gate.feat(release): v0.2.39 (#1947)