Skip to content

Commit 3f68a00

Browse files
authored
Merge pull request #3525 from docker/worktree-board-e24afe8043392316
fix: don't clobber attached runtime's cancel in RunSession/recallSession
2 parents 0b6f8e0 + c621e71 commit 3f68a00

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

pkg/server/session_manager.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,13 @@ func (sm *SessionManager) RunSession(ctx context.Context, sessionID, agentFilena
648648
cancel()
649649
return nil, ErrSessionBusy
650650
}
651-
runtimeSession.cancel = cancel
651+
// Track the current stream's cancel so DeleteSession aborts it — but only
652+
// for server-owned entries. Attached runtimes (done != nil) keep their
653+
// attach-lifetime cancel: DELETE must cancel the attach context, not the
654+
// in-flight stream, which WaitStopped waits on to end naturally.
655+
if runtimeSession.done == nil {
656+
runtimeSession.cancel = cancel
657+
}
652658

653659
// Apply the model override (if any) before persisting the user
654660
// messages so that an invalid ref does not leave an orphaned user
@@ -875,7 +881,11 @@ func (sm *SessionManager) recallSession(ctx context.Context, sessionID string, m
875881
return err
876882
}
877883
rt.session = sess
878-
rt.cancel = runCancel
884+
// Same rule as RunSession: never clobber an attached runtime's
885+
// attach-lifetime cancel with a per-stream cancel.
886+
if rt.done == nil {
887+
rt.cancel = runCancel
888+
}
879889
sm.mux.Unlock()
880890

881891
go func() {

0 commit comments

Comments
 (0)