Repository navigation
Description
Problem
tests/roadmap/test_roadmap_implement_command.py::test_a_done_step_prints_its_outcome_as_json_and_exits_0 failed in Tests & Coverage (shard 2 of 4) on the pull request #3526 (run 41919824262). It passed when the job ran again on the same commit, and it passes in a local run of the same shard.
json.loads(result.stdout) raised JSONDecodeError: Extra data. The stdout held console spans of logfire before the JSON: agent run, chat function:ModelScript:stream, running tool: write_file. A test that runs earlier in the same xdist worker most likely calls logfire.configure with the console on and instrument_pydantic_ai. The state stays set for the next test of the worker.
Expected
No test leaves the logfire configuration or the pydantic-ai instrumentation set. A test run prints no span on stdout, whatever the order of the tests in a worker.
Evidence
The change of #3526 does not touch logfire. The shard split is new (#3517), so the order of tests in a worker changes with each change of test times.
Proposed design
Problem statement
A test that runs earlier in an xdist worker calls logfire.configure with the console on and calls logfire.instrument_pydantic_ai. The state stays set for the next test of the worker. A later test that parses stdout as JSON fails with JSONDecodeError: Extra data, because the stdout holds console spans. The change makes every test leave no logfire configuration and no pydantic-ai instrumentation behind.
Acceptance criteria
Requirement: No console span in a later test's stdout
The test suite SHALL keep a logfire console span of one test out of the stdout of a later test in the same process.
Scenario: The JSON test runs after a configuring test
- WHEN a test calls
logfire.configurewith the console on and callslogfire.instrument_pydantic_ai, andtest_a_done_step_prints_its_outcome_as_json_and_exits_0runs after it in one process - THEN
json.loads(result.stdout)parses the outcome, and no span text is inresult.stdout.
Requirement: Reset after a failed test
The autouse fixture SHALL reset the logfire configuration and the pydantic-ai instrumentation when a test fails.
Scenario: A configuring test raises
- WHEN a test that configured logfire and instrumented pydantic-ai raises an exception
- THEN the fixture turns the console off and the pydantic-ai instrumentation off before the next test starts.
Requirement: The telemetry tests keep their assertions
The telemetry tests SHALL keep every assertion on the console output and the pydantic-ai spans.
Scenario: The logfire tests run under the autouse fixture
- WHEN
tests/telemetry/test_telemetry_logfire.pyandtests/telemetry/test_telemetry_llm_content.pyrun - THEN every test in both files passes with the same assertions.
Requirement: The suite passes in any order
The test suite SHALL pass with the telemetry tests and the implement command tests in any order in one worker.
Scenario: Both files run in one worker in both orders
- WHEN
tests/telemetry/test_telemetry_logfire.pyandtests/roadmap/test_roadmap_implement_command.pyrun in one xdist worker, in either order - THEN both files pass and no captured stdout holds a console span.
Existing Tool Considered
No alternatives check has run for this item. pytest, already a dependency, gives the autouse fixture that runs after each test, a failed one included. logfire gives logfire.configure(console=False) and pydantic-ai gives Agent.instrument_all(False). Neither restores the logfire global configuration by itself, so the project keeps one fixture of about 20 lines. Written cost to build, keep and fix that fixture: about 20k tokens and about 2 hours.
Key questions
- Which tests set the logfire configuration and the pydantic-ai instrumentation?:
tests/telemetry/test_telemetry_logfire.pyconfigures logfire and instruments pydantic-ai for real.tests/telemetry/test_telemetry_llm_content.pypatcheslogfire.configureandlogfire.instrument_pydantic_ai, and the test(cli): migrate 49 tests to public interfaces #2167 design keeps those patches. The product path issrc/devops_cli/telemetry/logfire.py, whichsrc/devops_cli/docs/generator.pycalls. [sources: tests/telemetry/test_telemetry_logfire.py, tests/telemetry/test_telemetry_llm_content.py, src/devops_cli/telemetry/logfire.py, src/devops_cli/docs/generator.py, openspec/changes/2167-the-49-test-files-that-no/tasks.md:67] - Where does the reset of the logfire configuration and the pydantic-ai instrumentation live?: In one autouse fixture in the root
tests/conftest.pythat runs after every test. (best practice) [sources: docs/TESTING.md, openspec/changes/2167-the-49-test-files-that-no/design.md:11]- Chosen: One autouse fixture for every test. It resets after each test, a failed test included, and no test author must remember it.
- Rejected: A
finallyblock in each test that configures logfire. It is easy to forget, and it does not cover a test that reaches the code path indirectly. - Rejected: Split the telemetry tests and the command tests across workers. The order of tests changes with test times (perf(ci): run the test row in four shards on four runners #3517), so the leak returns.
- How does the fixture turn the console and the pydantic-ai instrumentation off?: The fixture calls
logfire.configure(console=False)andAgent.instrument_all(False)in its teardown. (best practice) [sources: docs/TELEMETRY.md:149, tests/telemetry/test_telemetry_logfire.py]- Chosen: Turn the console off and uninstrument pydantic-ai in the teardown. It uses the two switches that the product path already sets, and it leaves a quiet configuration.
- Rejected: Restore a snapshot of the previous global configuration. logfire keeps no public API that returns the previous configuration.
- Rejected: Remove the logfire module from
sys.modulesand import it again. Other modules hold the configured instance, so a new import changes nothing they use.
- Does the fix change the product code or only the test suite?: Only the test suite. (best practice) [sources: src/devops_cli/telemetry/logfire.py, tests/telemetry/test_telemetry_logfire.py]
- Chosen: Reset the state in the test suite. The issue asks for test isolation, and the product keeps the console output for a person at a terminal.
- Rejected: Make the console output conditional on a TTY in
src/devops_cli/telemetry/logfire.py. A test that asserts the console output runs with a captured stdout, which is not a TTY, so the check hides the output that the test asserts.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-11-07: partly.
Tool: pytest-dev/pytest-forked (https://github.com/pytest-dev/pytest-forked), MIT, last activity 2026-08-08, maintained.
Activity
dan-petty commentedon Nov 4, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(tests)scope of the title gives the scope.Flaky CI failures block developer confidence but do not break functionality or affect end users directly.The failed run 41919824262 does not set P0: the author has no write access, and no caller attached it as evidence. A person can set P0 with the label priority/p0-critical.Flaky test runs waste developer time and erode trust in the CI signal, but they do not change product behaviour.The fix is a targeted teardown of logfire.configure and instrument_pydantic_ai in a shared fixture or conftest.Both items fix logfire state leaking into test execution, but #965 stops the SDK credential-check network call while this stops console spans from polluting stdout.devops-cli-service commentedon Nov 6, 2026
Status set to Ready at be8d18a (see proposed design in issue body).
devops-cli-service commentedon Nov 7, 2026
Alternatives check: partly
Reason: The web searches returned no results (connection timeouts), so I read the package and repository facts: pytest-forked runs every test in a forked child process, so a logfire configuration and pydantic-ai instrumentation that one test sets cannot reach the next test of a worker, and a failing test cannot leak either. It only sidesteps the leaked state instead of resetting logfire and pydantic-ai as the issue asks, needs fork (no Windows) and a coverage setup that reads subprocesses, so it covers the flaky stdout in part while the ~20-line autouse fixture stays the targeted fix.
Tool: pytest-dev/pytest-forked (https://github.com/pytest-dev/pytest-forked)
Covers:
Lacks:
Tools considered:
Searches run:
Sources:
Checked on 2026-11-07. A person decides what this means for the item. The check changes no label and closes no issue.
test: keep the logfire reset free of real git calls (#3532)
devops-cli-service commentedon Nov 14, 2026
Released in v0.138.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.138.0
devops-cli-service commentedon Nov 14, 2026
Live since 2026-11-14 15:02 UTC