Skip to content

perf(valkey): the embeddings engine, the threat-intel client and the library store share one fail-soft Valkey client with a short connect timeout #1992

Closed

Description

@dan-petty

Friction

  • Each fail-soft cache builds its own Valkey client. While Valkey is down, a silent host costs the full valkey.timeout for each new client.
  • The embeddings engine builds two clients: a probe with a timeout of at most 0.1 s, and a second client with the configured timeout.
  • A review and each tool call build a new CloudflareRadarClient, and each one builds its own ValkeyClient.

Evidence

Checked at main a752a14.

Existing tool considered

Proposed remedy

  • Build one process-wide fail-soft Valkey client with a short connect timeout, shared by the embeddings engine, CloudflareRadarClient and the library store.
  • Put the connect timeout in DEFAULT_VALKEY_CACHE_CONNECT_TIMEOUT_SECONDS in defaults.py, set from a measured loopback connect. Remove the literal 0.1.
  • Give devops ai ingest a public way to get the client.
  • Reset the shared client after each test in tests/conftest.py.

Acceptance criteria

  • The embeddings engine, CloudflareRadarClient and the library store share one client. A test shows that two engines and one radar client in one process hold the same object.
  • While Valkey is down, a second cache makes no second connect attempt. A test counts the attempts and finds one.
  • The connect timeout is DEFAULT_VALKEY_CACHE_CONNECT_TIMEOUT_SECONDS in defaults.py, and the literal 0.1 in embeddings.py is gone.
  • tests/conftest.py resets the shared client after each test, and the reset rule in docs/TESTING.md covers it.
  • The swallowed-failure ceilings of ai/rag/embeddings.py and security/vulnerability_lookup.py fall by the number of swallowed failures that the change removes.
  • The change builds no breaker, no half-open state and no cooldown.
  • Tests run offline. uv run devops ci passes.

Source: #1113

Proposed design

Problem statement

Each fail-soft Valkey cache in devops-cli builds its own client. While Valkey is down, each new client costs the full configured timeout on a silent host. The embeddings engine builds two clients, and each CloudflareRadarClient builds its own. This change consolidates them into one process-wide client with a short connect timeout, shared by the embeddings engine, CloudflareRadarClient and the library store.

Acceptance criteria

  • Criterion 1: The embeddings engine, CloudflareRadarClient and the library store share one client object.
    Verification: A test builds two engines and one radar client in one process and asserts they hold the same object.
  • Criterion 2: While Valkey is down, a second cache makes no second connect attempt.
    Verification: A test counts the connect attempts and finds exactly one.
  • Criterion 3: The connect timeout is DEFAULT_VALKEY_CACHE_CONNECT_TIMEOUT_SECONDS in defaults.py, and the literal 0.1 in embeddings.py is gone.
    Verification: grep for the constant name in defaults.py and confirm the literal 0.1 is absent from embeddings.py.
  • Criterion 4: tests/conftest.py resets the shared client after each test, and the reset rule in docs/TESTING.md covers it.
    Verification: Run the test suite and confirm no cross-test leakage of the shared client. Read docs/TESTING.md for the reset rule.
  • Criterion 5: The swallowed-failure ceilings of ai/rag/embeddings.py and security/vulnerability_lookup.py fall by the number of swallowed failures the change removes.
    Verification: Run uv run pytest tests/test_swallowed_failures_ratchet.py and confirm the ceilings are lower.
  • Criterion 6: The change builds no breaker, no half-open state and no cooldown.
    Verification: grep for breaker, half-open and cooldown in the changed files and confirm none are present.
  • Criterion 7: Tests run offline and uv run devops ci passes.
    Verification: Run uv run devops ci in a clean environment and confirm all checks pass.

Key questions

  • Where does the embeddings engine build its Valkey clients?: In _init_valkey, it builds a probe client with timeout=min(float(cfg.timeout), 0.1) and then a second client with the configured timeout. [sources: src/devops_cli/ai/rag/embeddings.py:456-478]
  • Where does CloudflareRadarClient build its Valkey client?: In init, it builds its own ValkeyClient with a valkey_client parameter defaulting to _DEFAULT_VALKEY. [sources: src/devops_cli/security/vulnerability_lookup.py:449-463]
  • How does devops ai ingest get its Valkey client?: It imports the private _resolve_client from the devops valkey command module and calls it directly. [sources: src/devops_cli/commands/ai_ingest.py:210-212]
  • Does this change build a circuit breaker?: No. The breaker with open, cooldown and half-open states is the scope of feat(cli): recovery transitions for adaptive knobs coalesced decrease, valkey breaker, failback #596. This change builds no breaker. (proposed) [sources: src/devops_cli/ai/rag/embeddings.py:456-478, src/devops_cli/security/vulnerability_lookup.py:449-463]
  • What is the measured loopback connect time that sets the new timeout?: A refused loopback port fails at once, probed at 7 ms. The constant DEFAULT_VALKEY_CACHE_CONNECT_TIMEOUT_SECONDS is set from this measurement. [sources: tests/conftest.py]
  • What is the default of valkey.timeout?: The default is 2.0 s. [sources: src/devops_cli/ai/rag/embeddings.py:456-478]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/refactor
    on Oct 23, 2026
  2. dan-petty commented on Oct 23, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/refactor. The change improves code structure and resource usage without adding new features.
    • Priority: P2-Medium. The change reduces resource usage and improves performance but does not fix a defect or security issue.
    • Value: Medium. The change helps multiple components share one client and reduces connection costs.
    • Effort: Medium. The change requires refactoring multiple clients and adding shared logic.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

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

  4. added
    priority/p2-medium
    status/ready
    value/medium
    effort/medium
    on Oct 28, 2026
  5. removed
    status/ready
    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

    effort/mediumpriority/p2-mediumsource/agenttype/refactorvalue/medium

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions