fix(runner): write thread id atomically (tmp+rename)

Aligns with anthropic-contractor: a crash mid-write leaves a stale
.plexum-codex-session.tmp instead of an empty real file that would
make the next turn start fresh and lose conversation thread.
This commit is contained in:
h z
2026-06-01 13:45:11 +01:00
parent 33de696653
commit e1c4add9fe

View File

@@ -293,9 +293,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", "codex: save session id failed",
map[string]any{"err": err.Error(), "path": tmp})
return
}
if err := os.Rename(tmp, path); err != nil {
host.Log("warn", "codex: rename session id failed",
map[string]any{"err": err.Error(), "path": path})
}
}