Skip to content

fix(ai): gateway tune creates a debug container per deployment once its first one exits #796

Closed

Description

@dan-petty

Context & Rationale

3a773b3 (#677) made gateway tune reuse a debug container on the gateway pod. _ensure_sweep_container (ai/gateway_tune.py:517-555) reuses only the container with the fixed name, and that container runs sleep 3600. This causes two problems:

  • Once that container exits, every deployment measured creates a new container with a suffixed name. A simulated run over 3 deployments created 3 containers.
  • A reused container can also exit in the middle of a sweep, which kills the run. The default exec timeout is 2,460 s per deployment, so a long sweep can easily outlast the container's hour.

Found while checking the #669 fix.

Scope & Deliverables

  • Deliverable: a run tracks its active sweep container and creates at most one container. That container lives at least as long as the run's timeout. Tests cover an expired container and a run over several deployments.
  • Constraint: none

Strategic Alignment

  • Milestone: Backlog (no release)
  • Design: none
  • Depends on: none

Generated by Claude Code

Proposed design

Problem statement

The gateway tune functionality in the AI module creates a new debug container for each deployment instead of reusing one, leading to resource inefficiency and potential run interruptions when containers expire or are prematurely terminated.

Acceptance criteria

  • Criterion 1: A single debug container is created and reused throughout the entire sweep run, regardless of the number of deployments measured.
    Verification: Run a gateway tune sweep over multiple deployments and verify only one container is created and reused.
  • Criterion 2: The sweep container lives at least as long as the run's timeout to prevent premature termination during long sweeps.
    Verification: Configure a long-running sweep with a timeout and confirm that the debug container remains active throughout the duration.
  • Criterion 3: If an existing sweep container expires or terminates, a new one is correctly created and reused for subsequent deployments.
    Verification: Simulate a container expiration event and verify that a new container is created and used for continuing deployments.

Key questions

  • What is the current behavior of _ensure_sweep_container when the fixed-name container exits?: Once the fixed-name container (running 'sleep 3600') exits, every deployment measured creates a new container with a suffixed name. [sources: src/devops_cli/ai/gateway_tune.py:517]
  • What is the default exec timeout per deployment in the sweep?: The default exec timeout is 2,460 seconds per deployment. [sources: src/devops_cli/ai/gateway_tune.py:517]
  • What happens to a sweep when the reused container exits in the middle of a sweep?: A reused container can also exit in the middle of a sweep, which kills the run. [sources: src/devops_cli/ai/gateway_tune.py:517]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor

    Linked: #909. Both fix the in-pod sweep runner (ai/gateway_tune.py here, ai/gateway_bench.py there) and add tests to tests/test_ai_gateway_tune.py; they land in either order. Found by the 2026-10-08 backlog review.

  3. added this to the v0.2.39 milestone on Oct 17, 2026
  4. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 25e2cda (see proposed design in issue body).

  5. added a commit that references this issue on Oct 22, 2026
    fef712b
  6. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1826, merged into release/v0.2.39 as fef712b.

    devops ai gateway tune now attaches one sweep container to the gateway pod for a whole run, and that container lasts the run. Before, the container had the fixed name gateway-tune-runner and slept a fixed hour. Once it exited, every deployment measured attached another container under a suffixed name, so a run over three deployments could leave three on the pod. A run's exec budget is 2460 s per deployment at the defaults, so a reused container could also end in the middle of a sweep and kill the run.

    Cause: _ensure_sweep_container looked up only the fixed name on every measure_in_gateway_pod call, gave an exited container a suffixed replacement, and created every container with sleep 3600. tune_pool makes one call per deployment, so nothing tracked the container across the run and nothing sized its life to the run.

    Change: tune_pool names one container gateway-tune-<6 hex> per run and passes it, with a lifetime of the exec timeout times the number of deployments, to every measure_in_gateway_pod call. The container is created with sleep for that lifetime rounded up. _ensure_sweep_container reuses a running container and attaches an absent one. It raises a GatewayTuneError naming the container when it has exited, because attaching a second one would break "at most one container per run". The fixed default name and the suffixed-replacement branch are gone. A container an earlier run left behind is never reused, since its remaining life is unknown. Reus…

    4 file(s) changed.

    How it was verified

    Check runs at a714944:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Changed-Test Independence: pass
    • Rule Pack Tests: pass
    • Fail-to-Pass Self-Check: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-796-gateway-tune-sweep-container.md:

    No Acceptance Criteria section.

  7. added a commit that references this issue on Oct 23, 2026
    f209f6c
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/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions