Skip to content

fix(ci): review workflow tests start the logfire SDK's credential check, which the network guard blocks #965

Closed

Description

@dan-petty

Problem

Four tests in tests/test_review.py start the Logfire SDK's credential check:

  • test_review_path_workflow
  • test_review_branch_workflow
  • test_review_pr_workflow
  • test_review_path_watch_mode

The check runs in a background thread, which tries to reach https://logfire-us.pydantic.dev/v1/info. The conftest DNS guard blocks it, so nothing leaves the machine. Every full run still prints the warning, and two builders and one reviewer each flagged it as a possible network call on 2026-10-02:

logfire/_internal/config.py:1884: UserWarning: Logfire API is unreachable ... Failed to resolve 'logfire-us.pydantic.dev' ([Errno -2] External DNS lookup blocked during test execution ...)

Reproduce (about 60 s): uv run pytest -p no:cacheprovider -q -n 0 tests/test_review.py -W "error::UserWarning:logfire".

What is known

  • devops-cli does not call logfire.configure in these tests. With logfire.configure and logfire._internal.config.configure both wrapped to print their stack, neither was called during test_review_path_workflow, yet the warning appeared. _init_logfire_if_enabled (commands/review.py:155) returns early, because the test config sets no telemetry.logfire.
  • No LOGFIRE_TOKEN is set in the environment, and no .logfire/ credentials directory exists in the home directory or the checkout.
  • So the SDK configures itself lazily on some other path, most likely pydantic-ai's instrumentation or a logfire span reached from the review workflow, and finds a token somewhere the test does not isolate.

Acceptance criteria

  • The cause is found and named in the PR: which call configures Logfire, and where it reads the token.
  • A test run never configures the Logfire SDK unless a test asks for it. The conftest isolates whatever the cause reads, or the code stops configuring Logfire implicitly.
  • The reproduction above passes with the warning raised as an error.
  • uv run devops ci passes.

A fifth affected test, and the cause (2026-10-07)

Measured at 36cfbbb; the cited lines were re-read at 5c45b1e (release/v0.2.28), where none of these files has changed.

  • Fifth test. tests/test_review_stage_flags.py::test_review_cli_stage_flags_propagation (:90) prints the same warning. uv run pytest -q -n0 -W default tests/test_review_stage_flags.py shows it for that test only [measured].

  • The cause, found by wrapping logfire.configure. All five tests reach it through devops-cli:

    • each patches devops_cli.commands.review.load_settings with a bare MagicMock (tests/test_review.py:47, :73, :98, :431; tests/test_review_stage_flags.py:93), so settings.telemetry.logfire is truthy;
    • _init_logfire_if_enabled (commands/review.py:171-185, called at :316, :543 and :867) therefore calls LogfireBridge.configure;
    • the bridge resolves a non-empty token from the mock and calls logfire.configure(send_to_logfire=True, ...) (telemetry/logfire.py:206);
    • the SDK then starts its check_logfire_token thread.

    This corrects "What is known" above, which saw no logfire.configure call at an earlier commit.

  • The reproduction above passes instead of failing. pytest anchors the -W module field, so error::UserWarning:logfire matches only a module named exactly logfire. The warning comes from logfire._internal.config, in a background thread. This command fails exactly the five tests (5 failed, 28 passed) [measured]:
    uv run pytest -p no:cacheprovider -q -n 0 tests/test_review.py tests/test_review_stage_flags.py -W "error:Logfire API is unreachable:UserWarning" -W "error::pytest.PytestUnhandledThreadExceptionWarning"

  • test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 may resolve it. Its hermetic floor turns telemetry export off by default and adds the config fixture that replaces load_settings patches. That default cannot reach a test whose settings object is a MagicMock. Once these five tests read the floor's config instead, telemetry.logfire is off and the cause is gone, with no product change. test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326 moves them off load_settings patches when it migrates the commands/review tests, unless this item does so first.

Strategic alignment (added).

Activity

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

    @dan-petty
    OwnerAuthor

    Placed in v0.2.32 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: URLs and host keys read by the library that dials, ollama hardening, and pull-request test-quality tooling. Position 5 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 9, 2026

    @dan-petty
    OwnerAuthor

    New failure mode (2026-10-09): it now fails an unrelated test

    On PR #1460 (CI run 37875213508, job 113642121902), tests/test_roadmap_dry_runs.py::test_a_dry_run_through_the_entry_point_starts_no_process_and_opens_no_connection[migrate] failed with ["getaddrinfo: ('logfire-us.pydantic.dev', 443)"] != []. That test replaces socket.getaddrinfo with a recorder, so the Logfire credential-check thread started by an earlier test resolved its host inside this test's window and was recorded as the dry run's own connection. The PR's change (#900, devops branches create) touches neither telemetry nor roadmap; the same test passed on the eight PRs merged into release/v0.2.30 the same hour, and a rerun is expected to pass.

    So the background thread is no longer just noise: it makes any test that records socket calls flaky. The fix this item plans (stop the SDK's credential check from starting in tests, or join it before the test ends) removes both.

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

    @dan-petty-bot
    Collaborator

    What changed

    #1505, merged into release/v0.2.32 as 1f1a5f8.

    Summary

    Cause

    • Five tests patched devops_cli.commands.review.load_settings with a bare MagicMock:
      • tests/test_review.py: test_review_path_workflow, test_review_branch_workflow, test_review_pr_workflow and test_review_path_watch_mode
      • tests/test_review_stage_flags.py: test_review_cli_stage_flags_propagation
    • With that mock, settings.telemetry.logfire is truthy. _init_logfire_if_enabled (src/devops_cli/commands/review.py) then calls LogfireBridge.configure (src/devops_cli/telemetry/logfire.py).
    • configure gets a non-empty token from the mock through get_logfire_token → _resolve(opt.TELEMETRY_LOGFIRE_TOKEN, settings) (config/settings.py). It then calls logfire.configure(send_to_logfire=True, token=...).
    • That call starts the SDK's check_logfire_token thread, and the conftest DNS guard blocks the thread's lookup. This produced the "Logfire API is unreachable" warning on every run.
    • The same leaked thread caused the socket-recorder flake on fix(cli): devops branches create creates the branch instead of failing on checkout -b -- #1460: test_roadmap_dry_runs recorded getaddrinfo: ('logfire-us.pydantic.dev', 443) as the dry run's own connection.
    • The issue body's -W "error::UserWarning:logfire" command passes without proving anything. pytest matches the module field exactly, and the warning comes from logfire._internal.config, in a background thread.

    Fix (tests only; nothing under src/ or tests/conftest.py changes)

    • The five tests no longer patch load_settings. They read the per-test config t…

    6 file(s) changed.

    How it was verified

    Check runs at 9c749a8:

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

    Acceptance Criteria of docs/agent/tasks/task-965-review-tests-start-no-logfire-token-check.md:

    • The cause is named: the MagicMock settings made _init_logfire_if_enabled call LogfireBridge.configure, which read the token from the mock through get_logfire_token and called logfire.configure, starting the check_logfire_token thread.
    • A test run never configures the Logfire SDK unless a test asks for it: the filterwarnings entries in pyproject.toml fail any test that starts the token check, and tests/test_review.py and tests/test_review_stage_flags.py pass with them.
    • The corrected reproduction passes: uv run pytest -p no:cacheprovider -q -n 0 tests/test_review.py tests/test_review_stage_flags.py -W "error:Logfire API is unreachable:UserWarning" -W "error::pytest.PytestUnhandledThreadExceptionWarning".
    • uv run devops ci passes: the pre-push gate and the PR's checks run it.
  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/citype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions