Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 26 additions & 30 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,30 @@ func (a *App) NewSession() {
// Clear first message so it won't be re-sent on re-init
a.firstMessage = nil
a.firstMessageAttach = ""

// Re-emit startup info so the sidebar shows agent/tools info in the new session
a.reEmitStartupInfo(context.Background())
}

// reEmitStartupInfo resets and re-emits startup info (agent, team, tools)
// through the events channel so the sidebar updates.
func (a *App) reEmitStartupInfo(ctx context.Context) {
a.runtime.ResetStartupInfo()
go func() {
startupEvents := make(chan runtime.Event, 10)
go func() {
defer close(startupEvents)
a.runtime.EmitStartupInfo(ctx, a.session, startupEvents)
}()
for event := range startupEvents {
select {
case a.events <- event:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM SEVERITY: Silent event drops without cancellation fallback

The select statement at line 586 has a default case that silently drops events when a.events is full, but lacks the ctx.Done() case that was present in the original code.

Original code (lines 698, 856):

select {
case a.events <- event:
case <-ctx.Done():
    return
}

New code (line 586):

select {
case a.events <- event:
default:
}

Impact:
Without the ctx.Done() case, if the goroutine is blocked or slow, there's no way to interrupt it during app shutdown or session replacement. This makes the pattern less robust than the original implementation.

Recommendation:
Add context cancellation to the select statement (see the recommendation in the previous comment for the complete fix).

case <-ctx.Done():
return
default:
}
}
}()
}

func (a *App) Session() *session.Session {
Expand Down Expand Up @@ -672,21 +696,7 @@ func (a *App) SetCurrentAgentModel(ctx context.Context, modelRef string) error {
}

// Re-emit startup info so the sidebar updates with the new model
a.runtime.ResetStartupInfo()
go func() {
startupEvents := make(chan runtime.Event, 10)
go func() {
defer close(startupEvents)
a.runtime.EmitStartupInfo(ctx, a.session, startupEvents)
}()
for event := range startupEvents {
select {
case a.events <- event:
case <-ctx.Done():
return
}
}
}()
a.reEmitStartupInfo(ctx)

return nil
}
Expand Down Expand Up @@ -846,21 +856,7 @@ func (a *App) ReplaceSession(ctx context.Context, sess *session.Session) {
a.applySessionModelOverrides(ctx, sess)

// Reset and re-emit startup info so the sidebar shows agent/tools info
a.runtime.ResetStartupInfo()
go func() {
startupEvents := make(chan runtime.Event, 10)
go func() {
defer close(startupEvents)
a.runtime.EmitStartupInfo(ctx, a.session, startupEvents)
}()
for event := range startupEvents {
select {
case a.events <- event:
case <-ctx.Done():
return
}
}
}()
a.reEmitStartupInfo(ctx)
}

// applySessionModelOverrides applies any stored model overrides from a loaded session.
Expand Down
Loading