You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
on_user_input hook fires on every stream teardown, not just real elicitation (false 'needs input' notifications for background agents) #4004
area/agentFor work that has to do with the general agent loop/agentic features of the apparea/runtimeRuntime engine, agent loop execution, tool dispatch, loop detection
The on_user_input hook — surfaced to users as a "needs input" notification — fires unconditionally whenever any agent stream stops, including streams that completed normally with zero questions. This makes the notification unreliable for background agent tasks: a run_background_agent sub-task that finishes cleanly triggers the exact same "needs input" alert as one that is genuinely blocked waiting on the user.
Root cause
executeOnUserInputHooks (pkg/runtime/hooks.go:570-583) is invoked from four call sites:
toolexec/dispatcher.go:810 — a real tool-confirmation prompt (legitimate)
elicitation.go:489 — a real elicitation/question (legitimate)
loop_steps.go:70 — max iterations reached (arguably legitimate — agent is stuck)
loop.go:216, inside finalizeEventChannel — called unconditionally at the end of every stream, success or failure, with no check for whether the stream actually ended in a pending-input state
Background sub-agent execution (run_background_agent, via agent_delegation.gorunCollecting at lines 346-396) calls RunStream, which tears down through the same finalizeEventChannel path. So a background agent that completes its task with no outstanding question still fires on_user_input.
Compounding this, the hook payload does not carry any field distinguishing why it fired — userconfig_test.go:1181 shows real hook configs mapping on_user_input straight to a fixed notification string (e.g. terminal-notifier -message "needs input"), with no way for the consumer to tell "genuinely waiting on you" apart from "a stream just ended."
Impact
Any client that surfaces on_user_input as a user-facing notification (e.g. background-agent-fanout systems built on docker-agent) gets a notification storm where most "needs input" alerts are false positives — a background task simply finishing. This defeats the purpose of the notification and trains users to ignore it.
Suggested fix
Gate the loop.go:216 call on the stream actually having ended in a pending-elicitation/pending-confirmation state, rather than firing on all teardown paths. Alternatively, include a reason/cause field in the hook payload (e.g. elicitation, tool_confirmation, max_iterations, stream_end) so consumers can filter to genuine input-needed events themselves.
Environment
Confirmed against docker-agent HEAD 8003b63
Reproduced via run_background_agent fan-out in a docker-agent-based agent system (multiple concurrent sub-agent tasks configured via background_agents toolset)
Factual additions from reviewing the current implementation:
finalizeEventChannel is deferred by RunStream and calls executeOnUserInputHooks(ctx, sess.ID, "stream stopped") during teardown. This is why normal completion—including runCollecting background sub-sessions—can reach the hook.
The hook payload currently exposes the session ID only; the call-site context/reason is not supplied to consumers. That prevents downstream hooks from distinguishing ordinary teardown from confirmation or elicitation without inferring it externally.
Small precision point: this is effectively every RunStream teardown with a current agent available; executeOnUserInputHooks returns when CurrentAgent() is absent.
It may also be worth explicitly defining the intended max_iterations behavior, since that is another existing on_user_input call site.
This supports either gating the teardown invocation on genuine pending input, or adding a reason/type to the emitted hook event.
area/agentFor work that has to do with the general agent loop/agentic features of the apparea/runtimeRuntime engine, agent loop execution, tool dispatch, loop detection
Activity
aheritier commentedon Aug 20, 2026
Factual additions from reviewing the current implementation:
finalizeEventChannelis deferred byRunStreamand callsexecuteOnUserInputHooks(ctx, sess.ID, "stream stopped")during teardown. This is why normal completion—includingrunCollectingbackground sub-sessions—can reach the hook.RunStreamteardown with a current agent available;executeOnUserInputHooksreturns whenCurrentAgent()is absent.max_iterationsbehavior, since that is another existingon_user_inputcall site.This supports either gating the teardown invocation on genuine pending input, or adding a reason/type to the emitted hook event.
cc @Sayt-0