feat(terminal): add session grace expiry tests and improve detach logic (#14127)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
HynoR
2026-10-19 17:54:05 +08:00
committed by GitHub
co-authored by Cursor
parent c695a2a408
commit 04099ae2a2
4 changed files with 24 additions and 2 deletions
+11 -1
View File
@@ -314,7 +314,17 @@ func (s *Session) detach(a *attachment, clean, revalidate bool, cursor uint64) {
if !s.Persistent || revalidate {
timeout = revalidateGrace
}
s.grace = time.AfterFunc(timeout, s.Close)
// Stop cannot cancel a fired timer; a racing Attach clears s.grace.
var grace *time.Timer
grace = time.AfterFunc(timeout, func() {
s.mu.Lock()
expired := s.grace == grace
s.mu.Unlock()
if expired {
s.Close()
}
})
s.grace = grace
}
s.mu.Unlock()
if clean {