From 3cfbd14203848076ae405e42fb3c55e8103fd7fe Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Tue, 4 Aug 2026 14:11:14 +0200 Subject: [PATCH] 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. --- session/registry.go | 3 +++ session/session.go | 20 +++++--------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/session/registry.go b/session/registry.go index 3128b32..7ad63c9 100644 --- a/session/registry.go +++ b/session/registry.go @@ -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 diff --git a/session/session.go b/session/session.go index 60e650c..c27248c 100644 --- a/session/session.go +++ b/session/session.go @@ -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 ---