Skip to content

Commit 2ef154a

Browse files
committed
Fix TUI stuck in Working state after failed sub-agent transfer_task
When a child stream emitted an ErrorEvent, runSubSessionForwarding returned immediately without reading remaining events. This caused StreamStoppedEvent to never reach the TUI, leaking the streamDepth counter and leaving the UI permanently stuck in the Working state. Drain all remaining child events (including StreamStoppedEvent) before returning on error, keeping streamDepth balanced. Fixes #2255 Assisted-By: docker-agent
1 parent 2021b77 commit 2ef154a

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ require (
185185
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
186186
github.com/opencontainers/go-digest v1.0.0 // indirect
187187
github.com/opencontainers/image-spec v1.1.1 // indirect
188-
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
188+
github.com/patrickmn/go-cache v2.1.0+incompatible
189189
github.com/perimeterx/marshmallow v1.1.5 // indirect
190190
github.com/pjbgf/sha1cd v0.3.2 // indirect
191191
github.com/pmezard/go-difflib v1.0.0 // indirect

pkg/runtime/agent_delegation.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@ func newSubSession(parent *session.Session, cfg SubSessionConfig, childAgent *ag
125125
// This is the "interactive" path used by transfer_task where the parent agent
126126
// loop is blocked while the child executes.
127127
func (r *LocalRuntime) runSubSessionForwarding(ctx context.Context, parent, child *session.Session, span trace.Span, evts chan Event, callerAgent string) (*tools.ToolCallResult, error) {
128-
for event := range r.RunStream(ctx, child) {
128+
childEvents := r.RunStream(ctx, child)
129+
for event := range childEvents {
129130
evts <- event
130131
if errEvent, ok := event.(*ErrorEvent); ok {
132+
// Drain remaining events (including StreamStoppedEvent) so the
133+
// TUI's streamDepth counter stays balanced.
134+
for remaining := range childEvents {
135+
evts <- remaining
136+
}
131137
span.RecordError(fmt.Errorf("%s", errEvent.Error))
132138
span.SetStatus(codes.Error, "sub-session error")
133139
return nil, fmt.Errorf("%s", errEvent.Error)

0 commit comments

Comments
 (0)