Skip to content

fix(terminal): lower agent process priority - #4573

Draft
primorLee wants to merge 2 commits into
OpenHands:mainfrom
primorLee:fix/lower-terminal-process-priority
Draft

fix(terminal): lower agent process priority#4573
primorLee wants to merge 2 commits into
OpenHands:mainfrom
primorLee:fix/lower-terminal-process-priority

Conversation

@primorLee

@primorLee primorLee commented Aug 21, 2026

Copy link
Copy Markdown

HUMAN:


AGENT:

Why

CPU-heavy agent commands currently inherit the agent-server's priority and can
starve the server. The original product report and benchmarks are documented at
OpenHands/OpenHands#16720. SDK issue #4575 contains a
minimal reproduction and testable acceptance criteria for this repository.

Summary

  • Prefix macOS terminal shells with /usr/sbin/taskpolicy -c utility and Linux
    terminal shells with an absolute nice -n 10 path, covering standalone tmux,
    pooled tmux, and the PTY subprocess backend.
  • Start the Windows PowerShell backend with BELOW_NORMAL_PRIORITY_CLASS and
    verify that a real child command inherits it.
  • Preserve startup on Linux systems without nice, and support
    OH_TERMINAL_PROCESS_PRIORITY=none for priority-sensitive benchmarks or
    development servers.
  • Add platform mapping, fallback, opt-out, and real child-process inheritance
    tests.

Issue Number

Fixes #4575

Original product issue: OpenHands/OpenHands#16720

How to Test

I completed the repository build steps on Windows (GNU Make is unavailable in
this checkout, so I ran the exact build target commands):

uv sync --dev
uv run pre-commit install

Windows end-to-end verification launches a real command through the persistent
PowerShell terminal; that child reads its own OS priority through psutil:

uv run pytest tests/tools/terminal/test_windows_terminal.py::test_terminal_process_runs_below_normal_priority -q --timeout=30
collected 1 item
tests\tools\terminal\test_windows_terminal.py . [100%]
1 passed in 1.88s

Platform policy, missing-nice, and opt-out coverage on the same checkout:

uv run pytest tests/tools/terminal/test_process_priority.py -q
tests\tools\terminal\test_process_priority.py .......ss [100%]
7 passed, 2 skipped in 0.06s

The two skips are the real Linux tmux/subprocess inheritance cases. They are
committed in this PR for the Ubuntu tools job; this machine has neither WSL nor
a Linux container runtime. The assertions use a unique output marker and compare
against the runner's actual niceness rather than assuming a zero baseline.

I also checked every changed POSIX file with Linux type stubs:

uv run pyright --pythonplatform Linux \
  openhands-tools/openhands/tools/terminal/terminal/process_priority.py \
  openhands-tools/openhands/tools/terminal/terminal/tmux_terminal.py \
  openhands-tools/openhands/tools/terminal/terminal/tmux_pane_pool.py \
  openhands-tools/openhands/tools/terminal/terminal/subprocess_terminal.py \
  tests/tools/terminal/test_process_priority.py \
  tests/tools/terminal/test_pool_integration.py
0 errors, 0 warnings, 0 informations

Pre-commit was run after each changed file. On this Windows host, its default
pyright invocation reports the existing POSIX-only pty, fcntl, and os.setsid
symbols as missing in subprocess_terminal.py; the explicit Linux-platform
pyright command above is clean. Ruff, pycodestyle, import rules, and tool
registration checks pass for all changed files.

I do not have macOS hardware in this environment. The Darwin argv path is covered
by the policy test, while the end-to-end taskpolicy -c utility measurement is
the one documented by the OpenHands member in the original product issue.

Video/Screenshots

Not applicable for a process-scheduling backend change; reproducible process-level
test output is included above.

Design Doc

Not included; the change is limited to one internal policy helper and four
existing process-spawn call sites.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • Scope is intentionally limited to the terminal tool. File editor helpers, MCP
    servers, and browser processes are unchanged.
  • Linux resolves nice before applying the terminal's possibly restricted
    PATH; if the utility is unavailable, terminal startup remains functional.
  • macOS uses the measured utility QoS class, not the much more restrictive
    background class.

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Agent terminal commands inherit server process priority

1 participant