Trial retry backoff sleeps while holding the global concurrency slot; one rate-limited agent can stall a multi-agent job

Open
#4,597 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@ElhaanDaud is already working on this.

Since Dec 3, 2026.

  • #4617 by @ElhaanDaud — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Start with TrialQueue._run_trial and _execute_trial_with_retries in src/harbor/trial/queue.py, then trace how job_plan.py schedules trials and uses the semaphore. Check the existing retry tests before changing the flow. Done when retry backoff no longer blocks healthy trials from using global concurrency slots and the tests cover this behavior.

Written by the indexing model from the issue text.

Description

Problem

TrialQueue._run_trial acquires the job-wide semaphore and then runs _execute_trial_with_retries inside it
(src/harbor/trial/queue.py, _run_trial / _execute_trial_with_retries). The retry backoff
(await asyncio.sleep(delay_sec)) therefore runs while the trial still holds one of n_concurrent_trials slots.

That is cheap with the default backoff (1-60 s). It becomes a problem when the backoff is long enough to outlast a
provider or subscription quota window, which is the reason to configure RetryConfig.min_wait_sec/max_wait_sec
for ApiRateLimitError at all. Quota windows of hours are common for subscription plans. In a job with several
agents (JobConfig.agents with per-agent n_concurrent / concurrency_group), when one provider's quota runs out:

  • its trials fail fast with ApiRateLimitError and go to sleep for min_wait_sec * multiplier^attempt, each holding
    a global slot;
  • trials are interleaved by agent (job_plan.py), so as other agents' trials finish, more of the exhausted agent's
    trials start, fail and sleep;
  • eventually all n_concurrent_trials slots are held by sleeping trials and the agents whose quota is fine make no
    progress until the backoff ends.

The per-agent caps (AgentConfig.n_concurrent) do not help: they gate only the agent.run() phase via
AGENT_START/AGENT_END hooks. Environment start, agent setup and the retry sleep all sit under the global semaphore.

Minimal repro

# job.yaml
n_concurrent_trials: 4
retry: {max_retries: 3, include_exceptions: [ApiRateLimitError], min_wait_sec: 600, wait_multiplier: 2, max_wait_sec: 3600}
agents:
  - {name: agent-a, model_name: provider-a/model, n_concurrent: 2}   # quota exhausted -> ApiRateLimitError
  - {name: agent-b, model_name: provider-b/model, n_concurrent: 2}   # healthy

Once agent-a's quota runs out, the healthy agent-b trials make no progress until agent-a's backoff (10+ minutes)
ends. The same happens with any agent that raises a retryable error quickly.

Proposed change

Release the global slot during the backoff and acquire it again before the next attempt:

async def _run_trial(self, trial_config):
    for attempt in range(self._retry_config.max_retries + 1):
        async with self._semaphore:
            result, delay = await self._run_attempt(trial_config, attempt)  # returns (result, None) when final
        if delay is None:
            return result
        await asyncio.sleep(delay)  # outside the semaphore

The attempt directory cleanup stays where it is. Retried trials can be queued behind fresh ones; if that ordering
matters, a priority queue or an "acquire before fresh trials" flag can keep it.

Optional follow-up, possibly a separate issue: let a rate-limit failure pause the agent's concurrency pool
(concurrency_key) for the backoff instead of each trial backing off on its own. Then one quota reset is waited for
once, not N times. #1664 covers LiteLLM-level 429 retries; this issue is about trial-level retries in TrialQueue.

Version: harbor 0.27.0 (unchanged in 0.27.1.dev202612011755).

Dominant language
Python
Stars
5.6k
Forks
1.9k
Avg merge
1d 17h
Merged PRs (30d)
156

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from harbor-framework/harbor

All issues in harbor-framework/harbor

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.