Skip to content

fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019

Closed

Description

@dan-petty

Problem

The gateway counted more devops-review requests than the spend ledger holds. Per the review evaluation of 2026-10-02, the gateway answered 420, 203 and 252 requests during the branch reviews 20261002-142541, -163203 and -180320 (S1 to S3). The ledger holds 273, 149 and 174 rows for them, so 279 of 875 gateway requests (32%) have no row. The ledger side is rechecked: the three session windows hold exactly those rows, and each profile.json llm_calls matches. The gateway side is one Prometheus measurement and is not rechecked here, because Grafana was unreachable. The evaluation also counted about 14 gpt-oss requests on ollama-24gib during S3. The ledger has no S3 row served by 24gib, against 6 in S1 and 5 in S2.

Until this is explained, every cost and throughput figure from the ledger is a lower bound. That includes the review profile, devops ai spend and the per-backend cost #477 takes from real traffic.

Three layers send gateway requests that write no ledger row, and the data cannot tell which explains the gap:

  • The retry transport. Every LLMClient HTTP client wraps its transport in a tenacity retry transport (_create_retry_transport, src/devops_cli/ai/client/base.py:59-70, used by _shared_client at :82-103 and _create_http_client at :73-80). It retries a 5xx, 408 or 429 status, a timeout and any transport error, up to max_retries + 1 = 5 attempts (src/devops_cli/ai/retries/__init__.py:40-100). These retries happen inside one http_client.post, so _dispatch_messages sees only the last outcome. Replayed at 38517a8 with a provider openai client whose innermost transport answers 500 once and then a reply: the gateway gets 2 requests and the ledger gets 1 row, ("chat_dispatch", "stop"). A read timeout and then a reply gives the same.
  • Client attempts that fail. _dispatch_messages records spend only after the provider returns (src/devops_cli/ai/client/unified.py:421-427). An attempt that raises writes nothing. _retry_chat_dispatch then tries again, up to max_retries more times (unified.py:645-668; DEFAULT_AI_MAX_RETRIES = 4, src/devops_cli/config/defaults.py:84). Stacked on the transport, one chat() call against a gateway that always answers 500 sent 25 requests and wrote no row in the same replay. A stream that fails before its first chunk records nothing either (unified.py:860-873, tests/test_ai_spend_dispatch.py:357-377). A review client's read timeout is 1,200 s (DEFAULT_REVIEW_TIMEOUT_SECONDS, defaults.py:296), and the gateway's is 1,500 s (k8s/llm/gateway/configmap.yaml:202). So after a client timeout the gateway can keep generating while the transport sends the same request again.
  • Retries inside the gateway. The router retries a failed backend call up to 5 times within the model group (num_retries, k8s/llm/gateway/configmap.yaml:198). devops-review has no fallback group (:207-213). The client sees one request. The gateway's per-deployment counter (litellm_deployment_total_requests_total, read by src/devops_cli/ai/pool_load.py:124) may count each attempt.

No existing test sees the first layer. route_client (tests/llm_stream_fakes.py:85-102) replaces the whole HTTP client with a plain MockTransport, so every spend test runs without the retry transport.

A reply that fails validation is not part of the gap. Its spend is recorded inside _dispatch_messages, before _validate_response_text rejects it (unified.py:647-657), so validation retries already write rows. The evaluation's "a ledger row is written only after a successful dispatch" is correct only in that sense: a dispatch that raises writes nothing, and neither does an attempt the transport retried.

The rule that a failed call writes no row came from #599 (8b1e8d4). It holds for a connection that never opens, since no request reached the gateway. It does not hold for an error status or a timeout, where the gateway did receive the request.

Acceptance criteria

  • (person-run) Measure before changing code. Run one branch review while no other client uses devops-review. Post a table on this issue for the session window with: ledger rows; for the alias, the gateway's proxy-level request delta by status code (litellm_proxy_total_requests_metric_total); its deployment-level delta (litellm_deployment_total_requests_total); and litellm_deployment_failure_responses_total. The table says how much of the gap is client attempts (proxy-level requests without a row) and how much is gateway retries (deployment-level minus proxy-level).
  • Each HTTP attempt that reaches the gateway and fails writes one ledger row, whichever layer retries it: the retry transport or _retry_chat_dispatch. That covers an HTTP error status and a read timeout. The row has finish reason error, the attempt's wall time, its stage and its serving backend when known, and 0 prompt and 0 completion tokens unless the provider reported usage. A connection that never opens (ConnectError, ConnectTimeout) writes no row. A successful attempt still writes exactly one row, as today.
  • Streams follow the same rule. A stream the gateway answers with an error status writes one error row per attempt that reached it. The http-500 case of test_a_stream_failing_before_its_first_chunk_records_nothing (tests/test_ai_spend_dispatch.py:357-377) is inverted, renamed and moved onto the real retry transport, as below. The connect case stays.
  • Tests in tests/test_ai_spend_dispatch.py keep the client's real retry transport. Only the innermost httpx2.HTTPTransport is replaced by a MockTransport (a helper beside route_client, which bypasses the retry transport), and the retry wait is patched to 0. A handler that answers 500 once and then a reply writes two rows, ("chat_dispatch", "error") and ("chat_dispatch", "stop"). A read timeout followed by a reply also writes two. A refused connection followed by a reply writes one. A handler that answers 500 five times and then a reply (the transport gives up once, _retry_chat_dispatch tries again) writes five error rows and one stop row. The first, second and fourth fail on the current code.
  • The review profile counts failed attempts with no schema change: llm_calls includes them, and each stage's finish_reasons["error"] counts them (src/devops_cli/ai/review/profile.py:208-229). devops_cli_ai_requests_total gets one point per failed attempt, as for every row (src/devops_cli/ai/spend/ledger.py:696).
  • The new tests reach no real gateway, Prometheus or DNS, and run in under 1 s together.
  • uv run devops ci passes.
  • (person-run) After the fix, repeat the measurement on one review. Ledger rows equal the gateway's proxy-level delta for the alias within 1%. The PR attributes any remaining difference from the deployment-level delta to gateway retries, with the counts.

Key questions

  • Why measure first? (proposed) The data cannot separate the layers. If gateway retries explain most of the gap, client-side rows change little, and the missing requests are the gateway's own cost, which only its counters see. The measurement needs a live gateway and a person, so it is the first acceptance item, and its table is posted before the code is reviewed.
  • Where is a failed attempt recorded? (proposed) In a thin transport wrapped inside the retry transport, the only place that sees every attempt. _dispatch_messages and chat_messages_stream set a context variable with the provider, model and task for the call, and the wrapper reads it. The wrapper cannot capture them when the client is built, because _shared_client shares one HTTP client per provider class and backend type across every task's LLMClient (base.py:98). Successful attempts stay recorded where they are now, with their tokens.
  • Should the retry layers be collapsed instead? (proposed) Not in this item. The transport (5 attempts), _retry_chat_dispatch (5) and the persona page loop (DEFAULT_REVIEW_RETRY_ATTEMPTS = 6, src/devops_cli/ai/review/pipeline.py:1357-1400) multiply, but the transport is also what honours Retry-After on a 429, which AGENTS.md requires. Changing how failures are retried is a separate defect. This item makes every attempt visible, which that work then needs to measure.
  • What does a failed attempt record? (proposed) Wall time, stage, backend and finish reason error, with 0 tokens unless the provider reported usage. Whether the backend processed the prompt before failing is unknown, so token totals stay honest lower bounds instead of guesses, while request counts and busy time become complete. Cost follows the tokens, so a failed attempt costs 0.
  • Should the ledger also record the gateway's internal retries? (proposed) No. The ledger records what this client sent. If the measurement shows that gateway retries matter, reading the gateway's counters belongs with feat(ai): llm gateway tuning cost from real traffic and no-load capacity estimates #477, which takes per-backend cost from real traffic.
  • Should this fold into fix(ai): response-cache hits are counted as cached requests #816? (proposed) No. fix(ai): response-cache hits are counted as cached requests #816 records requests the response cache answered, which never reached the gateway. This item records requests that reached the gateway and failed. Both write through track_request_spend, so whichever lands second rebases.
  • Do direct requests (src/devops_cli/ai/direct.py) change too? (proposed) No. They also record only on success, but a review never uses them: persona review (PydanticAgent, src/devops_cli/ai/agents/agent.py:887), verification and compose all go through LLMClient. File them separately if another consumer needs it.

Depends on: none.
Order: after #960 (v0.2.25), which changes LLMClient's timeouts in ai/client/unified.py, the file this item edits. If #816 or #591 is scheduled in the same release, sequence them: all three change how unified.py records a request.
Related: #816 (cache hits in the ledger). #591 (reasoning-token share and provider-reported stream usage). #477 (gateway cost from the ledger's per-backend rows). #599 (set the rule that a failed call records nothing). #960 (client timeouts). #1001 (one model seam; the record path moves with it).

Scope added 2026-10-02 from review session 20261002-214641 (.data/review-evaluation-20261002-s6.md, section 1): one verifier call for ai/mcp/server.py carried 42,490 prompt tokens, was cut, and took 408.9 s on ollama-16gib, 7.6 times the identical call in the previous session (53.8 s). For its last 276 s the run waited on that call alone. Explaining it needs gateway-side timing per attempt, which this item's measurement should record.

Scope added 2026-10-03 from review sessions 20261003-005122 (S7) and 20261003-012555 (S8) (.data/review-evaluation-20261003-s7-s8.md, sections 0, 1 and 3). Lines are at da50329. The gap also shows on the backend side, and the ledger cannot say which model served a call.

  • Backend requests with no row. ollama-16gib-fast's log shows 24 chat requests in S7 and 27 in S8 (the evaluation's count; the log is not saved with the sessions). The ledger holds 11 and 14 rows served by it (rechecked read-only: rows 9950-10008 and 10009-10069, none with finish reason error). Of the excess, 13 and 9 requests had status 200 and fall in the persona stages. S8's other 4 are the HTTP 500s below. Both runs had a persona-stage stall after two 8,192-token persona cuts on 16gib-fast (rows 9971/9972 in S7, 10029/10033 in S8). In S7, rows 9973-9982 ran 186-393 s, against about 30 s before. In S8, rows 10034-10042 ran 189-278 s, against 4.5-54 s before. Both stalls coincide with unledgered 16 GiB requests of 1.5 to 4.4 minutes each. Retries outside the ledger, another client and a model swap are all possible; the data cannot tell them apart. The 48 GiB and 64 GiB logs were lost when their pods were replaced, so those tiers are unmeasured.

  • Failed attempts with no row. S8's 4 HTTP 500s at 01:36:11 came from the old gateway pod during the verification stage, which spanned two gateway redeploys (01:35:21 and 01:39:31). None of them has a ledger row. Whether the client saw them (the retry transport or _retry_chat_dispatch) or the gateway's router retried them inside one client request (num_retries) is not known. Only the first case gets a row under this item's fix.

  • The model is not recorded. All 120 S7/S8 rows have model = devops-review, the alias, because both record paths pass self._config.model (src/devops_cli/ai/client/unified.py:486 and :905). The client parses the reply's own model into LLMResponse.model (src/devops_cli/ai/client/openai.py:149) and uses it only for the trace span's gen_ai.response.model and the llm_response_received event (unified.py:145, :129). The response cache also stores the alias (unified.py:556). served_by comes from the x-litellm-model-api-base header (openai.py:176, :206; src/devops_cli/config/constants.py:2143) and names a backend, not a model. A backend does not fix the model either: in S8, 48gib-slow served a gpt-oss reply with a reasoning trace (row 10053) and a qwen3-coder reply (row 10065). The evaluation's per-model figures (gpt-oss cut 9 of 20 verifier calls, qwen3-coder 0 of 33) had to be inferred from tier, the uncommitted gateway config read after the runs, and reasoning traces. feat(review): every reported finding is admitted with its producer's anchor and a location that exists in the reviewed commit, the review writes findings.sarif, and review.md shows findings and suppressions #871 names the same ledger gap but puts the model on findings and StageProfile, not on ledger rows. Both read the reply's model, so whichever lands second reuses the other's reading.

  • Each attempt's row records the backend that served it and the model the gateway resolved the alias to, in a new column beside model, which keeps the requested alias. The column is added in place like served_by (_ADDED_COLUMNS, src/devops_cli/ai/spend/ledger.py:64-68). A successful attempt takes the model from the reply. A failed attempt records backend and model when the error response names them, and null otherwise. A test whose handler answers with reply model gpt-oss:20b and the served-by header writes both on one row. It fails on the current code, which writes only devops-review.

  • Streams record the same two fields. A test on the stream path writes both, and fails on the current code.

  • (person-run) The measurement table adds each tier's own request count for the session window, from the ollama logs or metrics, next to the ledger rows by served_by. S7 and S8 measured the gap there. No gateway or ollama rollout runs during the window, and the table records the gateway configmap and the OLLAMA_MAX_LOADED_MODELS setting in effect.

  • (person-run) After the fix, the measured review's verifier calls can be counted per model from the ledger alone, and the counts match the backend logs per tier.

Key question added: Where does the resolved model come from? (proposed) The reply's own model field, which the client already parses. Whether the gateway returns the deployment's model or the alias there was not checked, because no gateway call was made for this evaluation. If it returns the alias, the PR reads the deployment from a gateway response header instead and says which. The person-run measurement checks it once against the live gateway.

Update 2026-10-08: refinement

The gap stands. The retry transport is now in the factory (http/client.py:160-166), so the recorder sits between egress and retry there. _retry_chat_dispatch re-raises at once (#1069), and review deployments set num_retries: 0 with a fallback (k8s/llm/gateway/configmap.yaml:85-97, :196).

  • A handler answering 500 five times writes five error rows, and the call raises.
    The alias is passed at ai/client/unified.py:452, :586, :907.

Proposed design

Problem statement

The spend ledger does not record every attempt a gateway request makes, particularly retries from the client-side transport and the retry dispatch logic. This causes a significant gap between the number of requests recorded in the ledger versus what the gateway actually processes, leading to underreported costs and throughput metrics.

Acceptance criteria

  • Criterion 1: Before changing code, measure the gap by running one branch review while no other client uses devops-review, and post a table with ledger rows, proxy-level request delta by status code, deployment-level delta, and failure responses.
    Verification: Run one branch review with a live gateway and Prometheus metrics, then post a table showing the session window data on this issue.
  • Criterion 2: Each HTTP attempt that reaches the gateway and fails writes one ledger row, whether it's retried by the retry transport or _retry_chat_dispatch, with finish reason error and relevant metadata.
    Verification: Test that a handler answering 500 once and then a reply writes two rows: ("chat_dispatch", "error") and ("chat_dispatch", "stop").
  • Criterion 3: Streams follow the same rule for failed attempts, with one error row per attempt that reached the gateway.
    Verification: Test that a stream failing before its first chunk records no row (current behavior) but after the fix, it should record an error row.
  • Criterion 4: Tests in test_ai_spend_dispatch.py use the real retry transport and verify correct ledger entries for various failure scenarios.
    Verification: Run existing tests with updated mock handling to confirm that 500 errors followed by a reply correctly write multiple rows.
  • Criterion 5: The review profile counts failed attempts without schema changes, including them in llm_calls and updating finish_reasons["error"].
    Verification: Verify that the review profile's llm_calls includes failed attempts and finish_reasons["error"] is updated accordingly.
  • Criterion 6: All new tests run in under 1 second and do not require real gateway, Prometheus or DNS access.
    Verification: Run the test suite locally to ensure all tests complete within 1 second.
  • Criterion 7: A changelog fragment is created for this fix under ### Fixed.
    Verification: Check that changelog.d/1019.md exists and contains a correct entry under ### Fixed.
  • Criterion 8: Running uv run devops ci passes all checks.
    Verification: Execute the CI command locally to confirm all checks pass.
  • Criterion 9: After the fix, ledger rows equal the gateway's proxy-level delta for the alias within 1%.
    Verification: Repeat the measurement after the fix and ensure that any remaining difference from deployment-level delta is attributed to gateway retries with correct counts.

Key questions

  • Why measure first?: The data cannot separate the layers. If gateway retries explain most of the gap, client-side rows change little, and the missing requests are the gateway's own cost, which only its counters see. The measurement needs a live gateway and a person, so it is the first acceptance item, and its table is posted before the code is reviewed. [sources: src/devops_cli/ai/client/unified.py:421-427]
  • Where is a failed attempt recorded?: In a thin transport wrapped inside the retry transport, the only place that sees every attempt. _dispatch_messages and chat_messages_stream set a context variable with the provider, model and task for the call, and the wrapper reads it. [sources: src/devops_cli/ai/client/base.py:59-70]
  • Should the retry layers be collapsed instead?: Not in this item. The transport (5 attempts), _retry_chat_dispatch (5) and the persona page loop (DEFAULT_REVIEW_RETRY_ATTEMPTS = 6) multiply, but the transport is also what honours Retry-After on a 429, which AGENTS.md requires. Changing how failures are retried is a separate defect. (proposed) [sources: src/devops_cli/ai/retries/init.py:40-100]
  • What does a failed attempt record?: Wall time, stage, backend and finish reason error, with 0 tokens unless the provider reported usage. Whether the backend processed the prompt before failing is unknown, so token totals stay honest lower bounds instead of guesses, while request counts and busy time become complete. [sources: src/devops_cli/ai/client/unified.py:421-427]
  • Should the ledger also record the gateway's internal retries?: No. The ledger records what this client sent. If the measurement shows that gateway retries matter, reading the gateway's counters belongs with feat(ai): llm gateway tuning cost from real traffic and no-load capacity estimates #477, which takes per-backend cost from real traffic. (proposed) [sources: src/devops_cli/ai/spend/ledger.py:696]
  • Should this fold into fix(ai): response-cache hits are counted as cached requests #816?: No. fix(ai): response-cache hits are counted as cached requests #816 records requests the response cache answered, which never reached the gateway. This item records requests that reached the gateway and failed. Both write through track_request_spend, so whichever lands second rebases. (proposed) [sources: src/devops_cli/ai/client/unified.py:421-427]
  • Do direct requests (src/devops_cli/ai/direct.py) change too?: No. They also record only on success, but a review never uses them: persona review (PydanticAgent, src/devops_cli/ai/agents/agent.py:887), verification and compose all go through LLMClient. File them separately if another consumer needs it. [sources: src/devops_cli/ai/direct.py]
  • Where does the resolved model come from?: The reply's own model field, which the client already parses. Whether the gateway returns the deployment's model or the alias there was not checked, because no gateway call was made for this evaluation. [sources: src/devops_cli/ai/client/openai.py:149]

Open questions

  • Backend requests with no row. ollama-16gib-fast's log shows 24 chat requests in S7 and 27 in S8 (the evaluation's count; the log is not saved with the sessions). The ledger holds 11 and 14 rows served by it (rechecked read-only: rows 9950-10008 and 10009-10069, none with finish reason error). Of the excess, 13 and 9 requests had status 200 and fall in the persona stages. S8's other 4 are the HTTP 500s below. Both runs had a persona-stage stall after two 8,192-token persona cuts on 16gib-fast (rows 9971/9972 in S7, 10029/10033 in S8). In S7, rows 9973-9982 ran 186-393 s, against about 30 s before. In S8, rows 10034-10042 ran 189-278 s, against 4.5-54 s before. Both stalls coincide with unledgered 16 GiB requests of 1.5 to 4.4 minutes each. Retries outside the ledger, another client and a model swap are all possible; the data cannot tell them apart. The 48 GiB and 64 GiB logs were lost when their pods were replaced, so those tiers are unmeasured.
  • Failed attempts with no row. S8's 4 HTTP 500s at 01:36:11 came from the old gateway pod during the verification stage, which spanned two gateway redeploys (01:35:21 and 01:39:31). None of them has a ledger row. Whether the client saw them (the retry transport or _retry_chat_dispatch) or the gateway's router retried them inside one client request (num_retries) is not known. Only the first case gets a row under this item's fix.
  • The model is not recorded. All 120 S7/S8 rows have model = devops-review, the alias, because both record paths pass self._config.model (src/devops_cli/ai/client/unified.py:486 and :905). The client parses the reply's own model into LLMResponse.model (src/devops_cli/ai/client/openai.py:149) and uses it only for the trace span's gen_ai.response.model and the llm_response_received event (unified.py:145, :129). The response cache also stores the alias (unified.py:556). served_by comes from the x-litellm-model-api-base header (openai.py:176, :206; src/devops_cli/config/constants.py:2143) and names a backend, not a model. A backend does not fix the model either: in S8, 48gib-slow served a gpt-oss reply with a reasoning trace (row 10053) and a qwen3-coder reply (row 10065). The evaluation's per-model figures (gpt-oss cut 9 of 20 verifier calls, qwen3-coder 0 of 33) had to be inferred from tier, the uncommitted gateway config read after the runs, and reasoning traces. feat(review): every reported finding is admitted with its producer's anchor and a location that exists in the reviewed commit, the review writes findings.sarif, and review.md shows findings and suppressions #871 names the same ledger gap but puts the model on findings and StageProfile, not on ledger rows. Both read the reply's model, so whichever lands second reuses the other's reading.
  • Each attempt's row records the backend that served it and the model the gateway resolved the alias to, in a new column beside model, which keeps the requested alias. The column is added in place like served_by (_ADDED_COLUMNS, src/devops_cli/ai/spend/ledger.py:64-68). A successful attempt takes the model from the reply. A failed attempt records backend and model when the error response names them, and null otherwise. A test whose handler answers with reply model gpt-oss:20b and the served-by header writes both on one row. It fails on the current code, which writes only devops-review.
  • Streams record the same two fields. A test on the stream path writes both, and fails on the current code.
  • (person-run) The measurement table adds each tier's own request count for the session window, from the ollama logs or metrics, next to the ledger rows by served_by. S7 and S8 measured the gap there. No gateway or ollama rollout runs during the window, and the table records the gateway configmap and the OLLAMA_MAX_LOADED_MODELS setting in effect.
  • (person-run) After the fix, the measured review's verifier calls can be counted per model from the ledger alone, and the counts match the backend logs per tier.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/ai
    scope/telemetry
    priority/p2-medium
    on Oct 2, 2026
  2. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    What S10 adds (review session 20261003-034353, release/v0.2.25 at d6ebe97; .data/review-evaluation-20261003-s10.md, sections 1 and 3). A measured case of attempts the ledger doesn't hold.

    • Count. The backends served 22 chat requests against 16 ledger rows (ollama pod logs, and in-cluster Loki for 48gib). All 6 extras are attempts behind 3 logical verification calls (pricing, verification.py and runner), each served three times.

    • Cost. The discarded attempts used 673.4 backend-seconds:

      • the 64gib first attempts: 187.2 + 163.6 + 156.3 s;
      • the runner's second attempt: 38.0 s;
      • the verification.py and pricing second attempts on 48gib: 71.9 and 56.6 s.

      The ledger records durations of 228.7-269.4 s, while the final attempts took 28.4-50.6 s.

    • Timing.

      • Second attempts started 184.9-186.2 s after the first ones.
      • All three third attempts started within 1.2 s of each other (03:55:23.7-03:55:24.9). Their second attempts had started at different times: 03:54:53.6 for verification.py, about 03:55:21 for the other two.
      • That points to one shared trigger rather than per-request timers.
    • Gateway.

      • The gateway logged 17 POST 200s for 16 ledger rows. The extra one is the runner's second qwen attempt (03:56:01.68), so at least one extra attempt was a separate client-facing request, not a LiteLLM-internal retry.
      • The verification.py and pricing second attempts finished (03:56:06.6 and 03:56:17.6) with no gateway 200.
      • No first attempt got a 200.
    • Runner cut. The runner's cut verdict (2 findings) is an artifact of this.

      • qwen completed that request twice: n_tokens 40,497 at 03:54:53 and 40,526 at 03:56:01.
      • The first completion finished before the gpt-oss attempt started (03:55:24) but was never delivered.
      • The cut gpt-oss reply got its 200 at 03:55:53.4 and was used.
    • A possible mechanism [hypothesis]: LiteLLM router_settings num_retries: 5 (k8s/llm/gateway/configmap.yaml:205, with allowed_fails: 3 and cooldown_time: 30). It hasn't been considered so far. The gateway timeout (1,500 s, :209) and the client read timeout (1,200 s) are ruled out.

    Limit: attempts missing from the ledger are matched to calls by token counts only.

  3. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    A measured case of the gap between the client and gateway timeouts (gemma4:31b, 2026-10-03). Source: the model-choice evaluation's verification pass (.data/model-choice-20261003.md). Ollama and event logs were read with kubectl, and the ledger read-only.

    What happened.

    • A review pinned to gemma4:31b (PID 2876635, started about 05:10Z) wrote no ledger row. The ledger ends at row 10550 (05:05:40), from an earlier abandoned run.
    • Only gemini (ollama-64gib) could load gemma4. condor and hog failed with cudaMalloc ... out of memory / failed to create MTP context at -c 512000 -np 4, which fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061 has since fixed.
    • gemini's replies took 22m25s and 23m05s (logged 05:36:50 and 05:37:30). That is past the review client's 1,200 s read timeout (DEFAULT_REVIEW_TIMEOUT_SECONDS, config/defaults.py:300). So the client had already abandoned those requests and sent them again: _retry_chat_dispatch retries on any exception (ai/client/unified.py:630).
    • From 05:39, gemini answered 500 at exactly 25m0s, about 40 times. That is the gateway's timeout: 1500 (k8s/llm/gateway/configmap.yaml:209). Each request ran on gemini's slots for 5 minutes after the client gave up on it, and the router's num_retries: 5 could send it once more.
    • The review process was gone by 05:47Z. Its requests stayed queued on all three nodes until the gateway rollout ended every one of them with 499/500 at 05:51:53. Abandoned work outlived the client by at least 5 minutes, and each request ran up to 25 minutes.

    What it means for this item.

    • None of those attempts has a ledger row, which is this item's gap.
    • For the person-run measurement: with a slow model, the 1,200 s / 1,500 s gap shows on the backend as 500s at exactly 25m0s.

    Related, filed today.

  4. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Review redesign (#1137, 2026-10-03): this item is a phase P0 child. Its body stands; its own ordering condition (after #960) is met. P0's "backend chats = ledger attempts" check (#1069) and #1147's call counts depend on it, and the review job queue (phase P3) builds its attempt records on it rather than absorbing it.

  5. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Amendment from the gateway usage investigation of 2026-10-17, at main 3dd7fa6.

    New evidence

    Corrections to the body

    • The dispatch loop no longer retries exceptions: src/devops_cli/ai/client/unified.py:660-667 re-raises with the comment "The HTTP transport is the single retry layer". The transport is the only client-side retry layer.
    • So "_retry_chat_dispatch then tries again" and the "500 five times then a reply" test case describe older code. The test case needs the current counts.
    • k8s/README.md:91 still says the client retries "in its HTTP transport and again in its dispatch loop". Fix it in this item's PR.

    Scope notes

    • Embedding requests are a separate, larger gap, covered by the embedding-recording item. This item stays chat-only, but the transport wrapper should read request_type from the same context variable so embedding attempts are covered once that item lands.
    • The gateway-side view of failed attempts goes on the dashboard in the gateway-series item, so this item adds no panel.

    Priority stays P2: no P1 waits on it.

  6. added this to the milestone on Oct 20, 2026
  7. dan-petty commented on Oct 20, 2026

    @dan-petty
    OwnerAuthor

    Status set back to New at 2954109: refine found it not ready (see Key questions, Fit and Suspected block in the proposed design in the issue body).

  8. removed this from the milestone on Oct 23, 2026
  9. added a commit that references this issue on Oct 24, 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

    priority/p2-mediumscope/aiscope/telemetrytype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions