Skip to content

feat(cli): recovery transitions for adaptive knobs coalesced decrease, valkey breaker, failback #596

Closed
3 of 3 issues completed

Description

@dan-petty

Tracking issue

This issue tracks the three PRs of the plan in "Scope & Deliverables". One pull request closes each child issue. No pull request closes this issue. This issue closes when all three PRs are delivered.

PR1 and PR2 got their child issues on 2026-10-24, after #1985 stopped intake from judging a part a duplicate of its source. This issue closes when all of its child issues close.


Context & Rationale

#430 added AIMD recovery to the embedding batch size, marked delivered in the "Capability-Gated Model Failover & AIMD Batch Recovery" item, but three one-way transitions remain. First, _embed_ollama fixes chunk_batch_size once per call (src/devops_cli/ai/rag/embeddings.py:697), and every slow batch in that call halves again (:640, :653) although none was sent at the reduced size. The increase fires on any batch at or under 2.0 s, with none of the cooldown or 0.5x margin vibes proposes (embeddings.py:331-336). Second, one Valkey error nulls the L2 client for the rest of the run (embeddings.py:359,374; security/vulnerability_lookup.py:451,467), pinned by tests/test_security_threat_intel.py:228, while cache/tiered.py:202-222 retries and reconnects on every call during an outage (valkey/pool.py:118-144). Third, trigger_failover persists a failover:* route (ai/gateway.py:487-526) with no failback, and a healthy probe clears the breaker flag but keeps the route (gateway.py:418). #430 also left a backwards-compatible _halve_batch_size alias (embeddings.py:327).

Scope & Deliverables

  • Context & Rationale*: feat(ai): capability-gated model failover & aimd batch recovery #430 added AIMD recovery to the embedding batch size, marked delivered in the "Capability-Gated Model Failover & AIMD Batch Recovery" item, but three one-way transitions remain. First, _embed_ollama fixes chunk_batch_size once per call (src/devops_cli/ai/rag/embeddings.py:697), and every slow batch in that call halves again (:640, :653) although none was sent at the reduced size. The increase fires on any batch at or under 2.0 s, with none of the cooldown or 0.5x margin vibes proposes (embeddings.py:331-336). Second, one Valkey error nulls the L2 client for the rest of the run (embeddings.py:359,374; security/vulnerability_lookup.py:451,467), pinned by tests/test_security_threat_intel.py:228, while cache/tiered.py:202-222 retries and reconnects on every call during an outage (valkey/pool.py:118-144). Third, trigger_failover persists a failover:* route (ai/gateway.py:487-526) with no failback, and a healthy probe clears the breaker flag but keeps the route (gateway.py:418). feat(ai): capability-gated model failover & aimd batch recovery #430 also left a backwards-compatible _halve_batch_size alias (embeddings.py:327).
  • Deliverable*: Three small PRs. Each PR closes its own child issue, which the section "Tracking issue" lists. PR1: pass the sent size into _record_batch_latency and the timeout path, skip a decrease when the sent size exceeds the current one, add a cooldown and a margin below the threshold before any increase, delete the alias, and migrate tests/test_rag_embeddings.py:399-407. Test it through _embed_ollama with a stubbed endpoint and two workers. PR2: adopt pybreaker behind one seam at the Valkey L2 boundary, route the engine, the threat-intel client and TieredCache through it, delete every self._valkey = None, and rewrite the pinning test to cover open, cooldown, half-open and closed. PR3: the route file feeds only devops ai gateway status/routes, while live fallback belongs to LiteLLM's fallbacks (k8s/llm/gateway/configmap.yaml:118-137). Make status report failover while any route is failover:*, and add failover --reset to restore default routes. List each knob, its trip, reset and test in the task file.
  • Constraint*: A naive recovery is worse than the ratchet. Increasing on every healthy batch without a margin can climb straight back to the size that breached, and uncoalesced decreases then undo it in one call. Retrying Valkey on every call makes each call pay a connection attempt during an outage, which the disable avoids, so the breaker needs a real open state. Failback stays explicit: flipping routes on one healthy probe would call the local routes healthy regardless of LiteLLM, which owns traffic. A deliberate trip is recorded as one, not forced to recover.
  • Measured*: PYTHONPATH=src uv run --no-sync python probe/round_probe.py: one _embed_ollama call with default parallelism and every batch slow drives the size from 32 to 1. PYTHONPATH=src uv run --no-sync python probe/recovery_probe.py: 32 healthy batches climb from 1 back to 32. PYTHONPATH=src uv run --no-sync python probe/l2_probe.py: after one transient Valkey read error, 0 of the next 100 reads reach L2.
  • Source*: vibes observations/devops-cli/20-model-failover-capability-cliffs-and-one-way-degradation-ratchets.md

Update 2026-10-08: refinement

PR 1 holds (ai/rag/embeddings.py:847-856, :460-495). #1065 added a second hand-rolled breaker, the RAG lookup pause (ai/rag/investigator.py:116-147); the Valkey sites are embeddings.py:518, :533 and security/vulnerability_lookup.py:401-438.

  • One circuit-breaker implementation in src, used by the Valkey boundary and the lookup pause, tested open, cooldown, half-open and closed.

Proposed design

Problem statement

The issue addresses three one-way transitions that remain from AIMD recovery implementation in #430. First, _embed_ollama does not coalesce decreases and increases without proper cooldown or margin. Second, Valkey errors permanently disable the L2 client instead of using a circuit breaker pattern. Third, failover routes persist without a corresponding failback mechanism.

Acceptance criteria

  • Criterion 1: The _record_batch_latency function properly handles sent size and skips decreases when sent size exceeds current size
    Verification: Run PYTHONPATH=src uv run --no-sync python probe/round_probe.py to verify that one _embed_ollama call with default parallelism and every batch slow drives the size from 32 to 1, and then run PYTHONPATH=src uv run --no-sync python probe/recovery_probe.py to verify that 32 healthy batches climb from 1 back to 32.
  • Criterion 2: A circuit breaker is adopted for Valkey L2 boundary and the engine, threat-intel client and TieredCache route through it
    Verification: Run PYTHONPATH=src uv run --no-sync python probe/l2_probe.py after implementing the circuit breaker to verify that after one transient Valkey read error, 0 of the next 100 reads reach L2.
  • Criterion 3: Failover routes report properly in devops ai gateway status and can be reset with failover --reset
    Verification: Run devops ai gateway status to confirm failover is reported while any route is failover:*, and execute devops ai gateway failover --reset to verify default routes are restored.

Key questions

  • What is the current implementation of _embed_ollama that causes uncoalesced decreases?: _embed_ollama fixes chunk_batch_size once per call and every slow batch in that call halves again although none was sent at the reduced size. The increase fires on any batch at or under 2.0 s, with none of the cooldown or 0.5x margin vibes proposes. [sources: src/devops_cli/ai/rag/embeddings.py:697, src/devops_cli/ai/rag/embeddings.py:640, src/devops_cli/ai/rag/embeddings.py:653, src/devops_cli/ai/rag/embeddings.py:331, src/devops_cli/ai/rag/embeddings.py:336]
  • What is the problem with the current Valkey error handling?: One Valkey error nulls the L2 client for the rest of the run, while cache/tiered.py retries and reconnects on every call during an outage. [sources: src/devops_cli/ai/rag/embeddings.py:359, src/devops_cli/ai/rag/embeddings.py:374]
  • What is the issue with the failover mechanism?: trigger_failover persists a failover:* route with no failback, and a healthy probe clears the breaker flag but keeps the route. [sources: src/devops_cli/ai/gateway.py:487, src/devops_cli/ai/gateway.py:526, src/devops_cli/ai/gateway.py:418]
  • Should the circuit breaker implementation be reused in a future item?: Yes, the v0.3.4 "Proportional API Rate Budgeting & GraphQL Circuit Breaker Guard" should reuse the implemented circuit breaker. (proposed) [sources: docs/agent/tasks/task-596-recovery-transitions-for-adaptive-knobs-coalesced-decrease-v.md]

Fit

Needs splitting into 3 items:

  1. PR1: Pass sent size into _record_batch_latency and timeout path, skip decrease when sent size exceeds current one, add cooldown and margin before increase, delete alias, and migrate tests
  2. PR2: Adopt pybreaker behind seam at Valkey L2 boundary, route engine, threat-intel client and TieredCache through it, delete self._valkey = None statements, rewrite pinning test
  3. PR3: Make status report failover while any route is failover:*, add failover --reset to restore default routes

Suspected block

None.

Dependencies

None.

Sub-issues

Sub-issues

3 of 3 Issues completed
Loading 3 sub-issues

Activity

  1. added this to the v0.2.23 milestone on Sep 25, 2026
  2. added
    type/feature
    scope/cli
    priority/p2-medium
    on Sep 25, 2026
  3. modified the milestones: v0.2.23, v0.2.24 on Sep 28, 2026
  4. removed this from the v0.2.23 milestone on Oct 1, 2026
  5. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from the shipped v0.2.23 to the backlog. It is still valid (checked 2026-10-01), and P2 items don't displace P1 work in the planned releases.

  6. added
    scope/ai
    and removed
    scope/cli
    on Oct 2, 2026
  7. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Lines cited at dcafadf.

    #1113 replaces the hand-written Valkey client with Valkey GLIDE (valkey-glide-sync). Two of its changes meet this item's second PR, the Valkey breaker:

    • Its first PR deletes the devops_cli.cache package, TieredCache included, and valkey/pool.py. Nothing in src builds a TieredCache outside tests, so leave cache/tiered.py (:202-222) out of the breaker.
    • Its second PR gives the fail-soft caches (embeddings, library symbols and threat intel) one shared store per process. The first failure switches the cache tier off for the rest of the process and closes the store, which also stops GLIDE's own reconnect attempts. Today each cache does this on its own with self._valkey = None (ai/rag/embeddings.py:412, :427; security/vulnerability_lookup.py:401, :422, :438).

    This item's breaker replaces that one-way switch with open, cooldown and half-open states. Whichever of the two lands second puts the breaker at the shared store's boundary rather than in each cache. An open breaker closes the store, because GLIDE otherwise keeps reconnecting.

  8. added this to the v0.2.39 milestone on Oct 17, 2026
  9. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Proposal needs splitting into 3 items at 3dd7fa6 (see proposed design in issue body).

  10. modified the milestones: v0.2.39, on Oct 20, 2026
  11. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    Issue #596 is a tracking issue. The issue body states that no pull request closes this issue. The plan requires three child pull requests. PR3 is child issue #1986. Intake must file child issues for PR1 and PR2. Work can start on each child issue after intake files it.

  12. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    All three child issues of this tracker are closed by merged pull requests on 2026-10-24:

    This issue closes when all of its child issues close, so it closes now.

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/aitype/feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions