Repository navigation
Labels
effort/highEffort High: much work, in one pull requestpriority/p2-mediumPriority P2: standard workscope/aiAI review pipeline, personas, prompts, LLM client, or RAGscope/infraDocker container images, DevContainers, and infrastructure toolingtype/refactorType refactor: a new structure, same behaviorvalue/highValue High: the delivery of the item matters much
Description
Problem
- Valkey is reached seven ways.
ValkeyClient[code: src/devops_cli/valkey/client.py:64] opens its socket in_create_socket(:131-133); the process-wide pool lives in valkey/pool.py (get_pool:202,reset_pool:211). Six modules outsidevalkey/constructValkeyClientinline: commands/valkey.py:47, ui/data_providers.py:642, security/vulnerability_lookup.py:392, ai/run_store.py:250, ai/cache/valkey_cache.py:48 and ai/rag/embeddings.py:423; cache/tiered.py:196 takes the pool.EmbeddingsEngine's defaultvalkey_clientsentinel [code: ai/rag/embeddings.py:73] opens and pings a socket on construction and sets the timeout of the privateclient._sock(:433-434). - Qdrant is built in four places.
resolve_qdrant_client[code: ai/rag/indexer.py:397] builds theQdrantClientwrapper [code: ai/rag/qdrant.py:142]; commands/rag.py:81, ai/rag/investigator.py:215 and ai/tools/builtin_tools.py:378 build it inline. The session guardguard_live_rag_datareassigns the wrapper's and the SDK's__init__for the whole run [code: tests/conftest.py:480]. - The embedder is built in nine places.
EmbeddingsEngine[code: ai/rag/embeddings.py:322] is constructed inline at commands/rag.py:87, commands/ai_ingest.py:244, roadmap/intake_model.py:160, ai/rag/investigator.py:227, ai/rag/indexer.py:458, ai/tools/builtin_tools.py:387, ai/agents/embeddings.py:249, ai/benchmark/embedding_runner.py:284 and ai/rag/embeddings.py:1057. Its one Protocol,Embedder, lives in roadmap [code: roadmap/intake_model.py:103]. - Tests copy their own doubles. Six Qdrant doubles:
FakeQdrantClientandRecordingQdrant(tests/test_rag_indexer_retriever.py:17, :236),DummyQdrant(test_rag_retriever_filters.py:24, test_rag_multi_project_indexer.py:45),StubQdrant(test_rag_query_telemetry.py:75) andRecordingQdrant(test_qdrant_timeout_setting.py:107). Valkey doubles includeFakeValkey(test_run_store.py:49, test_run_comparison.py:39) and_MockValkey(test_rag_embeddings.py:554). Embedder doubles includeFixedVectorEngine(test_rag_indexer_retriever.py:91, test_rag_retriever_filters.py:11),DummyEmbedder(test_rag_multi_project_indexer.py:71),StubEmbedder(test_rag_query_telemetry.py:61) and_Embedder(test_roadmap_intake.py:1190).ValkeyClient._create_socketis patched in 2 test files [measured: grep at 5c45b1e].
Acceptance criteria
Seams
- Valkey: one place supplies a connected client for the configured endpoint, pooled or not. A Protocol in
valkey/names the calls devops-cli makes: the typed commands (PING, GET, SET with expiry, DEL, MGET, KEYS, SCAN, INFO, DBSIZE, EVAL, FLUSHDB, FLUSHALL, BGSAVE), rawexecuteand pipelines (ai/run_store.py sends ZADD and ZRANGE this way), with AUTH and SELECT on connect. - Qdrant:
resolve_qdrant_clientis the seam's factory for the wrapper, and the wrapper uses a nativeqdrant_client.QdrantClientit is given instead of building one in_build_client(ai/rag/qdrant.py:197). A Protocol inai/rag/names the wrapper calls the RAG code makes. - Embedder: the
EmbedderProtocol moves from roadmap/intake_model.py:103 next toEmbeddingsEngine, under a name that does not clash with the pydantic-aiEmbedderof ai/agents/embeddings.py:175, which ai/rag/embeddings.py already imports (:30). One factory builds the real engine from settings. - Each fixture below removes its fake at teardown. Resetting the pool and the module caches (
_MODEL_DIMENSION_CACHE, ai/rag/embeddings.py:88;_DIM_MISMATCH_WARNED_COLLECTIONS, ai/rag/qdrant.py:60) after every test is left to the floor (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, Q28). - The inline constructions listed above are left to the package items that own them.
Fakes and fixtures
-
tests/support/fakes/valkey.py: an in-memory keyspace of strings and sorted sets answering the Protocol's calls, with expiry, recording each command. It can refuse the connection or the password as a server would. It is promoted fromFakeValkey(tests/test_run_store.py:49). -
tests/support/fakes/qdrant.py: in-memory collections with upsert, cosine search, payload filters and deletes, recording each call. It can answer as an unreachable server. It is promoted fromFakeQdrantClient(tests/test_rag_indexer_retriever.py:17). -
tests/support/fakes/embeddings.py: the same text always gets the same vector of the configured dimension; it records each text and whether it was a query, and can fail as a provider error does. - Three fixtures install the fakes through the seams and return them, registered once from the root conftest.
Contract suites
- Valkey: the real
ValkeyClientspeaks RESP to a loopback server the test owns, which replays recorded exchanges (valkey-server is not installed in the devcontainer [measured: which]). Cases: each command, a wrong password and a refused connection, raising the sameexceptions/valkeyclasses on both sides. - Qdrant: the real wrapper runs over qdrant-client's own local mode (the
:memory:location), which needs no server [measured: qdrant-client 1.19.1]. Cases: create, upsert, search order and scores, filters, delete, a dimension mismatch, and an unreachable server (a native client pointed at a loopback port nothing listens on), raisingQdrantClientError[code: ai/rag/qdrant.py:36] on both sides. - Embedder: the real engine, without Valkey, runs against recorded Ollama
/api/embedand OpenAI-compatible/v1/embeddingsresponses served from a loopback server the test owns. Cases: one vector per text in input order, the dimension, empty input and a provider error. - (person-run) The Valkey exchanges and provider responses are captured once from local servers and committed under
tests/fixtures/with the commands that captured them.
Migration
- tests/test_valkey_concurrency.py, the
TestValkeyClienttests in tests/test_valkey.py (:124) and tests/test_rag_qdrant.py (paths before test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313's move) use the fakes or the contract suites and patch no devops_cli name,_create_socketincluded. - If 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 introduced its interim
unreachable(...)marker, every marker that names Valkey, Qdrant or an embedding provider, in a test whose code reaches the edge through these seams, gives way to the fixtures, in the fake's refusing state where the test relies on the refusal. Markers on code that constructs its client inline go with the package item that routes that construction. - The other copies listed above are deleted by the package items that own their tests. The provider-HTTP tests of
EmbeddingsEnginein tests/test_rag_embeddings.py move with refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001, which puts embeddings behind its model adapters. - Tests run offline; each new test runs under 1 s.
- If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its ceilings drop by the sites this PR removes.
-
uv run devops cipasses.
Key questions
- Three edges in one item? Decided 2026-10-07: Valkey, Qdrant and embeddings form one seam item of phase D. (proposed) If the PR proves too big, refinement applies
needs-splitalong the three seams. - Qdrant's real side? (proposed) qdrant-client's local mode: a real implementation of the same client API, in process, so no Qdrant server and no recording are needed.
- How does this relate to refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001? (proposed) This item gives RAG, intake and agents an embedder seam and fake; refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 changes what the real engine calls underneath (an
embedverb on its adapters). The contract suite's real side holds across that change, because it replays provider responses at the HTTP level. - Fixture names? (proposed)
valkey,qdrantandembedder.
Strategic alignment
- Depends on: test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312. Blocks: test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326, test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327, test(review): ai/review and review/ are tested through one public interface over the model, tool-executor and process fakes, with no mock detection in src #1328, test(ai): Wire rag once in ai/rag, test with edge fakes #1329, test(mcp): mcp, agent and tool tests run on edge fakes #1330, test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331, test(security): scanner, secret and crypto tests run on the executor, process, http and keyring fakes, and scanners stop looking for mocks #1332, test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334, test(infra): infrastructure tests run on edge fakes #1335. Related: refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 (model seam and embeddings), refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 (the engine's HTTP clients), refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315 (k8s:// Qdrant addressing), 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 (default deny, interim markers and state resets).
- Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase D).
Proposed design
Problem statement
Valkey, Qdrant and the embedder are each constructed inline in multiple modules, and tests copy their own fake doubles. This makes the seams hard to test, the fakes hard to maintain, and the real-client behaviour unverified. The Valkey seam and fake already exist; the Qdrant and embedder seams, fakes and contract suites are missing.
Acceptance criteria
- Criterion 1: A Protocol in valkey/ names the typed commands, raw execute and pipelines that devops-cli makes.
Verification: rg -n 'class.*Protocol' src/devops_cli/valkey/ shows a Protocol with ping, get, set, delete, mget, keys, scan, info, dbsize, eval, flushdb, flushall, bgsave, execute and pipeline methods. - Criterion 2: resolve_qdrant_client is the factory for the Qdrant wrapper, and the wrapper accepts a native qdrant_client.QdrantClient instead of building one.
Verification: rg -n 'def resolve_qdrant_client' src/devops_cli/ai/rag/indexer.py exists; rg -n '_build_client' src/devops_cli/ai/rag/qdrant.py prints nothing. - Criterion 3: A Protocol in ai/rag/ names the wrapper calls the RAG code makes.
Verification: rg -n 'class.*Protocol' src/devops_cli/ai/rag/qdrant.py shows a Protocol with ensure_collection, upsert_points, search_points, scroll_points, count_points, delete_points_by_files, delete_points_by_project and is_alive. - Criterion 4: The Embedder Protocol lives next to EmbeddingsEngine under a name that does not clash with pydantic-ai Embedder.
Verification: rg -n 'class.*Embedder.*Protocol' src/devops_cli/ai/rag/embeddings.py exists; rg -n 'from devops_cli.roadmap.intake_model import.*Embedder' src/ prints nothing. - Criterion 5: One factory builds the real EmbeddingsEngine from settings.
Verification: rg -n 'def.*build.*embedder|def.*create.*embedder' src/devops_cli/ai/rag/embeddings.py shows a factory function that takes AIConfig and returns an EmbeddingsEngine. - Criterion 6: tests/support/fakes/qdrant.py provides an in-memory fake with upsert, cosine search, payload filters and deletes, recording each call, and can answer as an unreachable server.
Verification: uv run pytest tests/test_rag_qdrant.py -x --tb=short passes; the file contains a class with upsert_points, search_points, delete_points_by_files and a refusing mode. - Criterion 7: tests/support/fakes/embeddings.py provides a deterministic fake that returns the same vector for the same text, records each text and whether it was a query, and can fail as a provider error.
Verification: uv run pytest tests/test_rag_indexer_retriever.py -x --tb=short passes; the file contains a class with embed_texts that returns fixed vectors and a failing mode. - Criterion 8: Three fixtures named valkey, qdrant and embedder install the fakes through the seams and return them, registered from the root conftest.
Verification: rg -n 'def valkey\b|def qdrant\b|def embedder\b' tests/conftest.py shows three fixture definitions. - Criterion 9: The Valkey contract suite tests each command, a wrong password and a refused connection against a loopback server, raising the same exceptions on both sides.
Verification: uv run pytest tests/test_valkey.py -x --tb=short passes; the tests use serving_valkey or the valkey_client fixture and assert ValkeyAuthenticationError, ValkeyConnectionError and ValkeyCommandError. - Criterion 10: The Qdrant contract suite runs the real wrapper over qdrant-client local mode for create, upsert, search order, filters, delete, dimension mismatch and an unreachable server.
Verification: uv run pytest tests/test_rag_qdrant.py -x --tb=short passes; the tests use QdrantClient with a :memory: location and assert QdrantClientError for the unreachable case. - Criterion 11: The embedder contract suite runs the real engine against recorded Ollama and OpenAI-compatible responses from a loopback server.
Verification: uv run pytest tests/test_rag_embeddings.py -x --tb=short passes; the tests serve /api/embed and /v1/embeddings from a loopback listener and assert one vector per text, the dimension, empty input and a provider error. - Criterion 12: Existing tests in test_valkey_concurrency.py, TestValkeyClient in test_valkey.py and test_rag_qdrant.py use the shared fakes or contract suites and patch no devops_cli name or _create_socket.
Verification: rg -n '_create_socket|patch.*devops_cli' tests/test_valkey_concurrency.py tests/test_valkey.py tests/test_rag_qdrant.py prints nothing. - Criterion 13: Tests run offline and each new test runs under 1 second.
Verification: uv run pytest tests/test_valkey.py tests/test_rag_qdrant.py tests/test_rag_embeddings.py tests/test_rag_indexer_retriever.py --durations=10 -x --tb=short passes with no test over 1 s. - Criterion 14: uv run devops ci passes.
Verification: uv run devops ci exits 0.
Key questions
- Three edges in one item?: Decided 2026-10-07: Valkey, Qdrant and embeddings form one seam item of phase D. If the PR proves too big, refinement applies needs-split along the three seams. (proposed)
- Qdrant's real side for the contract suite?: Use qdrant-client's local mode (:memory: location), which is a real implementation of the same client API in process, needing no Qdrant server and no recording. (proposed)
- How does this relate to refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001?: This item gives RAG, intake and agents an embedder seam and fake. refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 changes what the real engine calls underneath (an embed verb on its adapters). The contract suite's real side holds across that change because it replays provider responses at the HTTP level. (proposed)
- Fixture names?: valkey, qdrant and embedder. (proposed)
- Does fix(valkey): one validated URL names every Valkey endpoint, valkey-py dials an address that one check vetted, and the unused cache layer goes #1113 block this item's Valkey work?: No. fix(valkey): one validated URL names every Valkey endpoint, valkey-py dials an address that one check vetted, and the unused cache layer goes #1113 replaces the hand-written Valkey client and cache with GLIDE behind one store. This item's Valkey seam and fake already exist and target the current client. Whichever lands second adapts its work to the other's result. [sources: tests/support/fakes/valkey.py]
Open questions
- Qdrant's real side? (proposed) qdrant-client's local mode: a real implementation of the same client API, in process, so no Qdrant server and no recording are needed.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-10-29: not-applicable.
Tool: none found.
Metadata
Metadata
Assignees
Labels
effort/highEffort High: much work, in one pull requestpriority/p2-mediumPriority P2: standard workscope/aiAI review pipeline, personas, prompts, LLM client, or RAGscope/infraDocker container images, DevContainers, and infrastructure toolingtype/refactorType refactor: a new structure, same behaviorvalue/highValue High: the delivery of the item matters much
Type
Projects
- StatusShow more project fieldsNew
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 8, 2026
Folded here instead of a new issue: the agent filing quota (#1153) is spent for this cycle, and this refactor shares this item's change surface. It is recorded here in full so it is not lost.
refactor(ai): embedding and qdrant calls retry through tenacity and classify failures by exception type and status, not message text
Problem
Checked at release/v0.2.29 (05e9388). Embeddings and the Qdrant wrapper each hand-roll retries and decide what failed by searching the error message. The project already retries model traffic with pydantic-ai's
HTTPX2TenacityTransportandwait_retry_after(ai/retries/__init__.py:14-22,:108-137), reached throughnew_http_client(retries=...)(http/client.py:163-166), and tenacity is a direct dependency.ai/rag/embeddings.py):_calculate_backoff_delay(:76-84) and_compute_retry_delay(:267-274), withtime.sleeploops (:811-813);Retry-Afteris honoured only when it is all digits (:270-272), so an HTTP-date value is ignored;_is_transient_embedding_error(:239-264) matches substrings such as"timeout"and"errno 104";httpx2.Clients (:380,:629,:659,:796) bypass the factory and its retry transport, and the endpoint is joined by string (:654-657).ai/rag/qdrant.py):_execute_with_retry(:246-253) loops with a lineartime.sleep(0.5 * attempt)and no jitter (:122);_is_transient_qdrant_error(:40-57) matches substrings such as"timeout"and"connection reset";"not found" in err or "404" in err(:308,:373,:466), so any message containing "404" (a 500 body, a collection name) reads as not found;"dimension error"(:468);ResponseHandlingExceptionfor transport failures andUnexpectedResponse, which carriesstatus_code, for HTTP errors.Proposed remedy
retries=(orget_shared_client(..., retries=...)), so retry, backoff andRetry-After(seconds and HTTP-date) come from the shared tenacity transport. Delete_calculate_backoff_delay,_compute_retry_delayand_is_transient_embedding_error. What counts as transient follows httpx2's exception types andCONST_RETRYABLE_HTTP_STATUS_CODES. AIMD batch sizing and node failover stay.tenacity.Retryingwith:stop_after_attemptand a jittered exponential wait;retryonResponseHandlingException, or onUnexpectedResponsewith a 5xx status;before_sleephook that emitsQDRANT_RETRIES_TOTALas today.UnexpectedResponse.status_code == 404. A dimension mismatch is found before the query, by comparing the query's length with the collection's configured vector size from the collection info. What then happens is fix(ai): a rag collection records its embedding model, a mismatch fails instead of wiping the collection, and ranking keeps the cosine score #1066's decision.Acceptance criteria
rg -n '_calculate_backoff_delay|_compute_retry_delay|_is_transient_embedding_error|_is_transient_qdrant_error|err_str' src/devops_cli/ai/ragprints nothing.Retry-Afteras an HTTP date is retried after that time, measured through tenacity's sleep hook or refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320's clock, never wall time. The test fails on the current code.QDRANT_RETRIES_TOTAL, a 400 is not retried, and a 500 whose body contains "404" is not read as not found. The last test fails on the current code.MockTransportpassed as itstransport=argument, or over refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317's fake. Embedding tests use an httpx2MockTransport.MockTransport, throughtests/llm_stream_fakes.route_clientor refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's fixture) or the process edge. No test patches a devops_cli name.changelog.d/<n>.mdrecords the change;CHANGELOG.mdis not edited.uv run devops cipasses.Related: #1066, #1317, #1381, #1001, #1065, #1019, #1320
Found by the 2026-10-08 client-library audit.
5 remaining items
dan-petty commentedon Oct 26, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
This is an architectural improvement that enhances testability and maintainability but does not address a critical issue or bug.Improving the architecture of core components like Valkey, Qdrant, and embedder will benefit all downstream code and testing efforts.Refactoring multiple components with their associated tests and fakes requires significant development effort.Both items involve introducing a single seam for a component with multiple inline constructions. However, the candidate focuses on Valkey, Qdrant and embedder specifically, while item 1314 targets HTTP clients and DNS resolution.dan-petty commentedon Oct 28, 2026
Refine cannot set this item to Ready at 69636b6 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.
devops-cli-service commentedon Oct 30, 2026
Alternatives check: not-applicable
Tool: none found
Checked on 2026-10-29. A person decides what this means for the item. The check changes no label and closes no issue.
refactor(ai): seams and fakes for Valkey, Qdrant and embedder (#1317)
refactor(ai): seams and fakes for Valkey, Qdrant and embedder (#1317)
chore(main): release 0.23.0 (#2802)