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:
@@ -293,9 +293,18 @@ func loadSessionID(workspace string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func saveSessionID(workspace, id string, host plugin.HostAPI) {
|
func saveSessionID(workspace, id string, host plugin.HostAPI) {
|
||||||
|
if id == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
path := filepath.Join(workspace, SessionFile)
|
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",
|
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})
|
map[string]any{"err": err.Error(), "path": path})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user