Skip to content

Subagent can hang before launch when the interactive shell has background jobs #51

Description

@ferologics

Summary

The tmux-backed subagent tool can remain in running forever without ever starting the child Pi process when the user's interactive shell has a background job.

I hit this consistently with Fish and the Hydro prompt, which starts an asynchronous git-status job from its fish_prompt handler. The trigger is shell-specific, but the underlying launch race is general: the extension creates an interactive shell and immediately types an exec ... command into it.

What happens

  1. tmux new-session starts the user's interactive shell.

  2. Hydro starts an asynchronous prompt job.

  3. The extension uses send-keys to submit exec env ... pi ....

  4. Fish refuses the first exec while a background job exists and prints:

    A second attempt to exit will terminate them.
    Use 'disown PID' to remove jobs from the list without terminating them.
    
  5. Fish returns to its prompt, so the pane remains alive, but child Pi never starts and never writes result.json.

  6. The parent polling loop sees neither a result nor a dead pane and waits indefinitely.

The failed run directories contain task.md and an empty session/ directory, with no result.json, confirming that this happens before child Pi starts.

Minimal reproduction

The same behavior can be reproduced without Pi by creating a detached tmux session under Fish/Hydro, then immediately using send-keys to submit an exec command. The command is refused and its marker file is not created. Repeating the command a second time succeeds, matching Fish's warning.

Proposed fix

Launch the pane command directly after setting remain-on-exit, rather than injecting it into an interactive shell:

tmux respawn-pane -k -c <cwd> -t <target> <child-command>

This removes the interactive-shell startup race while preserving attachability, remain-on-exit, and dead-pane detection. I have a small tested patch and will open a PR referencing this issue.

Environment

  • Pi 0.83.0
  • tmux 3.6b
  • Fish 4.0.2
  • Hydro prompt
  • macOS
  • agent-stuff commit d265b8e

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions