fix: unify session persistence to preserve name on restart

- flushSave and SaveSession now use PersistSession instead of
  agent.SaveFull, ensuring the multi-agent format with Name field
  is consistently written
- Rename now calls PersistSession immediately so renamed sessions
  survive server restart

The previous approach had two save formats (legacy single-agent via
agent.SaveFull, and new multi-agent via PersistSession) writing to
the same file. Since flushSave ran on every turn, it would overwrite
the Name field with the legacy format that didn't preserve it.
This commit is contained in:
Levi Neely 2026-08-04 14:11:14 +02:00
parent 5a9d605840
commit 3cfbd14203
2 changed files with 8 additions and 15 deletions

View File

@ -138,6 +138,9 @@ func Rename(oldName, newName string) error {
delete(sessions, oldName)
mu.Unlock()
// Persist immediately so the rename survives restart
PersistSession(newName)
pkgLog.Info("renamed session %s -> %s", oldName, newName)
PublishEvent("session."+sess.ID()+".rename", oldName+" "+newName)
return nil

View File

@ -361,26 +361,16 @@ func (a *Session) flushSave() {
if !dirty || a.id == "" || a.sessionsDir == "" {
return
}
path := a.activeSessionPath(a.id, ".json")
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
// Use PersistSession for consistent format (writes Name field correctly)
if err := PersistSession(a.Name()); err != nil {
a.log.Error("session save: %v", err)
return
}
if len(a.agents) > 0 {
ag := a.agents[0]
if err := ag.SaveFull(path, a.id, a.Name(), a.CWD(), a.remote); err != nil {
a.log.Error("session save: %v", err)
}
}
}
// SaveSession writes the current session state to the given path.
// Returns nil if there is no agent (empty session).
// SaveSession writes the current session state.
// The path argument is ignored; session is saved via PersistSession.
func (a *Session) SaveSession(path string) error {
if len(a.agents) > 0 {
return a.agents[0].SaveFull(path, a.id, a.Name(), a.CWD(), a.remote)
}
return nil
return PersistSession(a.Name())
}
// --- Identity accessors ---