Repository navigation
Description
Problem
Checked on 2026-11-22 (main 6e497c2), in the build of #6717 (PR #6719).
- With direct Ollama nodes,
_embed_batch_with_subdivision(src/devops_cli/ai/rag/embeddings.py:1088-1102) halves a batch after anyEmbeddingsErrorand tries each half again, down to one text. - A permanent error, such as HTTP 404 for a model that the node does not serve, gives the same reply for each half. So one batch of n texts sends about 2n-1 requests to each node before the run fails, and a batch of 128 texts sends about 255 requests for one answer.
- Halving helps only when one text of the batch causes the error (for example an input that is too long).
Proposed remedy
- Halve a batch only on an error that one text can cause: HTTP 400, 413 or 422 (the classes that PR fix(ai): rag index skips data fixtures and survives a failed batch #6719 adds to
EmbeddingsErrorasstatus). On any other error (401, 403, 404, 5xx, a timeout or a connect error), stop the halving and raise the error at once, so the retry and the breaker of the indexer decide. - Write the tests first: an Ollama fake that answers 404 to each request gets one request for the batch; a fake that refuses one long text with 400 still gets the halving and gives the vectors of the other texts.
Acceptance criteria
- The new tests pass with
uv run devops ci teston the embeddings tests. - For a batch of 128 texts and a node that answers 404, the fake records 1 request, not about 255.
Dependencies
- fix(ai): rag index skips data fixtures and survives a failed batch #6717 (its PR adds the HTTP status to
EmbeddingsError).
Alternatives check of 2026-11-22: none.
Tool: none found.
Reason: Searches found only general HTTP status references (400, 413, 422, 404) and no library that gates embedding batch halving on error class; the fix changes the project's own _embed_batch_with_subdivision, so no tool covers it.
Lacks:
- Halving only on 400, 413 or 422 statuses
- No halving on 401, 403, 404, 5xx, timeout, connect
- Fake-based tests for one request on 404 and halving on 400
Proposed design
Problem statement
Halve an embedding batch only on an error that one text can cause or that a smaller batch can fix. With direct Ollama nodes, _embed_batch_with_subdivision halves a batch after any EmbeddingsError. A permanent error such as HTTP 404 gives the same reply for each half, so a batch of 128 texts sends about 255 requests to each node before the run fails. The change halves a batch on HTTP 400, 413 and 422, on a timeout, and on a malformed reply. It raises 401, 403, 404, 5xx and a connect error at once.
Acceptance criteria
Requirement: halve_on_input_refused_status
The embedding engine SHALL halve a batch and retry each half when EmbeddingsError.status is 400, 413 or 422.
Scenario: one_long_text_is_refused
- WHEN a fake Ollama node refuses one text of a batch with HTTP 400 and answers each other text
- THEN the engine halves the batch and returns the vectors of the other texts
Requirement: no_halve_on_not_found
The embedding engine MUST raise an EmbeddingsError with status 404 at once and MUST NOT halve the batch.
Scenario: model_not_found
- WHEN a fake Ollama node answers HTTP 404 to each embeddings request for a batch of 128 texts
- THEN the fake records 1 request, and the engine raises the
EmbeddingsError
Requirement: no_halve_on_auth_error
The embedding engine MUST raise an EmbeddingsError with status 401 or 403 at once and MUST NOT halve the batch.
Scenario: node_refuses_the_key
- WHEN a fake Ollama node answers HTTP 401 to the first embeddings request for a batch
- THEN the fake records 1 request, and the engine raises the
EmbeddingsError
Requirement: no_halve_on_server_error
The embedding engine MUST raise an EmbeddingsError with a 5xx status at once and MUST NOT halve the batch.
Scenario: node_answers_503
- WHEN a fake Ollama node answers HTTP 503 to the first embeddings request for a batch
- THEN the fake records 1 request, and the engine raises the
EmbeddingsError
Requirement: no_halve_on_connect_error
The embedding engine MUST raise an EmbeddingsError on a connect error at once and MUST NOT halve the batch.
Scenario: node_refuses_the_connection
- WHEN a fake Ollama node raises a connect error on the first embeddings request for a batch
- THEN the engine makes 1 attempt, and it raises the
EmbeddingsError
Requirement: keep_halving_on_timeout
The embedding engine SHALL halve a batch and retry each half when a request to a direct Ollama node times out.
Scenario: timeout_on_a_parallel_batch
- WHEN a fake Ollama node times out on a 4-text batch and answers each half
- THEN the engine sends the batch as
[4, 4, 2, 2, 2, 2]and returns the vectors
Requirement: keep_halving_on_malformed_reply
The embedding engine SHALL halve a batch and retry each half when a 200 reply gives fewer vectors than texts.
Scenario: fewer_vectors_than_texts
- WHEN a fake Ollama node answers 200 OK with one vector for a 2-text batch
- THEN the engine halves the batch and returns the vectors of each text
Requirement: no_halve_on_unknown_error
The embedding engine MUST raise an EmbeddingsError with no status at once and MUST NOT halve the batch when the error is not a malformed reply.
Scenario: unknown_error
- WHEN a fake Ollama node raises an
EmbeddingsErrorwith no status and a message that is not a vector count mismatch - THEN the engine makes 1 attempt, and it raises the
EmbeddingsError
Requirement: no_halve_across_nodes
The embedding engine MUST try each direct Ollama node once for a batch and MUST NOT halve the batch when a node answers 404 and the next node raises a connect error.
Scenario: two_nodes_fail
- WHEN a fake node answers HTTP 404 and a second fake node raises a connect error for a 2-text batch
- THEN the fake records 2 requests, and the engine raises the
EmbeddingsError
Requirement: embedding_tests_pass
The embeddings test suite SHALL pass with the new tests.
Scenario: run_the_embeddings_tests
- WHEN the embeddings test suite runs with
uv run devops ci test - THEN the command exits 0 and reports the new tests as passed
Existing Tool Considered
The alternatives check of 2026-11-22 in the issue body gives the verdict none and names no tool. The change therefore edits the project's own _embed_batch_with_subdivision (src/devops_cli/ai/rag/embeddings.py:1130) to gate halving on EmbeddingsError.status and the existing timeout and malformed-reply conditions. Written cost: an estimated 15 000 tokens to build, keep and fix the status gate and its tests, and about 2 hours of elapsed time.
Key questions
- Which errors allow the engine to halve a batch?: Halve on HTTP 400, 413 and 422, on a timeout, and on a 200 reply with fewer vectors than texts. Raise 401, 403, 404, 5xx and a connect error at once. (best practice) [sources: src/devops_cli/ai/rag/embeddings.py:1130, tests/ai/rag/test_embedding_batching.py:239-263, tests/ai/rag/test_embedding_provider_failures.py:316-324, openspec/specs/embedding-batch-size/spec.md:22-24]
- Chosen: Keep timeout and malformed-reply halving; stop on permanent HTTP errors and connect errors. The existing spec and tests require timeout and malformed-reply halving. Permanent errors and connect errors apply to the whole request, so halving repeats the error.
- Rejected: Stop halving on timeout. It breaks
test_parallel_batches_that_time_out_on_an_ollama_node_halve_the_batch_size_onceand removes adaptive batching for a large batch. - Rejected: Stop halving on a malformed reply. It breaks
test_an_ollama_node_that_gives_fewer_vectors_than_texts_gets_the_batch_cut. - Rejected: Halve on any 4xx. 401, 403 and 404 apply to the whole request, so halving repeats the same error.
- Rejected: Halve on any
EmbeddingsError. A permanent error such as 404 gives the same reply for each half, so one batch of n texts sends about 2n-1 requests.
- What does the engine do on an error that does not allow halving?: It raises the
EmbeddingsErrorat once. The retry and the breaker of the indexer then decide. (best practice) [sources: src/devops_cli/ai/rag/indexer.py, src/devops_cli/ai/rag/embeddings.py:1130]- Chosen: Raise at once and let the retry and the breaker of the indexer decide. The indexer already holds the retry and the breaker, so the engine adds no second policy.
- Rejected: Retry the same batch in the engine. It duplicates the retry of the indexer.
- Rejected: Halve on 5xx. A 5xx applies to the whole request, so each half gets the same error and the request count grows.
- Which existing tests must change?:
test_ollama_raises_after_every_node_failsintests/ai/rag/test_embedding_provider_failures.pymust assert 2 requests, not 4. The timeout and malformed-reply tests stay as they are. (best practice) [sources: tests/ai/rag/test_embedding_provider_failures.py:76-105, tests/ai/rag/test_embedding_batching.py:239-263, tests/ai/rag/test_embedding_provider_failures.py:316-324]- Chosen: Update the multi-node test to assert 2 requests. The engine no longer halves on 404, so it sends one request to each node.
- Rejected: Keep the test at 4 requests and halve on 404. This keeps the request explosion that the issue fixes.
- Rejected: Update the timeout and malformed-reply tests. The change keeps their behavior.
- Where do the new tests go?: Add the 404 and 400 tests to
tests/ai/rag/test_embedding_batching.py, with the fake intests/support/fakes/embeddings.py. (best practice) [sources: tests/ai/rag/test_embedding_batching.py, tests/support/fakes/embeddings.py]- Chosen: Add to
tests/ai/rag/test_embedding_batching.py. This file already holds the tests ofEmbeddingsErrorbatching. - Rejected: Add a new test file. The existing file already covers the batching of
EmbeddingsError, so a new file splits the same subject.
- Chosen: Add to
- Where does the engine read the HTTP status of an
EmbeddingsError?: FromEmbeddingsError.status, which fix(ai): rag index skips data fixtures and survives a failed batch #6717 adds to the class atsrc/devops_cli/ai/rag/embeddings.py:173. [sources: src/devops_cli/ai/rag/embeddings.py:173]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 22, 2026
Both modify _embed_batch_with_subdivision in embeddings.py, but #117 adapts size on latency while the candidate gates halving on error type.devops-cli-service commentedon Nov 22, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (5)
Searches run:
Sources:
devops-cli-service commentedon Nov 22, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
dan-petty commentedon Nov 25, 2026
Cannot build as written on
origin/main(b42683d4b):#6722requires_embed_batch_with_subdivision(src/devops_cli/ai/rag/embeddings.py:1130-1143) to halve a batch only whenEmbeddingsError.statusis400,413, or422and raise every other error (401,403,404,5xx, timeout, connect error, or status-less error) at once, which conflicts with existing requirements and tests:openspec/specs/embedding-batch-size/spec.md:22-24andtests/ai/rag/test_embedding_batching.py:239-263):test_parallel_batches_that_time_out_on_an_ollama_node_halve_the_batch_size_onceexplicitly specifies that a timed-out 4-text batch on a direct Ollama node is halved and retried ([4, 4, 2, 2, 2, 2]), whereas#6722(no_halve_on_connect_error) prohibits halving on a timeout.tests/ai/rag/test_embedding_provider_failures.py:316-324):test_an_ollama_node_that_gives_fewer_vectors_than_texts_gets_the_batch_cutexpects_embed_batch_with_subdivisionto halve a 2-text batch when200 OKreturns only 1 vector (EmbeddingsErrorwithstatus=None).tests/ai/rag/test_embedding_provider_failures.py:76-105):test_ollama_raises_after_every_node_failssends HTTP404on one node andConnectErroron the second and assertslen(posts) == 4(halving the 2-text batch once).Returning to
Newper AGENTS.md Rule 2 so refinement can align the allowed halving classes (for instance, keeping400/413/422, malformed counts, and/or timeouts while stopping non-splittable401/403/404/5xxandConnectError, or updatingopenspec/specs/embedding-batch-size/spec.mdand the affected tests).devops-cli-service commentedon Nov 25, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
chore(main): release 0.219.0 (#7177)
devops-cli-service commentedon Nov 25, 2026
Released in v0.219.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.219.0
devops-cli-service commentedon Nov 25, 2026
Live since 2026-11-25 17:09 UTC