Skip to content

fix(tools): signal done and auto-close idle interactive subagents - #1429

Merged
edenreich merged 4 commits into
mainfrom
fix/issue-1422
Sep 30, 2026
Merged

edenreich merged 4 commits into
mainfrom
fix/issue-1422

Conversation

@inference-gateway-maintainer

@inference-gateway-maintainer inference-gateway-maintainer Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #1422

Summary

Interactive subagents (each a live infer chat in a tmux pane) can now signal completion explicitly and their panes close themselves. The subagent chat marks its result-file write with done: true on its task turn (and on a failed terminal turn), and the parent monitor treats that as terminal: it delivers exactly one completion note, kills the pane, removes the temp files, and records the terminal status inline, then returns. A new tools.agent.idle_timeout (seconds, default 300, 0 disables) is the safety net that closes a pane whose subagent never reports done, and the old idle-by-stability fallback stops masquerading as a completion.

Changes

  • SubagentResultFile gains a Done field (written by the chat TUI's result-file writer on every fully completed turn and by the error path), so INFER_SUBAGENT_RESULT_FILE becomes the subagent's explicit terminal signal, not just a per-turn transcript.
  • PaneObservation gains Done, HarvestFailed and HarvestError, and NewPaneInspector populates them from the result file, so the monitor can decide on terminal turns without scraping the pane.
  • interactiveSubagentJob.Run now returns on the first terminal outcome: a done write (completed or failed, with or without assistant text), the pane closing, the idle timeout expiring, or monitor cancellation. On done/failed it emits exactly one [Subagent Completed: <label>] note with the harvested message and error, then tears the subagent down inline (kills the pane, removes the result and approval files, sets the tracker status completed/failed) instead of waiting for the retention-window reap, since the supervisor only calls Close on eviction or reap. A cancelled monitor runs the same teardown, so CloseSubagent and a supervisor stop leave no temp files behind. Reap's Close now just drops the tracker entry.
  • New config key tools.agent.idle_timeout on AgentToolConfig (default 300, 0 disables, env override INFER_TOOLS_AGENT_IDLE_TIMEOUT). Inactivity means no new result-file write, no change in the pane's screen tail, and no pending approval for the full window. A harvested turn, a screen change (including via SendSubagentInput), or an approval pauses the clock. On expiry the monitor emits one [Subagent Closed: <label>] note ("closed after 5m0s of inactivity without a done signal" plus the last harvested message) and tears the subagent down through the same teardown path.
  • The idle-by-stability fallback now warns as [Subagent Idle: <label>] (ended its turn without output or is waiting for input, and names the pending auto-close) instead of faking a [Subagent Completed]. Writes from an older binary without the done field keep the previous per-turn harvest behavior and are eventually closed by the timeout.
  • Removed AgentInteractiveConfig. Panes always open as a vertical split and always fall back to headless outside tmux. The subagent mode is a typed scheddomain.SubagentMode used by the config and SubagentState.
  • tools.agent.interactive.layout and tools.agent.interactive.fallback are removed and ignored if still set.
  • Updated the Agent and CloseSubagent tool descriptions (and the regenerated tool_definitions.golden.json) to match: panes close themselves on done/failure/idle timeout, CloseSubagent is only for stopping one early, a finished turn closes the pane even when it ends with a question, and SendSubagentInput only reaches a pane that is still working or stuck.
  • Docs: docs/configuration-reference.md (Tool Settings + Tools Configuration env vars) and docs/subagents.md (new "Interactive Subagents" section).
  • Tests: failed turn without an answer closes with the error, a cancelled monitor removes the temp files, done-turn close (one note, result file removed, tracker completed), failed-turn close (error in note, tracker failed), idle-timeout close (warning then close note), close note carrying the last harvested message, approval pausing the clock, screen activity pausing the clock, config wiring including the 0 disable, plus updated idle-fallback and monitor tests.

Downstream impact

Interactive subagents had no way to say their task finished, so the monitor reported every completed turn as a completion, left the pane open at the prompt, and the main agent had to guess when to close them.

The subagent chat now marks its result-file write done on its task turn (and on a failed terminal turn). The monitor treats a fresh done write as terminal: it emits exactly one completion note with any error, kills the pane, removes the temp files and records the terminal status inline, then returns.

A new tools.agent.interactive.idle_timeout (seconds, default 300, 0 disables) closes a pane that never reports done after inactivity - no harvested turn, no screen change, no pending approval - with one close note carrying the last harvested message. The old idle-by-stability fallback no longer masquerades as a completion and warns as [Subagent Idle] with the pending auto-close instead.
…idle timeout config

A failed first request writes a done result with no assistant text. The monitor only checked done behind a non-empty answer, so the error was dropped and the pane waited for the idle timeout. Done is now checked first.

A cancelled monitor now tears down too, so the result and approval files no longer leak when CloseSubagent or a supervisor stop winds the job.

The tools.agent.interactive block is gone. Panes always open as a vertical split and always fall back to headless outside tmux, which removes the layout and fallback keys. The timeout is now tools.agent.idle_timeout. The subagent mode is a typed SubagentMode instead of a commented string.

The monitor tests use a blank pane id so teardown never reaches the host tmux.
@edenreich
edenreich merged commit 006be00 into main Sep 30, 2026
12 checks passed
@edenreich
edenreich deleted the fix/issue-1422 branch September 30, 2026 11:40
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.220.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Interactive subagents never signal done - emit a done event and auto-close idle panes after a configurable timeout

1 participant