From 270b52573aa70eeca56b304518a1e99e8cd0b97a Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 11 Oct 2026 04:28:28 +0800 Subject: [PATCH] agent: stash.json is changed under a lock and written whole, and one that doesn't parse is kept aside, not written over as no stash stash.json holds every agent's config from before magpie wired it. stash, forget and unstash read it, changed it and wrote it back with os.WriteFile, with no lock, and a read that didn't parse came back empty. Two changes at once (Connect all, a gateway move setting each agent again) could leave the file half written, and the next change read that as no stash and wrote it back: every agent's originals gone, so Disconnect had nothing to put back. Now each change runs under stashMu and is written with edit.WriteAtomic; a file that doesn't parse is copied to stash.json.bad-