Skip to content

fix(rag): a timed-out embedding batch closes the HTTP client that the other parallel batches use, so intake reports a healthy gateway as down #2011

Closed

Description

@dan-petty

Friction

  • devops roadmap intake stopped twice with "The model gateway ... did not answer", although devops ai gateway status reported the gateway healthy.
  • The retries printed [Errno 9] Bad file descriptor beside read timeouts. A batch that fails this way fails for a reason that its own request did not cause.

Evidence

Runs on 2026-10-23 at main 0bff85f and a752a14.

  • Intake embeds every board item through the gateway. _embed_parallel_openai_batches (src/devops_cli/ai/rag/embeddings.py:1067) runs up to 4 batches in parallel. All of them share one httpx2.Client (_get_http_client, :418-424).
  • On a transient error, _post_openai_batch_with_retry calls _reset_http_client() (:1038). That function closes the shared client (:426-434) while the other batches still read from it. Their reads then fail with [Errno 9] Bad file descriptor, and they reset the client again.
  • With no embedding timeout set, the read timeout is max(15.0, 30.0) s (DEFAULT_RAG_EMBEDDING_TIMEOUT and :422). A batch is up to 32 texts of up to 4000 characters (DEFAULT_RAG_EMBEDDING_BATCH_SIZE, DEFAULT_ROADMAP_INTAKE_TEXT_CHARS).
  • One short text took 19.8 s on a cold model and 40 short texts took 1.2 s warm. With DEVOPS_CLI_AI_TASK_EMBEDDING_TIMEOUT=120, the same intake passed.

Existing tool considered

  • The connection pool of httpx2 is safe for threads, and it drops a broken connection itself. So a worker does not need to close the shared client to discard a bad socket.

Proposed remedy

  • Do not close the shared client from one batch on a transient error. Let the pool drop the failed connection, or give each worker its own client.
  • Size the read timeout of a batch for its batch size and text length, or measure it, and state the value in defaults.py.

Acceptance criteria

  • A transient error in one parallel batch does not close the client that another batch uses. A test over a fake transport, where one batch times out, shows that the other batches complete.
  • No embedding request fails with Bad file descriptor because another batch closed the client.
  • The read timeout of an intake embedding batch is a named default, and a test shows that a batch of the largest size and text length is not cut off by it with a fake slow transport.
  • Tests run offline. uv run devops ci passes.

Activity

  1. added
    source/agent
    type/bug
    on Oct 23, 2026
  2. dan-petty commented on Oct 23, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/bug. The candidate fixes a bug in the embedding batch processing logic.
    • Priority: P1-High. The bug causes intake to report healthy gateways as down and leads to bad file descriptor errors. The failed run 1019 does not set P0: it does not appear in the candidate's text. A person can set P0 on the board.
    • Value: High. Fixing this bug improves system stability and prevents false alerts for gateway health.
    • Effort: Medium. The fix requires modifying client handling logic and adjusting timeout behavior in parallel batches.
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

    source/agenttype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions