Skip to content

fix(deps): pyproject.toml declares every package src imports, and a deptry step in devops ci keeps it that way #1120

Closed

Description

@dan-petty

Problem

Lines cited at dcafadf.
At 132ecc5, the MESSAGES.ci labels cited at lang/en/messages.py:764-765 are at :773-774.

Nothing checks that [project].dependencies matches what src imports. Ruff does not look at dependencies. mypy resolves imports against the installed environment, where transitive packages are present too; uv check runs ty, which pyproject.toml:155 sets to unresolved-import = "ignore". uv lock --check only compares pyproject.toml with uv.lock. deptry 0.25.1, run with the project's installed packages, scans 504 files at dcafadf in 0.56–0.68 s and reports 31 findings. At the branch tip 132ecc5 it scans 505 files in 0.78–0.84 s and reports the same 31:

  • Imported directly, declared nowhere (DEP003, present only through another package):
    • logfire: telemetry/logfire.py:136,159,203,246,257,322 (configure, span, metric_counter, instrument_pydantic, instrument_pydantic_ai). It arrives through pydantic-ai-slim's logfire extra (logfire[httpx]>=4.39.0).
    • nacl (PyNaCl): github/secrets.py:9, which seals GitHub Actions secrets in encrypt_secret (:49-54). It arrives through PyGithub (pynacl>=1.4.0).
    • openai: ai/models/ollama.py:9, AsyncOpenAI in the Ollama provider signatures (:128, :167, :175, :200). It arrives through pydantic-ai-slim's openai extra (openai>=3.0.0).
    • pydantic_graph: ai/run/__init__.py:24,34. It arrives through pydantic-ai-slim (pydantic-graph==2.35.0).
    • secretstorage: commands/devcontainer.py:1390, the gnome-keyring lock check _keyring_is_locked (:1386-1396). It arrives through keyring, and only on Linux (SecretStorage>=3.2; sys_platform == "linux").
    • httpx, encode's original package (0.28.1, last release 2024-12-06). uv.lock gets it from fastmcp (through fastmcp-slim's client and server extras), mcp, google-genai and qdrant-client. pydantic-ai 2.35 imports it optionally (pydantic_ai/_http.py:32-35) and marks its remaining legacy support TODO(v3): remove (:80). Three places in src import it:
      • ai/settings/__init__.py:11 from httpx import Timeout is unguarded and runs at module import. ai/models/ollama.py:24 imports the module, and Timeout is re-exported from ai/__init__.py:354,934, ai/agents/__init__.py:523,989 and ai/agents/pydantic_agent.py:423,713. If those packages stop requiring httpx (for example by moving to httpx2), devops_cli.ai.settings fails to import, and the Ollama model path and the agents package fail with it.
      • http/broker.py:9-12 and telemetry/memory_profiler.py:247-250 both use try: import httpx2 as httpx / except ImportError: import httpx. httpx2 is declared, so the fallback branch never runs. It is dead code that names an undeclared package. Both files then call httpx2 through the httpx alias (broker.py :38-39, :53, :66, :72, :80, :87, :91, :95, :113, :139; memory_profiler.py :266), so a search for httpx2. misses those call sites.
  • Imported directly, missed by deptry: from opentelemetry import trace at ai/run/__init__.py:62 and telemetry/tracer.py:1390 comes from opentelemetry-api, which arrives through the declared OTLP exporter. deptry matches imports by top-level name, and the exporter also installs into the opentelemetry namespace, so deptry counts the import as covered.
  • Declared, never imported (DEP002):
    • pydantic-handlebars==0.2.1 is flagged, but deleting it would break template rendering. src uses pydantic-ai's TemplateStr (ai/template/__init__.py:12,22, and ai/agents/agent.py:614 renders Handlebars-templated system prompts; covered by tests/test_pydantic_ai_template.py). TemplateStr imports pydantic-handlebars lazily (pydantic_ai/template.py:61,125-135). pydantic-ai-slim and logfire list pydantic-handlebars only under extras this project does not enable (spec, variables). In uv.lock, devops-cli is the only package that requires it.
    • The 13 tree-sitter packages are false positives. ai/ast/engine.py:55-68 maps languages to grammar modules, which :422-423 loads by name with importlib.
  • Missing (DEP001): temporalio, dbos and prefect in ai/durable.py:272,283,294. refactor(ai): the durable resolver offers only the engines that work, and the unread ai.durable settings are removed #1121 settles these three engines, and this item leaves them alone.

Acceptance criteria

  • [project].dependencies declares the directly imported packages, exact-pinned at the versions uv.lock already resolves: logfire==5.1.0, pynacl==1.6.2, openai==3.13.0, pydantic-graph==2.35.0, opentelemetry-api==1.44.0 and secretstorage==3.5.0; sys_platform == 'linux'. No resolved version changes. A uv lock --dry-run of this change at dcafadf, deptry included, adds only deptry 0.25.1, requirements-parser 0.13.1 and tomli 2.4.1.
  • pydantic-ai[spec]==2.35.0 replaces pydantic-handlebars==0.2.1. pydantic-handlebars stays in uv.lock, and tests/test_pydantic_ai_template.py passes unchanged.
  • No module under src imports httpx or aliases httpx2 as httpx: rg -n -g '*.py' -e '^\s*(import|from) httpx\b' -e 'httpx2 as httpx' src prints nothing. Today it prints ai/settings/__init__.py:11, http/broker.py:10,12 and telemetry/memory_profiler.py:248,250. This item owns all three direct httpx imports in src: ai/settings/__init__.py:11, http/broker.py:12 and telemetry/memory_profiler.py:250. fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 no longer deletes the broker.py shim, or the memory_profiler.py one.
    • ai/settings/__init__.py no longer imports httpx. create_model_settings(timeout=…) takes float | None. resolve_runtime_model_settings (:123-133), which today passes untyped **kwargs straight into create_model_settings (:130), takes timeout: float | None as an explicit keyword and forwards it, and tests/test_pydantic_ai_settings.py keeps passing. Timeout is removed from that module's __all__ and from the re-exports listed above. There is no deprecation shim (pre-1.0).
    • This item deletes both fallback shims, http/broker.py:9-12 and telemetry/memory_profiler.py:247-250. Both files use import httpx2 with no alias, and their call sites are renamed to httpx2., so later searches for httpx2. find them.
    • In tests/test_http_broker.py, the local import httpx at :64 and :99 goes, and the mocks at :76 and :110 use spec=httpx2.Response, the type the broker returns. If fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 has already removed those per-request override tests, nothing is left to change there. tests/test_rag_query_telemetry.py:18 keeps httpx, because it builds qdrant-client's own transport.
    • The MCP example in the shipped knowledge-base page ai/knowledge_base/devops_cli/libraries/pydantic_ai.md:81-85 uses httpx2.AsyncClient and httpx2.Timeout, so retrieval stops suggesting the import this gate rejects. MCPToolset stores http_client but never passes it on (ai/agents/tools.py:133, :180, :246-256), so the edit changes no behaviour.
  • deptry is a gate step:
  • uv run deptry src lands as one deps row of refactor(ci): github ci runs the gate through devops ci from one check table #843's check table, which devops ci and GitHub CI both run, with refactor(ci): github ci runs the gate through devops ci from one check table #843's parity test mapping the row (if this item lands before refactor(ci): github ci runs the gate through devops ci from one check table #843, refactor(ci): github ci runs the gate through devops ci from one check table #843 carries the row). There is no separate task entry in commands/ci.py, no separate subcommand and no separate step in .github/workflows/ci.yml. A local pre-commit hook (language: system, pass_filenames: false, files: ^(pyproject\.toml|src/.*\.py)$) runs it at commit time.
  • The step's supporting edits are in place:
  • After this change, deptry src reports no issue. Tests with a fake runner pin the step's argv. On a real tree, adding import httpx to a module fails the step with DEP003, and removing the last import of a declared package fails it with DEP002. The task file records both results.
  • Gate cost is measured and recorded in the task file. deptry took 0.56–0.84 s wall (about 2 CPU-seconds) for 504–505 files at host load 18–21 on 16 CPUs. It runs alongside pytest, so the gate's wall time does not measurably grow. It reads only local package metadata and makes no network call.
  • changelog.d/<issue>.md records the removed Timeout re-export under ### Removed and the deptry step under ### Added.
  • Tests stay offline, and uv run devops ci passes.

Key questions

  • What timeout type does ModelSettings.timeout take: an httpx.Timeout, an httpx2.Timeout or a float? Proposed: a float. pydantic-ai 2.35 types it as int | float | Timeout, where Timeout is the legacy httpx.Timeout (pydantic_ai/settings.py:8-15,209). Its docstring (:210-226) says numeric seconds work everywhere and a legacy httpx.Timeout is converted for SDKs that need one (_http.py:68-77). It also says httpx2.Timeout is "deliberately not part of this contract, because some SDKs behind these settings still reject it", and that Google and Mistral take numbers only. openai 3.13 accepts float | httpx2.Timeout | None (openai/_types.py:36,123). So swapping in an httpx2.Timeout is not safe, and keeping httpx.Timeout depends on a package pydantic-ai plans to drop. The only production caller, ai/models/ollama.py:212-218, passes timeout: float | None (:174). The public resolve_runtime_model_settings (ai/settings/__init__.py:123-133, re-exported from ai/__init__.py:364,1123, ai/agents/__init__.py:533,1185 and ai/agents/pydantic_agent.py:433,903) forwards untyped **kwargs into create_model_settings and is called only from tests (tests/test_pydantic_ai_settings.py:120). It gets the same float | None keyword, so no untyped path bypasses the narrower type. A per-phase timeout belongs on the provider's own httpx2 client (http/client.py:27 already builds an httpx2.Timeout), not in ModelSettings.
  • Who deletes the two fallback shims, this item or fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898? Proposed: this item deletes both fallback shims, http/broker.py:9-12 and telemetry/memory_profiler.py:247-250, and fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 no longer deletes either; both deletions are out of its scope. The deptry step cannot pass while either file imports httpx. The lines are dead code and do not depend on fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898's egress rewrite. fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 is P1 in v0.2.29 and this item is in the backlog, so fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 is likely to land first. Until this item lands, fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 leaves those lines alone and keeps calling httpx2 through the httpx alias. This item then makes the same deletion, and renames the alias's call sites, in whatever broker.py and memory_profiler.py fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 leaves behind.
  • Why deptry and not a hand-written test or another tool? Proposed: deptry. It reports exactly the four cases needed: DEP001 missing, DEP002 unused, DEP003 transitive and DEP004 a dev dependency imported in shipped code. It is MIT-licensed and lives at osprey-oss/deptry, formerly fpgmaas/deptry. It has two maintainers: fpgmaas, the author, and mkniewallner, who cut 0.25.1. Maintainer commits run through 2026-08 and weekly Renovate lock maintenance through 2026-09. The latest release is 0.25.1 (2026-03-18). It ships abi3 wheels with a Rust core, declares Python 3.14 and has tested against 3.15 since 2026-08. The alternative, FawltyDeps (Tweag), last released in 2025-06 and last pushed in 2025-07. A hand-written import-versus-pyproject test would re-implement deptry's module-to-distribution mapping. deptry's known limit is that it matches by top-level name, so imports inside a shared namespace (opentelemetry) go unchecked. That is why opentelemetry-api is declared by hand.
  • How does deptry see the installed packages? Proposed: uv run deptry src from the dev group. deptry reads distribution metadata from the interpreter it runs in, and its documentation says to run it inside the project's virtual environment. A uvx run or a hook environment managed by pre-commit would not contain the project's packages. deptry's own published hook is language: system for the same reason. Using src as the root makes deptry treat devops_cli as first-party. Run from . without known_first_party, it reports 3,157 findings, nearly all of them false DEP003 findings for devops_cli itself.
  • Should deptry scan tests/? Proposed: no. deptry treats every scanned file as shipped code, so tests/ would raise 327 DEP004 findings for pytest and hypothesis. The contract is the package users install, and deptry excludes tests by default.
  • Does declaring packages that already arrive transitively make upgrades harder? Proposed: accept that cost. pydantic-graph moves in lockstep with pydantic-ai (pydantic-ai-slim requires pydantic-graph==2.35.0), and opentelemetry-api moves with the OTLP exporter series. uv lock fails loudly if the pins drift apart. uv tree --outdated --depth=1, already a gate step, then lists these packages too.
  • Should pydantic-handlebars be a direct pin or come through the extra? Proposed: the extra. pydantic-ai names spec as the install route for TemplateStr (pydantic_ai/template.py:133-135), and the pydantic-ai package exposes the same extra (pydantic-handlebars and PyYAML). With the extra, no DEP002 ignore is needed. The handlebars version follows pydantic-ai's requirement, and uv.lock pins it.
  • Should logfire come through an extra or be declared directly? Proposed: directly, as logfire==5.1.0. src calls its core API itself, and the httpx extra still arrives through pydantic-ai's logfire extra.
  • What platform marker does secretstorage need? Proposed: sys_platform == 'linux', the marker keyring itself uses. The import stays inside the gnome-keyring check, so behaviour on other platforms does not change.

Strategic alignment

Activity

  1. added
    type/bug
    scope/ai
    priority/p2-medium
    scope/ci
    on Oct 3, 2026
  2. added this to the v0.2.31 milestone on Oct 8, 2026
  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Placed in v0.2.31 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: finding identity v2, URL credential masking, tests that leave no state, the Docker endpoint check and the Argo CD/OTel perimeters. Position 8 of 10 in the release's planned merge order. Its board Status is set to Ready, so the release-start fill keeps it.

  4. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Re-checked at 05e9388 by the 2026-10-08 client-library audit. These direct imports are still undeclared in [project].dependencies:

    • secretstorage: commands/devcontainer.py:1396, moved from :1390. It arrives through keyring on Linux only.
    • openai: ai/models/ollama.py:9 (AsyncOpenAI). It arrives through pydantic-ai-slim's openai extra.
    • anthropic: to be added here once the AI-slice item that adopts the Claude SDK lands.

    PyNaCl is already listed in this item.

    The audit's telemetry item (refactor(telemetry): spans are built and exported by the OpenTelemetry SDK, ...) also makes opentelemetry-sdk and opentelemetry-exporter-otlp-proto-common direct imports. Both arrive today only through logfire and the grpc exporter.

  5. dan-petty-bot commented on Oct 9, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1480, merged into release/v0.2.31 as b22837d.

    Summary

    Resolves #1120.

    Declares direct dependencies in pyproject.toml for packages directly imported across src/ (logfire, pynacl, openai, pydantic-graph, opentelemetry-api, secretstorage), removes vestigial httpx imports and fallback shims across src/, integrates deptry as a local CI quality gate step (deps) and CLI subcommand (devops ci deps), and tests the step specification and CLI dispatch.

    19 file(s) changed.

    How it was verified

    Check runs at 2e93066:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1120-deptry-dependencies.md:

    • deptry src passes cleanly with zero findings on the codebase.
    • Direct dependencies (logfire, pynacl, openai, pydantic-graph, opentelemetry-api, secretstorage) are declared in pyproject.toml.
    • All residual httpx imports and fallback shims in src/ are removed; Timeout re-export is eliminated from devops_cli.ai.settings.
    • devops ci deps executes uv run deptry src and is wired as a gate check in devops ci.
    • AGENTS.md and documentation matrices are synchronized with the deps gate check.
    • Test suite covers deps check spec, CLI subcommand dispatch, and workflow parity.
    • Verified failure modes: adding import httpx triggers DEP003; removing a declared package triggers DEP002.
    • uv run devops ci passes 100% locally.
  6. added a commit that references this issue on Oct 9, 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/citype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions