OpenHands / OpenHands/software-agent-sdk

[Bug]: Agent terminal commands inherit server process priority

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

Nobody has claimed this yet.

bug performance priority:medium ready-for-dev tools
Dominant language
Python
Stars
1.1k
Forks
539
Avg merge
1d 19h
Merged PRs (30d)
137

Description

Is there an existing issue for the same bug?
  • I searched OpenHands/software-agent-sdk; there is no same-repository issue. The original cross-repository report is OpenHands/OpenHands#16720.
Bug Description

Agent commands launched through the SDK terminal backends inherit the agent-server process priority. CPU-heavy commands such as parallel Rust compilation can therefore starve the server event loop and make local OpenHands sessions appear locked up.

The upstream reproduction in OpenHands/OpenHands#16720 measured the same priority for the server and terminal commands. A follow-up by an OpenHands member confirmed that the required policy is platform-specific: macOS utility QoS, Linux niceness +10, and Windows Below Normal priority.

Expected Behavior

Terminal-tool child processes should run below the agent server's CPU priority by default, while an explicit terminal environment setting should allow priority-sensitive benchmarks or development servers to retain the parent priority.

Actual Behavior

Run uv run python reproduce_priority.py using the minimal SDK program below. On current main, the child reports normal Windows priority (32) or the same Unix niceness as the parent (0 in a default shell). CPU-heavy child processes consequently compete with the agent server at equal scheduling priority.

Steps to Reproduce
  1. Check out OpenHands/software-agent-sdk and run uv sync --dev.
  2. Save the minimal code below as reproduce_priority.py.
  3. Run uv run python reproduce_priority.py.
  4. Start several CPU-heavy commands through the same terminal session and observe that the agent server becomes slow or unresponsive.
Acceptance Criteria
  • Linux standalone tmux, pooled tmux, and subprocess terminal children inherit niceness +10 (capped at 19).
  • macOS terminal children run with taskpolicy -c utility.
  • Windows terminal child commands inherit BELOW_NORMAL_PRIORITY_CLASS.
  • OH_TERMINAL_PROCESS_PRIORITY=none preserves the parent priority.
  • A restricted terminal PATH, or a Linux image without nice, does not make a previously valid terminal fail to start.
Installation Method

uv sync --dev from a source checkout.

If you selected "Other", please specify

Source checkout.

SDK Version

main, reproduced at dc0c8428438dde13efa422fb456adfb542fd532d.

Version Confirmation
  • I confirmed this bug exists on the latest OpenHands SDK main branch before implementing the fix.
Python Version

3.13.15 locally; the scheduling behavior is not Python-version-specific.

Model Name (if applicable)

Not applicable.

Operating System

macOS, Linux, and Windows.

Logs and Error Messages

There is no exception. The failure mode is server starvation under CPU load. The full macOS/Linux throughput and latency measurements are in OpenHands/OpenHands#16720.

Minimal Code Sample
import platform
import tempfile

from openhands.tools.terminal import TerminalAction
from openhands.tools.terminal.terminal import create_terminal_session

command = (
    'python -c "import psutil; print(psutil.Process().nice())"'
    if platform.system() == "Windows"
    else "python -c 'import os; print(os.getpriority(os.PRIO_PROCESS, 0))'"
)

with tempfile.TemporaryDirectory() as work_dir:
    session = create_terminal_session(work_dir=work_dir)
    try:
        session.initialize()
        print(session.execute(TerminalAction(command=command)).text)
    finally:
        session.close()
Screenshots and Additional Context
  • Original product issue and benchmark: OpenHands/OpenHands#16720
  • SDK implementation PR: OpenHands/software-agent-sdk#4573

Contributor guide

Open the contributing guide

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.

Research direction

Start with uv sync --dev and reproduce_priority.py, then trace create_terminal_session and the terminal backends imported by the sample. Verify child priority behavior on Linux, macOS, and Windows, including restricted PATH and missing nice cases. Done means the three platform defaults work, none preserves the parent priority, and terminal startup remains valid in constrained environments.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, macos, python
Domain
cli, operating-systems, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.