Skip to content

fix(tests): isolate KeyringBackend._classes registration across xdist workers #1601

Closed

Description

@dan-petty

Friction

During devops ci runs under pytest-xdist and pytest-randomly, tests that inspect caplog.records while loading settings (such as tests/test_roadmap_refine.py::test_a_research_plan_that_never_fits_its_schema_refines_without_search_results and tests/test_review_embeddings_unserved.py) fail whenever tests/test_config_cmd.py::test_strict_keyring_access_raises_instead_of_reading_as_missing runs earlier on the same xdist worker.

Evidence

Deterministic reproduction without pytest-randomly:

$ uv run pytest -p no:randomly -o addopts="" \
    tests/test_config_cmd.py::test_strict_keyring_access_raises_instead_of_reading_as_missing \
    tests/test_roadmap_refine.py::test_a_research_plan_that_never_fits_its_schema_refines_without_search_results
FAILED tests/test_roadmap_refine.py::test_a_research_plan_that_never_fits_its_schema_refines_without_search_results
Captured log call:
WARNING  devops_cli.config.settings:settings.py:756 Cannot read a secret: the OS keyring is locked; run `devops devcontainer unlock-keyring`

Root cause:

  1. test_strict_keyring_access_raises_instead_of_reading_as_missing in tests/test_config_cmd.py (and FakeKeyring in tests/cluster_secret_fakes.py) subclasses keyring.backend.KeyringBackend with priority = 1 and error: Exception = KeyringLocked("locked").
  2. KeyringBackendMeta registers every KeyringBackend subclass in the process-global KeyringBackend._classes set when the class is defined.
  3. In subsequent tests on the same worker, keyring.get_keyring() returns ChainerBackend, whose .backends property queries KeyringBackend.get_viable_backends(), instantiating Raising() with priority = 1 and default KeyringLocked("locked"). Every _keyring_get() call then raises KeyringLocked and logs Cannot read a secret: the OS keyring is locked; run devops devcontainer unlock-keyring.

Proposed Remedy

  1. Avoid subclassing keyring.backend.KeyringBackend in test doubles (or remove test subclasses from KeyringBackend._classes on teardown) and isolate keyring.get_keyring in tests/conftest.py with an autouse fixture so no test reads or mutates process-global keyring backend state across tests.
  2. Add a regression test verifying that running test_strict_keyring_access_raises_instead_of_reading_as_missing before a settings load does not leave Raising in KeyringBackend._classes or emit locked-keyring warnings in subsequent tests.

Activity

  1. added
    source/agent
    type/test
    on Oct 16, 2026
  2. dan-petty commented on Oct 16, 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 focuses on fixing a test-related issue with keyring backend isolation.
    • Priority: P2-Medium. The issue affects test reliability and reproducibility under specific conditions but does not block core functionality.
    • Value: Medium. Fixing this improves test stability and reduces flaky test failures, which benefits the team's development workflow.
    • Effort: Low. The fix involves isolating keyring backend state in tests with a simple autouse fixture and adding one regression test.
  3. added a commit that references this issue on Oct 17, 2026
    4cd237f
  4. added this to the v0.2.36 milestone on Oct 17, 2026
  5. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1607, merged into release/v0.2.36 as 4cd237f.

    Closes #1601

    Full devops ci runs failed intermittently on tests that store or read a secret, each passing alone; on 2026-10-17 three of five gate runs across unrelated branches failed this way:

    • tests/test_k8s.py::test_k8s_bootstrap_openwebui: SecretStorageError("Failed to store secret in keyring: 'EncryptedKeyring' object has no attribute 'set_password'"), twice.
    • tests/test_review_embeddings_unserved.py::test_parallel_review_workers_ask_an_unserved_embedding_model_once: two extra devops_cli.config.settings WARNING records (the locked-keyring warning fix(tests): isolate KeyringBackend._classes registration across xdist workers #1601 reproduces with test_roadmap_refine).

    4 file(s) changed.

    How it was verified

    Check runs at dee6c29:

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

    No task file.

  6. added a commit that references this issue on Oct 17, 2026
    3dd7fa6
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