diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 4f97df9..ddff1c5 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -210,9 +210,18 @@ func loadSessionID(workspace string) string { } func saveSessionID(workspace, id string, host plugin.HostAPI) { + if id == "" { + return + } path := filepath.Join(workspace, SessionFile) - if err := os.WriteFile(path, []byte(id), 0o600); err != nil { + tmp := path + ".tmp" + if err := os.WriteFile(tmp, []byte(id), 0o600); err != nil { host.Log("warn", "gemini: save session id failed", + map[string]any{"err": err.Error(), "path": tmp}) + return + } + if err := os.Rename(tmp, path); err != nil { + host.Log("warn", "gemini: rename session id failed", map[string]any{"err": err.Error(), "path": path}) } }