Repository navigation
Description
Ready: implementation plan (refined 2026-10-17 at 3dd7fa6)
This section supersedes any text below that conflicts with it.
Decisions
- Can an explicit
--concurrencyexceed the cap?: no, not in gateway mode. A value above the slot sum (DEFAULT_GATEWAY_REVIEW_CONCURRENCY,src/devops_cli/config/defaults.py:430) is clamped to it, and one warning names both numbers, for example "--concurrency 8 is above the gateway's 3 backend slots; using 3". The cap protects the backend, and group analysis already clamps the same way (src/devops_cli/review/analysis.py:773-776). - Reviews only, or every gateway call?: every chat request that
LLMClientsends to the gateway in the process. One process-wide limiter lives insrc/devops_cli/ai/client/network.py. It is taken in the two methods every gateway chat call passes through:_openai_compat_messages(src/devops_cli/ai/client/openai.py:177) and_openai_compat_stream(openai.py:206), whenprovider == "gateway". This covers persona calls, group analysis (analysis.py:700), roadmap intake (src/devops_cli/roadmap/intake_model.py:163-168) and everydevops aichat command, so the code supports it cleanly. - What takes no slot: model listing (
openai.py:234), the gateway's health and model-info probes (src/devops_cli/ai/gateway.py:239-281) and embeddings. Embeddings use their own client andai.gateway_concurrency["embedding"]cap (src/devops_cli/ai/rag/embeddings.py:955-968), and the embedding group is served by a backend outside the slot table (k8s/llm/gateway/configmap.yaml:50-53). The pydantic-ai direct path (LLMClient.direct_request*,src/devops_cli/ai/client/unified.py:938) is used by no command, and refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 removes that second stack. So it is left alone. - Limiter shape: a module-level
threading.BoundedSemaphore(DEFAULT_GATEWAY_REVIEW_CONCURRENCY)and anacquire_gateway_slot()context manager besideacquire_ollama_slot(network.py:243). The wait is bounded by a newDEFAULT_GATEWAY_SLOT_TIMEOUT_SECONDS: float = 900.0indefaults.py, the same bound as the Ollama lease (defaults.py:74). A wait past it raisesAIClientErrornaming the cap. - Slot scope and retries: one slot per logical call, held across the transport's own retries. Retries run inside the pooled client (
src/devops_cli/ai/client/base.py:78-92,src/devops_cli/ai/retries/__init__.py:108), so there is no per-attempt hook without a second transport layer. Holding the slot during a backoff only lowers throughput while the backend is already refusing, and it never lets the count exceed the cap. A stream holds its slot until the generator closes. - Worker pools in gateway mode: the file pool is
min(total_files, slot sum), whateverai.ollama_urlsandai.ollama_max_parallelhold. A file's personas still run in parallel (pipeline.py:1211,src/devops_cli/ai/agents/pipeline.py:357). The limiter, not the pools, keeps requests in flight at or under the slot sum. - Complexity:
execute_multi_persona_review(pipeline.py:3658) already carries# noqa: C901, so it gains no branch. The sizing moves into a pure helper,_review_worker_count(config, total_files, requested) -> tuple[int, int | None], which returns the worker count and the clamped request (or None). The caller prints the warning. - Non-gateway providers: unchanged. Ollama keeps its per-URL leases (
network.py:243-281) and itsmax(DEFAULT_REVIEW_CONCURRENCY, urls * max_parallel)sizing, and an explicit--concurrencyis still honoured there. - Pre-analysis sizing (
pipeline.py:2593-2603): unchanged. It calls no model (ai_client=Noneatpipeline.py:1180). - Constant names:
DEFAULT_GATEWAY_REVIEW_SLOTSandDEFAULT_GATEWAY_REVIEW_CONCURRENCYkeep their names. They describe the backends that the review and chat groups route to. A chat call to a group served elsewhere, such asdevops-background, still takes a slot. That errs on the side of fewer requests and never more. A rename would rewrite three done task files for no change in behaviour. - Wording of the criteria: "verifier" in the body below reads "group analysis". refactor(review): the model verifier, the hallucination catalog and the model-claim guards are deleted, and person-recorded verdicts become suppressions #1150 deleted the verifier stage, and group analysis (feat(review): each finding group gets a model-written explanation and plan grounded in the rule's documentation at the installed tool version, kept apart from findings, with every quote, citation, version and code block checked #1147) is the second stage.
Delivery
-
PR 1 (S): gateway reviews and every gateway chat call stay within the backend slot sum. This PR closes fix(ai): gateway reviews keep requests in flight at the backend slot count, however many ai.ollama_urls are configured #1354. Tests first:
tests/test_review_pipeline.py: with a gateway config, threeai.ollama_urls,ollama_max_parallel=2and six files,ReviewWorkerPool.creategetsconcurrency=3(today 6). Withconcurrency=8in gateway mode it gets 3, and one warning names 8 and 3. Withprovider=ollamaandconcurrency=8over ten files it still gets 8.tests/test_gateway_review_stall.py: a gatewayLLMClienton a fake transport counts requests in flight, under a lock and with a short hold in each request. Six files with five personas each and threeai.ollama_urlsgive(peak <= 3, calls) == (True, 30). Today the peak reaches 15.tests/test_ai_client_network.py: eight threads throughacquire_gateway_slot()never exceed the cap. With the timeout patched to a few milliseconds and every slot held, a waiter raisesAIClientErrornaming the cap. Aprovider=openaiclient sends while every gateway slot is held.
Files:
src/devops_cli/ai/client/network.py,src/devops_cli/ai/client/openai.py,src/devops_cli/ai/review/pipeline.py,src/devops_cli/config/defaults.py,src/devops_cli/lang/en/messages.py(ReviewMessages,:19),src/devops_cli/lang/en/help.py(ReviewCommandHelp.concurrency,:1369), the regenerated CLI docs, the three test files,changelog.d/1354.md(under### Fixed) anddocs/agent/tasks/task-1354-gateway-review-slot-limit.md(Done).
Acceptance criteria
- In gateway mode, the persona stage's file pool is
min(total_files, DEFAULT_GATEWAY_REVIEW_CONCURRENCY), whateverai.ollama_urlsholds. Group analysis keeps its existing clamp (analysis.py:773-776). - An explicit
--concurrencyabove the slot sum is clamped to it in gateway mode, with one warning naming both numbers. The warning text lives inReviewMessages. - One process-wide limiter in
network.pycovers every chat requestLLMClientsends withprovider == "gateway", streamed or not. Requests in flight never exceed the slot sum. - Tests: with three URLs the pool size is 3 (today 6), and peak requests in flight stay at or below 3 (today 15). Each new test's call phase is under 1 s, and none touches the network.
- The
--concurrencyhelp fordevops reviewsays it is capped at the gateway's backend slots, anduv run devops docs checkpasses afteruv run devops docs generate --sync-readme. -
changelog.d/1354.mdrecords the change.CHANGELOG.mdanddocs/ROADMAP.mdare not edited. - The PR body cites the fail-to-pass check run for the new tests.
-
uv run devops cipasses.
Current references
- Worker sizing, gateway and Ollama:
src/devops_cli/ai/review/pipeline.py:3711-3735(batch_capacityat:3727, explicit concurrency at:3728-3729) - File worker pool:
src/devops_cli/ai/review/pipeline.py:3782 execute_multi_persona_review, with# noqa: C901:src/devops_cli/ai/review/pipeline.py:3658- Personas run with
parallel=True:src/devops_cli/ai/review/pipeline.py:1211 - Persona thread pool, up to 8:
src/devops_cli/ai/agents/pipeline.py:357 - Group analysis clamp:
src/devops_cli/review/analysis.py:773-776 - Slot table and sum:
src/devops_cli/config/defaults.py:425-430 - Ollama slot lease (the pattern to mirror):
src/devops_cli/ai/client/network.py:243-281 - Gateway chat calls:
src/devops_cli/ai/client/openai.py:177-204and:206-232 - Provider dispatch:
src/devops_cli/ai/client/unified.py:404-424 - Existing pool-size tests:
tests/test_review_pipeline.py:1143-1177 - Existing gateway review tests:
tests/test_gateway_review_stall.py:303
Dependencies and order
- fix(ai): review calls through the gateway no longer stall for about 190 s on ollama, with the cause measured first #1069, feat(release): v0.2.28 #1283, refactor(review): the model verifier, the hallucination catalog and the model-claim guards are deleted, and person-recorded verdicts become suppressions #1150 and feat(review): each finding group gets a model-written explanation and plan grounded in the rule's documentation at the installed tool version, kept apart from findings, with every quote, citation, version and code block checked #1147: closed. Nothing blocks this item.
- refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 (v0.2.37, one model seam): it rewrites the wire adapters in
openai.pyandunified.py. Merge this item first, so that refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 carries the limiter into the gateway adapter. - fix(ai): reasoning request parameters follow the model's declared capability, not its name #888 (v0.2.37, reasoning parameters): it edits
_build_compat_payload(openai.py:86-111), not the two request methods. Whichever merges second rebases. - fix(review): a group-analysis reply cut at its token cap is rejected, not shown as a checked explanation #876 (v0.2.37, blocked): it touches the persona stage's reply handling, not its sizing. There is no order constraint.
Problem
This is a Copilot thread on release PR #1283, verified at b57ef7f. #1069 aimed to keep gateway reviews within the backend's slot count. In gateway mode, though, file workers are max(DEFAULT_GATEWAY_REVIEW_CONCURRENCY, len(ollama_urls) * ollama_max_parallel) at both the persona and verifier stages [code: src/devops_cli/config/defaults.py:445; src/devops_cli/ai/review/pipeline.py:3530, :3827]. Each file also runs its personas in parallel. A probe peaked at 15 requests in flight with one URL and 30 with three, against 3 slots. Gateway traffic goes only to gateway_url, so each extra ai.ollama_urls entry raises the overload without adding capacity. That can rebuild the backend queue #1069 meant to prevent. The owner's setup lists several Ollama URLs. The v0.2.28 release notes no longer claim the limit.
Acceptance criteria
- In gateway mode, both stages size their worker pools at
DEFAULT_GATEWAY_REVIEW_CONCURRENCY, whateverai.ollama_urlsholds. - One thread-safe limit at the slot sum covers persona and verifier requests, so requests in flight never exceed it.
- Tests: with three URLs the pool size is 3 (today 6), and peak requests in flight stay at or below 3 (today 15).
-
changelog.d/<n>.mdrecords the change;CHANGELOG.mdanddocs/ROADMAP.mdare not edited. -
uv run devops cipasses.
Strategic alignment
- Milestone: none; the roadmap tooling places it. Related: fix(ai): review calls through the gateway no longer stall for about 190 s on ollama, with the cause measured first #1069, feat(release): v0.2.28 #1283.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty-bot commentedon Oct 8, 2026
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.
It undermines the concurrency guarantee #1069 established and can rebuild backend overload for multi-URL setups, but the system still functions and is not a security or total-outage issue.Users with multiple Ollama URLs (like the owner) experience backend overload and queue growth, but single-URL users are less affected.Requires changing pool sizing in two pipeline stages, adding a shared thread-safe semaphore, and writing concurrency tests, but the scope is confined to a few files.dan-petty commentedon Oct 17, 2026
Readiness check for v0.2.37, against
release/v0.2.36at 22d8748. Line numbers are at that commit.Status: ready after a reference refresh. One pull request (S).
Today
src/devops_cli/ai/review/pipeline.py:3727setsbatch_capacity = max(base_capacity, len(ollama_urls) * max_par), and the worker pool is created at:3782.parallel=True(pipeline.py:1211), up to 8 workers (src/devops_cli/ai/agents/pipeline.py:357).src/devops_cli/ai/client/network.py:158has only per-Ollama-URL semaphores.References that moved
defaults.py:445→:430pipeline.py:3530→:3716-3735:3827) was deleted by refactor(review): the model verifier, the hallucination catalog and the model-claim guards are deleted, and person-recorded verdicts become suppressions #1150 (PR refactor(review): the model verifier, the hallucination catalog and the model-claim guards are deleted, and person-recorded verdicts become suppressions (#1150) #1529).src/devops_cli/review/analysis.py:772-776) caps its pool at the slot sum, and runs after the persona stage (pipeline.py:4854).Dependencies: #1069, #1283 and #1150 are closed.
The body's 15 was the one-URL figure. With today's three URLs it is 30.
Questions for the owner
--concurrencystill be able to exceed the cap?:3729allows it today.Plan, tests first
review.workers == 3, with at most 3 requests in flight.BoundedSemaphoreinai/client/network.pyaround each persona call and each group-analysis call.changelog.d/1354.md.fix(ai): gateway requests stay within the backend slot count in every…
dan-petty commentedon Oct 18, 2026
What changed
#1639, merged into
release/v0.2.37as 30b8fdd.24 file(s) changed.
How it was verified
Check runs at 3f7f716:
Acceptance Criteria of
docs/agent/tasks/task-1354-gateway-review-slot-limit.md:min(total_files, DEFAULT_GATEWAY_REVIEW_CONCURRENCY), whateverai.ollama_urlsholds:test_gateway_file_pool_is_the_slot_sum_whatever_the_ollama_nodesgets 3 with three URLs andollama_max_parallel=2over six files (6 on the base). Group analysis keeps its clamp.--concurrencyabove the slot sum is clamped to it with the gateway provider, with one warning naming both numbers, whose text lives inReviewMessages(test_gateway_concurrency_above_the_slot_sum_is_clamped_with_one_warning). An Ollama review keeps its node sizing (6) and an explicit 8 over ten files with no warning, withai.gateway_enabledset or not (test_ollama_review_keeps_its_node_sizing_and_an_explicit_concurrency).network.pycovers every chat requestLLMClientsends withprovider == "gateway", streamed or not. Eight threads never hold more than the slot sum (test_gateway_slots_never_admit_more_than_the_slot_sum), a wait past the timeout raises anAIClientErrornaming the slot sum (test_a_wait_past_the_slot_timeout_names_the_slot_sum), a gateway chat call sends nothing while every slot is held, plain or streamed (test_a_gateway_chat_call_waits_for_a_gateway_slot), an open stream keeps its slot after its first chunk and gives it back when closed early (test_a_gateway_stream_holds_its_slot_until_the_generator_closes), and anopenaiclient sends while every gateway slot is held, withai.gateway_enabledset or not (test_another_provider_sends_while_every_gateway_slot_is_held).ai.ollama_urls, through a gatewayLLMClienton a fake gateway that holds each request until more than the slot sum are in flight or 0.25 s after the first request, make 12 calls with at most 3 in flight (TestGatewayRequestsStayWithinTheSlotSum). The same test fails at 4 in flight on the base and with the limiter switched off. No new test touches the network.ai.llm.gateway_slotspan under its call span, one 120 s observation of the wait histogram, and 2 s as itsllm.wall_secondsand spend duration, plain or streamed (test_a_gateway_call_is_timed_from_when_its_slot_is_held).devops review benchmark -c 8records 3 as its setup's concurrency through the gateway and 8 with Ollama (test_a_review_benchmark_records_the_concurrency_its_reviews_ran_at).FormattedLLMResponse, with or without a schema (test_a_repaired_reply_builds_no_model_class_of_its_own).--concurrencyhelp fordevops reviewsays it is capped at the gateway's backend slots, anduv run devops docs checkpasses afteruv run devops docs generate --sync-readme.changelog.d/1354.mdrecords the change under### Fixedand### Added.CHANGELOG.mdanddocs/ROADMAP.mdare not edited.TestGatewayRequestsStayWithinTheSlotSumtook 0.39 s to 0.81 s over ten runs, and the limiter and sizing tests each run in under 0.15 s.feat(release): v0.2.37 (#1720)