Skip to content

fix(test): the five-persona transient-503 review test ends reviewed whatever runs before it #1609

Closed

Description

@dan-petty

Friction

tests/test_gateway_review_stall.py::TestSingleRetryLayerAndStatusRules::test_five_personas_with_one_transient_503_sees_exactly_six_calls failed once in a full uv run devops ci run and passed alone and in the next full run; its cause is not known.

Evidence

  • 2026-10-16, full run with pytest-xdist and pytest-randomly: assert (6, 'failed') == (6, 'reviewed'). All six expected calls reached the fake transport (five personas and one retry of a transient 503), yet the file's review stage ended failed, which ReviewPipelineOrchestrator sets only when reviewing the file raises (src/devops_cli/ai/review/pipeline.py, the except blocks that set stage = "failed" and record error).
  • Not reproduced: 12 concurrent runs of the test alone, and the 10 modules tests/test_gateway*.py, tests/test_ai_client*.py and tests/test_review_pipeline*.py under pytest-randomly seeds 11, 22, 33, 44, 55 and 66 (164 passed each).
  • The test now asserts the recorded error with the stage, so the next failure names the exception.

Remedy

When it next fails, read the named exception and remove the order, load or shared-state dependency at its source. Until then, run the module in the full suite's conditions (devops ci test --repeat 3, several seeds) to find the predecessor test that leaves the state behind.

Proposed design

Problem statement

The test test_five_personas_with_one_transient_503_sees_exactly_six_calls in tests/test_gateway_review_stall.py occasionally fails with a 'failed' stage instead of the expected 'reviewed' stage, even though all expected calls (six) are made to the fake transport. This failure is intermittent and occurs only under specific conditions in full test runs, suggesting a race condition or shared state dependency from previous tests.

Acceptance criteria

  • Criterion 1: The test passes consistently without intermittent failures when run in isolation
    Verification: Run the test alone with pytest and confirm it passes 100% of the time
  • Criterion 2: The test continues to pass in a full test suite with multiple seeds
    Verification: Execute uv run devops ci with several different pytest-randomly seeds and verify the test does not fail
  • Criterion 3: The error message when the test fails shows the specific exception that caused the failure
    Verification: Modify the test to assert on the recorded error and observe that it names the actual exception in the failure case

Key questions

  • What specific condition causes the test to fail?: The test fails when a previous test leaves behind state that interferes with the test's execution, specifically causing the ReviewPipelineOrchestrator to set the stage to 'failed' instead of 'reviewed'. [sources: src/devops_cli/ai/review/pipeline.py]
  • What exception causes the failure?: The specific exception is not yet known, but it's captured in the error field of the review stage and will be named when the test fails again. [sources: tests/test_gateway_review_stall.py]
  • What are the conditions under which this test fails?: The test fails intermittently in full runs with pytest-xdist and pytest-randomly, but not when run in isolation or in subsequent full runs. [sources: tests/test_gateway_review_stall.py]
  • What should be done to fix the intermittent test failure?: When the test next fails, read the named exception and remove the order, load or shared-state dependency at its source. Until then, run the module in the full suite's conditions to find the predecessor test that leaves the state behind. (proposed) [sources: tests/test_gateway_review_stall.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/test
    on Oct 17, 2026
  2. dan-petty commented on Oct 17, 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/test. The candidate describes a test fix for a transient failure.
    • Priority: P2-Medium. The issue is a test flake that impacts CI reliability but does not affect core functionality.
    • Value: Low. The change affects only a single flaky test and does not provide user-facing benefits.
    • Effort: Medium. Requires identifying the root cause of the flake and potentially modifying shared state or dependencies.
  3. dan-petty commented on Oct 19, 2026

    @dan-petty
    OwnerAuthor

    Evidence (2026-10-19): the second failure names a wrapper, not the exception

    The test failed again in a pre-push uv run devops ci run (pytest-xdist, worker gw15, 14.5 s for the test):

    assert (6, 'failed', ...'API key.', []) == (6, 'reviewed', None, [])
    [1/1] Skipped errored file: test.py (Review: Cannot connect to AI provider API. Check network access, api_base_url, and API key.)
    
    • All six calls reached the fake transport, and no gateway request left through a real transport (bypassing is empty). So the connection message does not describe a connection.
    • The message comes from LLMClient._retry_chat_dispatch (src/devops_cli/ai/client/unified.py:667-670). Its last except Exception turns any exception raised while a reply is dispatched or parsed into _connection_error(exc), keeping the original only as __cause__. A KeyError, a validation error or a lock timeout therefore reads as "Cannot connect to AI provider API". The error this test records names the wrapper, not what failed.

    Remedy, amended

    1. Map only transport failures (httpx2.TransportError and its subclasses) to the connection error. Let any other exception propagate under its own type, or wrap it in an AIClientError that names the type. Add a test that a non-transport exception raised in dispatch does not report "Cannot connect".
    2. Then the next failure of this test names its real exception, and the order or shared-state dependency can be removed at its source, as the original remedy says.

    Step 1 is also a product defect: a user whose reply fails to parse is told to check their network and API key.

  4. added this to the v0.2.37 milestone on Oct 19, 2026
  5. dan-petty commented on Oct 19, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 0ae4ea4 (see proposed design in issue body).

  6. added
    status/in-progress
    on Oct 19, 2026
  7. added a commit that references this issue on Oct 19, 2026
    1eec7a1
  8. dan-petty commented on Oct 19, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1696, merged into release/v0.2.37 as 1eec7a1.

    Isolate response cache and settings state in review stall tests and ensure dispatch exception types are reported accurately rather than catching all exceptions as connection failures.

    Closes #1609

    6 file(s) changed.

    How it was verified

    Check runs at 8072521:

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

    Acceptance Criteria of docs/agent/tasks/task-1609-five-persona-transient-503-flake.md:

    • LLMClient._retry_chat_dispatch maps only httpx2.TransportError and subclasses to _connection_error.
    • Non-transport exceptions during dispatch propagate or wrap in AIClientError naming the exception type.
    • Unit tests verify non-transport dispatch exceptions do not report "Cannot connect".
    • Disk cache eviction in LLMResponseCache safely tolerates concurrently unlinked files.
    • test_five_personas_with_one_transient_503_sees_exactly_six_calls isolates settings and response cache state and passes reliably.
    • Changelog fragment changelog.d/1609.md added.
  9. added a commit that references this issue on Oct 20, 2026
    954914e
  10. 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/test

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions