Skip to content

on_user_input hook fires on every stream teardown, not just real elicitation (false 'needs input' notifications for background agents) #4004

Closed

Description

@steilerDev

Summary

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:

  1. toolexec/dispatcher.go:810 — a real tool-confirmation prompt (legitimate)
  2. elicitation.go:489 — a real elicitation/question (legitimate)
  3. loop_steps.go:70 — max iterations reached (arguably legitimate — agent is stuck)
  4. 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.go runCollecting 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)

Activity

  1. added
    area/runtime
    area/agent
    on Aug 20, 2026
  2. added theissue type on Aug 20, 2026
  3. aheritier commented on Aug 20, 2026

    @aheritier
    Collaborator

    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.

    cc @Sayt-0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/agentarea/runtime

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions