Trial runs the agent's `populate_context_post_run` on the event loop, so trials that end together stall the orchestrator for seconds

Open Beginner friendly
#4,652 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Leeminjing is already working on this.

Since Dec 5, 2026.

  • #4655 by @Leeminjing — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
77/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start in src/harbor/trial/trial.py at _sync_agent_output (v0.28.0 lines 1203–1208) and compare with PR #4043, which moved live metrics work to a worker thread. Check how _populate_agent_context and load_model_usage_from_trajectory are called and run the relevant trial tests. Done means both calls no longer block the event loop, trajectories stay the same, and concurrent trial completion does not stall other work.

Written by the indexing model from the issue text.

Description

Trial._sync_agent_output is a coroutine, but it calls _populate_agent_context (the agent's populate_context_post_run) and load_model_usage_from_trajectory synchronously, on the event loop: trial.py#L1203-L1208 at v0.28.0, and the same on main and in 0.26.0.

One conversion is quick: about 90 ms for a 3 MB Claude Code session log. But when the agent phases of many trials end together, their conversions run back to back and the loop serves nothing else until the last one is done. With 54 trials that is about 5 s on 0.28.0, during which the other trials' commands, uploads and timeouts all wait. We hit it in a job where about 50 trials ended together.

A possible fix is to run the two calls in a worker thread, as #4043 did for the live metrics:

await asyncio.to_thread(self._populate_agent_context, target.agent_result)

With that change the same 54 trials held the loop for about 0.4 s and wrote the same trajectories.

Related: #2691, the same kind of stall from task.checksum at a trial's start.

Disclosure: Claude Code helped trace the call site, measure it and draft this report, which I reviewed.

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.