Skip to content

fix(delegation): preserve child workspace hints and queue busy input while subagents run - #5501

Closed
MestreY0d4-Uninter wants to merge 1 commit into
NousResearch:mainfrom
MestreY0d4-Uninter:work/delegation-clean-validate
Closed

fix(delegation): preserve child workspace hints and queue busy input while subagents run#5501
MestreY0d4-Uninter wants to merge 1 commit into
NousResearch:mainfrom
MestreY0d4-Uninter:work/delegation-clean-validate

Conversation

@MestreY0d4-Uninter

@MestreY0d4-Uninter MestreY0d4-Uninter commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • inject a concrete local workspace hint into delegated child prompts when Hermes knows the parent workspace path
  • explicitly steer child agents away from guessing container-style paths like /workspace/... for local repo tasks
  • queue busy input instead of interrupting when delegated child agents are still active in the CLI

Problem

A real delegated batch hit two separate failure modes at once:

  1. A child agent guessed an invalid local workdir (/workspace/hermes-agent) and immediately failed terminal calls on the local backend.
  2. While other children were still running, a follow-up user message triggered the parent interrupt path, which propagated to active children and discarded in-flight delegated work.

These are independent failures, so fixing only one still leaves the delegation flow fragile.

Root cause

1. Missing explicit workspace hint for child agents

Repo-centric child tasks had enough context to know they should inspect a repository, but not enough to know the exact local path. In that situation, the child could guess a container-style path and emit invalid terminal tool calls.

2. CLI interrupt policy was too aggressive during active delegation

display.busy_input_mode: interrupt is reasonable for a single active agent, but when delegated child agents are still running it is too destructive. Interrupting the parent propagates directly to active children, which turns an ordinary follow-up message into delegated work loss.

What changed

Delegation workspace hinting

  • extended tools/delegate_tool.py:_build_child_system_prompt() with an optional workspace_path
  • added explicit prompt guidance telling child agents not to assume /workspace/... unless that path is explicitly provided
  • added _resolve_workspace_hint(parent_agent) to derive a best-effort absolute local path from the parent runtime (TERMINAL_CWD, subdirectory hints, or parent cwd fields)
  • _build_child_agent() now injects that workspace hint into the child prompt when available

Busy-input handling during active child runs

  • added HermesCLI._should_queue_busy_input()
  • queue mode still always queues
  • interrupt mode now also queues when delegated child agents are active
  • applied the guard in both:
    • busy Enter-path input handling
    • the interrupt-monitor loop inside HermesCLI.chat()

This preserves the normal interrupt behavior when no children are active, while protecting active delegated work from being aborted by a routine follow-up message.

Files changed

  • tools/delegate_tool.py
  • cli.py
  • tests/tools/test_delegate.py
  • tests/test_cli_init.py

Validation

Focused tests on the patched checkout

  • uv run pytest tests/tools/test_delegate.py -q -o addopts=''
  • uv run pytest tests/test_cli_init.py -q -o addopts=''
  • uv run pytest tests/test_real_interrupt_subagent.py -q -o addopts=''

Focused tests on a clean worktree from latest origin/main

Applied the patch on top of a clean worktree created from the latest upstream main, then ran:

  • uv run pytest tests/tools/test_delegate.py -q -o addopts=''
  • uv run pytest tests/test_cli_init.py -q -o addopts=''
  • uv run pytest tests/test_real_interrupt_subagent.py -q -o addopts=''

Additional runtime smoke

Ran a small runtime harness against the clean worktree to verify the intended CLI behavior:

  • with active child agents, a second message was queued and interrupt() was not called
  • without active child agents, the same second message still followed the normal interrupt path

Why this shape

This keeps the change small and local:

  • prompt shaping solves the invalid guessed workdir case without inventing new delegation API surface
  • CLI queueing only activates for the risky case (active child agents), so the existing interrupt UX remains intact elsewhere

@MestreY0d4-Uninter
MestreY0d4-Uninter force-pushed the work/delegation-clean-validate branch from 668f014 to e68c7b0 Compare April 6, 2026 17:03
@MestreY0d4-Uninter
MestreY0d4-Uninter marked this pull request as ready for review April 6, 2026 17:46
teknium1 pushed a commit that referenced this pull request Apr 7, 2026
Selectively cherry-picked from PR #5501 by MestreY0d4-Uninter.

- Add _resolve_workspace_hint() to detect parent's working directory
- Inject WORKSPACE PATH into child system prompts
- Add rule: never assume /workspace/ container paths
- Excludes the cli.py queue-busy-input changes from the original PR
teknium1 pushed a commit that referenced this pull request Apr 7, 2026
Selectively cherry-picked from PR #5501 by MestreY0d4-Uninter.

- Add _resolve_workspace_hint() to detect parent's working directory
- Inject WORKSPACE PATH into child system prompts
- Add rule: never assume /workspace/ container paths
- Excludes the cli.py queue-busy-input changes from the original PR
@teknium1

teknium1 commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Partially merged via PR #5748 — the workspace path hints from delegate_tool.py were cherry-picked with authorship preserved. The cli.py queue-busy-input changes were excluded. Thanks @MestreY0d4-Uninter!

Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
Selectively cherry-picked from PR NousResearch#5501 by MestreY0d4-Uninter.

- Add _resolve_workspace_hint() to detect parent's working directory
- Inject WORKSPACE PATH into child system prompts
- Add rule: never assume /workspace/ container paths
- Excludes the cli.py queue-busy-input changes from the original PR
@MestreY0d4-Uninter
MestreY0d4-Uninter deleted the work/delegation-clean-validate branch April 27, 2026 01:39
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
Selectively cherry-picked from PR NousResearch#5501 by MestreY0d4-Uninter.

- Add _resolve_workspace_hint() to detect parent's working directory
- Inject WORKSPACE PATH into child system prompts
- Add rule: never assume /workspace/ container paths
- Excludes the cli.py queue-busy-input changes from the original PR
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
Selectively cherry-picked from PR NousResearch#5501 by MestreY0d4-Uninter.

- Add _resolve_workspace_hint() to detect parent's working directory
- Inject WORKSPACE PATH into child system prompts
- Add rule: never assume /workspace/ container paths
- Excludes the cli.py queue-busy-input changes from the original PR
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Selectively cherry-picked from PR NousResearch#5501 by MestreY0d4-Uninter.

- Add _resolve_workspace_hint() to detect parent's working directory
- Inject WORKSPACE PATH into child system prompts
- Add rule: never assume /workspace/ container paths
- Excludes the cli.py queue-busy-input changes from the original PR
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Selectively cherry-picked from PR NousResearch#5501 by MestreY0d4-Uninter.

- Add _resolve_workspace_hint() to detect parent's working directory
- Inject WORKSPACE PATH into child system prompts
- Add rule: never assume /workspace/ container paths
- Excludes the cli.py queue-busy-input changes from the original PR
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.

2 participants