There it is. Here's the sequence:
- User edits session ID in config, saves → writes new ID to filesystem and localStorage
- User runs
machine info → machine tool reads the old session ID (which it generated earlier), writes it back to the file
- After
machine info completes, persistSessionId() reads the file (now containing the old ID again) and overwrites localStorage with the old value
The machine tool regenerates/writes its own session-id.yml on every run, overwriting what we put there. So persistSessionId then copies that old value back to localStorage, undoing the config save.
The fix: persistSessionId should not overwrite localStorage if the user has explicitly set a value via the config editor. But actually, the simpler fix is to just not persist back from the filesystem after the user has explicitly set one — or better yet, the issue is that we need the machine tool to use the ID we set, not generate its own.
Hmm, actually let me reconsider. The user said: "if I then reloaded the page and ran machine info again — now I get the new value." On reload, restoreSessionId writes the file from localStorage before any machine command runs, and the machine tool reads it. So the file write works, and the machine tool does respect the file.
The real problem: the first machine info (before config save) already generated a session ID and wrote it to the file. Then the config save writes the new ID to the file. Then machine info runs again — but the machine tool writes its already-loaded ID back to the file? Or maybe the machine tool doesn't re-read on each invocation because it's all in the same Python process?
Actually wait — the user explicitly said the machine tool literally reads the file each time. So if we wrote the new value, machine info should see it. Unless... persistSessionId runs after machine info and overwrites localStorage, but that shouldn't affect the filesystem file.
Let me reconsider: the user said machine info reports the old value right after config save. That means the file still has the old value at the time machine info reads it. Which means runtime.writeFile in the config save handler didn't actually update the file. Maybe the await isn't working as expected, or the write is failing silently.
Let me add visible logging to the save handler to confirm the write completed: