Skip to content

refactor(ai): delete the unwired harness port and the capability clones nothing imports #1836

Closed

Description

@dan-petty

Largest verified deletion, zero new dependencies, and every other ai/ deletion (R02-R04) shares its tests, conftest registry and invariants lists, so it must land first. Ranker spot-check: the ten modules total 5,186 lines and the only importer outside the package is commands/ai_harness.py through slots.py. AGENTS.md section 1 forbids zombie code and obsolete shims.

Existing tool considered: No replacement is adopted: the code is unreachable. The names the capability clones copy already exist in pydantic_ai.capabilities (pydantic-ai 2.54.0, pinned). If the owner later wants these features, adopt pydantic-ai-harness 0.59.0 (per audit: MIT, released 2026-10-21; it pins pydantic-ai 2.59.0). The code to delete is about 8700 lines of source and tests (audit of 2026-10-22, spot-checked by the ranker and re-checked by an adversarial verifier). Keeping it means carrying it through every gate run, every refactor and every review, and fixing the defects it produces, for no caller.

Evidence (verifier, 2026-10-22):

  • Premise holds. An AST import graph over src (/tmp/open-libs-audit/verify-R01/graph.py) shows the ten harness modules total 5,186 lines (586+1007+291+175+373+713+718+344+447+532, matching wc -l). The only importer outside the package is commands/ai_harness.py, via harness.slots. Nothing in src imports the ten modules or their symbols. The only reason they load is that harness/init.py imports them. No registry, importlib or subclasses lookup instantiates capabilities by name (AgentSpec.capabilities is an untyped list). No pyproject, pre-commit or CI file mentions them.
  • capabilities.py: a per-symbol importer scan confirms that only BaseCapability, HandleDeferredToolCalls, SystemReminders, _accepts_positional_arguments and the re-exports ToolCallPart, DeferredToolRequests, DeferredToolResults, ToolApproved and ToolDenied have live importers. Pruned in a scratch copy, the file goes from 1,116 to 232 lines. ruff is clean and mypy --strict passes on all 572 src files. The pydantic-ai 2.54.0 pin already exports Thinking, WebSearch, WebFetch, MCP, NativeTool, PrefixTools and the rest (checked with dir(pydantic_ai.capabilities)), so nothing is lost.
  • End-to-end result in the scratch copy: 11,308 tests passed and 3 failed. The same 3 fail on an unmodified git-archive baseline of the same commit (11,443 passed): test_host_sandbox ruff-in-mounts, test_roadmap_reprioritize telemetry gauges, test_test_selection full-gate. Total coverage went from 92.41% to 92.33%, so the 90% gate is safe. devops docs check fails until docs/ERRORS.md is regenerated; regeneration changes only that file (one row removed). devops ai harness status still runs. No pyproject pin changes: no third-party package is used only by the deleted modules (checked: dns, pydantic, pydantic_ai, yaml are all used elsewhere).

Proposed change: Delete src/devops_cli/ai/harness/{agents,compaction,conversation,docs,filesystem,memory,planning,repo_context,shell,workflow}.py (5,186 lines). Reduce harness/init.py to what slots.py, skills.py and constants.py define. In ai/agents/capabilities.py delete every class and helper without a non-test importer (WebSearch, WebFetch, Thinking, NativeTool, MCP, Capability, Instrumentation, UseThreadExecutor, SelectModel, ResolveModelId, PrepareTools, PrefixTools, IncludeToolReturnSchemas, SetToolMetadata, RaiseContentFilterError, ReinjectSystemPrompt, ProcessHistory, ProcessEventStream and their helper models); keep BaseCapability, HandleDeferredToolCalls, SystemReminders, _accepts_positional_arguments and the pydantic_ai re-exports the runner and agent import. Delete the tests of the deleted code (about 2,100 lines of tests/test_harness.py, 14 of 20 tests in test_ai_agent_capabilities.py, 7 of 9 in test_pydantic_ai_native_capabilities.py, single tests elsewhere). Update the shared lists: AGENTS.md line 39 (point at core/process.py's surviving guarded group termination), CONST_DOMAIN_EXCEPTION_MODULES, the bare-exception module list in test_architectural_invariants.py, the swallowed_failures_ceilings.json keys of the deleted files, the conftest compaction reset entry, docs/ERRORS.md (regenerate). Remove exception classes only the deleted modules raise (check MemoryOperationConflictError). Leave commands/ai_harness.py, harness/slots.py and harness/skills.py working. Do not touch the pyproject pins.

Corrections found by the verifier (the change includes them):

  • Delete BaseCapability.prefix_tools and BaseCapability.with_metadata with the clones. They return PrefixTools and SetToolMetadata, so keeping them is an undefined-name failure (ruff F821, mypy name-defined). Name the other symbols the prune must remove, since 'helper models' is vague: the dicts _NATIVE_TOOL_SETTINGS_BUILDERS and _NATIVE_TOOL_PROMPT_BUILDERS, ThinkingPart, CodeExecutionTool, MCPServerTool, WebSearchTool, WebFetchTool, WebSearchUserLocation, ModelSelectionContext, ModelResolutionContext, AgentStreamEvent and the ThreadExecutor alias. Fix the stale 'as ProcessHistory and ProcessEventStream do' sentence in HandleDeferredToolCalls.handle_deferred.
  • Do not blanket-delete tests that reach live code through the clones. Rewrite them with a minimal BaseCapability subclass. In the copy, deleting them newly uncovers: agent.py 24 lines (322-365, load_capability and deferred loading, 81.8% to 77.8%), tools.py 27 lines (188-267, MCPToolset, 83.1% to 66.9%), pydantic_ai_bridge.py:257 and toolsets/init.py 3 lines. The tests to rewrite: test_pydantic_agent.py::test_pydantic_agent_capabilities_and_on_demand (keep, using BaseCapability with get_tools); the MCPToolset half of test_ai_agent_capabilities.py::test_mcp_toolset_and_capability (delete only the MCP-capability half); test_pydantic_ai_native_capabilities.py::test_dual_compatibility_with_devops_cli_pydantic_agent, test_create_pydantic_ai_agent_with_native_capabilities and test_get_persona_pydantic_agent_native_execution (replace Thinking and Capability with BaseCapability or SystemReminders).
  • Split, do not delete, tests/test_validation.py::test_capability_blocked_domains_and_settings_domain_validation. Its k8s.domain and cloudflare.domain half (fix(security): local names come from the public suffix list, and domains match on DNS labels, not string suffixes #887) is the only test of that Settings validation; keep it as test_settings_domain_validation. Delete the WebFetch, WebFetchTool and WebSearchTool half and test_capability_domain_lists_refuse_root_and_leading_dot.
  • Add these missing files to files_owned. Tests: tests/test_pydantic_agent.py (9 tests, 361 lines to delete or rewrite, as above), tests/test_ai_agent_deferred_tools.py (replace Thinking() with BaseCapability() in lines 15, 220 and 221), tests/test_runtime_security_and_ssrf_hardening.py (delete test_web_fetch_capability_propagates_blocked_domains, import at line 10), tests/test_docs.py (~line 772 pins the MemoryOperationConflictError row in ERRORS.md, so remove that element and one True from the tuple). Source: src/devops_cli/ai/harness/skills.py (the duplicate DEFAULT_PYAI_DOCS_TOPICS at its tail), src/devops_cli/config/defaults.py plus src/devops_cli/config/init.py (18 constants and their re-exports orphaned by the deletion: DEFAULT_THREAD_EXECUTOR_{MAX_WORKERS,PREFIX,ID}, DEFAULT_{SELECT_MODEL,RESOLVE_MODEL,PREPARE_TOOLS,PREFIX_TOOLS,INCLUDE_RETURN_SCHEMAS,SET_TOOL_METADATA,RAISE_CONTENT_FILTER,REINJECT_SYSTEM_PROMPT,PROCESS_HISTORY,PROCESS_EVENT_STREAM}_ID, DEFAULT_AGENT_STREAM_EVENT_KIND, DEFAULT_THINKING_EFFORT, DEFAULT_REASONING_FORMAT, DEFAULT_SHELL_BG_OUTPUT_LINES, DEFAULT_SHELL_DRAIN_TIMEOUT_SECONDS). Keep DEFAULT_PLAN_REMINDER_ID and DEFAULT_PLAN_REMINDER_CADENCE; agent.py and SystemReminders use them. Also CONST_SQLITE_PER_CONNECTION_DATABASES and CONST_ERROR_CODE_HARNESS_EXECUTION in config/constants.py.
  • Delete the 7 task prompts that only harness/constants.py loads: src/devops_cli/ai/tasks/{advisor_system,summarizing_compaction,coder_agent,researcher_agent,macroscope_guidance,planning_guidance,playwright_guidance}.md. No test flags unreferenced prompts (the suite passed with them orphaned), so list them explicitly. Reduce harness/constants.py to UNSUPPORTED_BEHAVIORAL_SKILL_FIELDS only: the 7 load_task_prompt constants, 4 command and pattern sets, HarnessDeprecationWarning and the logger are all dead.
  • Spell out the exception cleanup: HarnessExecutionError becomes unraised once memory.py goes. Delete it, its CONST_ERROR_CODE_HARNESS_EXECUTION, the all entry, and the three uses in tests/test_architectural_invariants.py (import at 108, issubclass at 136, instance at 167), then regenerate docs/ERRORS.md. Verified in the copy: the suite and docs check pass after this.
  • Fix the acceptance list. tests/test_pydantic_agent.py, test_ai_agent_deferred_tools.py and test_codebase_hygiene_and_shims.py cannot 'pass unchanged': they import deleted names (test_codebase_hygiene_and_shims.py imports Shell and WarnOnCacheBusts at module level, and two of its tests go). Reword to 'pass with only clone-referencing tests removed or rewritten'. Add 'no src module under ai/agents/ or ai/pydantic_ai_bridge.py loses covered lines' and keep the coverage floor. The grep over docs for deleted module paths hits docs/SELF_IMPROVEMENT.md:1147 (and :1107, SqlitePlanStore) in a historical case-study section. Either add that file to files_owned and drop those bullets (AGENTS.md says a change must update docs it makes stale), or exclude section 6 from the grep.
  • Cite AGENTS.md by text, not by line number: the paragraph is now at line 40, because docs(agents): building internal code instead of using an open tool needs a written cost #1834 (b2d362f) landed on the release branch after the proposal was written. The same commit and feat(sandbox): declare runner controls without an engine call and report engine security facts #1831 edited config/constants.py and config/defaults.py, so rebase before touching them. Point the paragraph at src/devops_cli/sandbox/host.py::_terminate_process_group, which quotes the guards verbatim (pid <= 1, pid == os.getpid(), pgid <= 1 or pgid == os.getpgrp()) and works on a Popen pid. core/process.py::_terminate_process_group_async plus _is_invalid_pgid also survives, but it takes an asyncio process and lacks the getpid guard.
  • Record the new orphans the deletion creates as an explicit follow-up issue. They are not in scope for R01 and are not covered by the other first-wave items: common_tools.web_fetch_tool, duckduckgo_search_tool and is_private_ip_or_localhost (their only users are the clones and harness.agents; they also account for the web_fetch and duckduckgo rows in test_http_egress.py and dns_names.is_at_or_under); format_prompt.format_plan_reminder_as_xml and its test; and harness.skills.Skills, which no src code constructs (slots.py uses only ParsedSkill). R01 itself must still drop the 'harness docs' row from both tables in tests/test_http_egress.py (edit the file; do not delete it).
  • Add the cheap hygiene fix: run ruff check --fix on tests/test_subsystem_containment_and_redaction.py after the import prune (one I001 import-order error in the copy).

Acceptance criteria:

  • The ten harness modules and every capabilities.py symbol without a non-test importer are deleted together with their tests; none is skipped or xfailed. A grep of src, tests, AGENTS.md and docs (excluding docs/agent/tasks and docs/agent/archive) for the ten deleted module paths returns nothing.
  • A reachability script (AST import graph from commands/, main and server/) is pasted in the PR body and shows no importer of a deleted module.
  • These still pass unchanged: tests/test_harness_slots.py, test_skills_harness_suite in tests/test_harness.py, the surviving tests of tests/test_ai_agent_capabilities.py and tests/test_pydantic_ai_native_capabilities.py, tests/test_pydantic_agent.py, tests/test_ai_agent_deferred_tools.py, tests/test_architectural_invariants.py, tests/test_public_export_surface.py and tests/test_codebase_hygiene_and_shims.py.
  • AGENTS.md names a function that still exists as the process-group termination reference, CONST_DOMAIN_EXCEPTION_MODULES and the invariants module list name no deleted module, the ceilings fixture has no key for a deleted file, and docs/ERRORS.md is regenerated.
  • uv run devops ci passes in full (coverage at least 90.0 percent, devops docs check clean) and the devops ai harness commands still import and run.

Activity

  1. added
    source/agent
    type/refactor
    on Oct 22, 2026
  2. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    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.

    • Type: type/refactor. The candidate is a refactor that deletes unused code and simplifies the AI module structure.
    • Priority: P1-High. This change removes dead code and simplifies the architecture, which is critical for maintainability and performance.
    • Value: High. Removing unused code improves maintainability and reduces risk of bugs while simplifying the system.
    • Effort: Medium. The change involves deleting substantial code and updating related tests and documentation, but it's a well-defined cleanup task.
  3. added this to the v0.2.39 milestone on Oct 22, 2026
  4. added
    status/in-progress
    on Oct 22, 2026
  5. added a commit that references this issue on Oct 22, 2026
    8ff9bc8
  6. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1855, merged into release/v0.2.39 as 8ff9bc8.

    Cause: devops_cli.ai.harness carried a port of Pydantic AI Harness capabilities (shell, filesystem, memory, planning, compaction, sub-agents, docs, repo context, conversation search, a coder, a researcher, a Macroscope reviewer and a Playwright browser) that no command, server tool or other module used. Only commands/ai_harness.py imports the package, and only for harness/slots.py. The other ten modules (5,186 lines) loaded solely because harness/init.py imported them. ai/agents/capabilities.py held a second set of unused clones of capabilities that pydantic-ai already ships in pydantic_ai.capabilities (Thinking, WebSearch, WebFetch, MCP, NativeTool, PrefixTools and others). Both sets were carried through every gate run, refactor and review for no caller.

    Change: The ten modules are deleted: agents, compaction, conversation, docs, filesystem, memory, planning, repo_context, shell and workflow. harness/init.py now exports only what skills.py, slots.py and constants.py define. harness/constants.py keeps UNSUPPORTED_BEHAVIORAL_SKILL_FIELDS, the one constant skills.py reads. ai/agents/capabilities.py keeps BaseCapability, HandleDeferredToolCalls, SystemReminders, _accepts_positional_arguments and the five pydantic-ai re-exports, and goes from 1,116 lines to 232. BaseCapability.prefix_tools and with_metadata go with the clones they returned, so the upstream methods of those names apply. The seven task prompts that only harness/constants.py loaded are deleted. HarnessExecu…

    51 file(s) changed.

    How it was verified

    Check runs at 0bce756:

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

    Acceptance Criteria of docs/agent/tasks/task-1836-unwired-harness-port.md:

    • The ten harness modules and every ai/agents/capabilities.py symbol without a caller outside the deleted code are deleted together with their tests, and none is skipped or xfailed. A search of src, tests, AGENTS.md, README.md and docs (outside docs/agent/tasks, docs/agent/archive and CHANGELOG.md) for the deleted module paths and class names finds nothing.
    • The import graph from commands/, server/ and main reaches no deleted module, and the deleted modules are absent from the tree afterwards.
    • The harness slots, the remaining capability, agent, deferred-tool, export-surface, hygiene and architectural-invariant tests pass, with only tests that referenced deleted names removed or rewritten.
    • AGENTS.md names a function that exists as the process-group termination reference, CONST_DOMAIN_EXCEPTION_MODULES and the invariants list name no deleted module, the ceilings fixture has no key for a deleted file, and docs/ERRORS.md is regenerated and uv run devops docs check reports every file up to date.
    • ruff check, ruff format --check and mypy pass over src and tests, and no module under ai/agents/ or ai/pydantic_ai_bridge.py loses covered lines.
    • Pending a person: uv run devops ci passes on the delivering tree. This change ran the targeted tests and a full-suite coverage run, not the gate.
  7. added a commit that references this issue on Oct 23, 2026
    f209f6c
  8. 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

    source/agenttype/refactor

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions