Skip to content

Commit 0930416

Browse files
committed
fix(bootstrap): TUI race condition exits before agent fallback completes
The allDone check treated stream-based StatusError as terminal, causing the TUI to quit when other agents finished before a recovering agent could deliver its AgentResultMsg. Track ResultReceived explicitly so the TUI waits for every agent's final result.
1 parent 5521507 commit 0930416

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

internal/ui/bootstrap_tui.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ const (
2323
)
2424

2525
type AgentState struct {
26-
Name string
27-
Status AgentStatus
28-
Message string
29-
Result *core.Output
30-
Err error
31-
Spinner spinner.Model
32-
StartedAt time.Time
33-
LastTool string
34-
LastNode string
35-
LastEventAt time.Time
26+
Name string
27+
Status AgentStatus
28+
Message string
29+
Result *core.Output
30+
Err error
31+
Spinner spinner.Model
32+
StartedAt time.Time
33+
LastTool string
34+
LastNode string
35+
LastEventAt time.Time
36+
ResultReceived bool // true once AgentResultMsg has been processed
3637
}
3738

3839
type AgentResultMsg struct {
@@ -234,6 +235,7 @@ func (m BootstrapModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
234235
allDone := true
235236
for i, state := range m.Agents {
236237
if state.Name == msg.Name {
238+
state.ResultReceived = true
237239
// AgentResultMsg is the final result - it overrides any intermediate
238240
// errors captured during retry attempts. This fixes the bug where
239241
// retryable errors (like JSON parse errors) would mark the agent as
@@ -262,7 +264,12 @@ func (m BootstrapModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
262264
}
263265
m.Agents[i] = state
264266
}
265-
if m.Agents[i].Status == StatusRunning {
267+
// An agent is only "done" once its AgentResultMsg has arrived.
268+
// Stream-based EventAgentError can set StatusError prematurely
269+
// (e.g., ReAct max-step errors that the agent recovers from via
270+
// deterministic fallback). Without this check, the TUI quits
271+
// before the fallback completes on fast-finishing projects.
272+
if !m.Agents[i].ResultReceived {
266273
allDone = false
267274
}
268275
}

0 commit comments

Comments
 (0)