fixed session manager

This commit is contained in:
2026-06-05 16:03:42 +02:00
parent 84de557052
commit 706f064b8b
4 changed files with 173 additions and 31 deletions

View File

@ -130,19 +130,33 @@ func (m *Manager) Scrollback(id string) ([]byte, error) {
}
func (m *Manager) DeleteSession(ctx context.Context, id string) error {
runtime, err := m.runtimeByID(id)
if err != nil {
return err
m.mu.RLock()
runtime, hasRuntime := m.runtimes[id]
m.mu.RUnlock()
var snapshot domain.Session
if hasRuntime {
snapshot = runtime.Snapshot()
} else {
stored, ok, err := m.store.Get(ctx, id)
if err != nil {
return err
}
if !ok {
return ErrSessionNotFound
}
snapshot = stored
}
snapshot := runtime.Snapshot()
if snapshot.Status == domain.SessionStatusRunning {
return ErrSessionRunning
}
m.mu.Lock()
delete(m.runtimes, id)
m.mu.Unlock()
if hasRuntime {
m.mu.Lock()
delete(m.runtimes, id)
m.mu.Unlock()
}
return m.store.Delete(ctx, id)
}