A missing PATH entry under launchd turned into "no saved password found"
MITM never came back after a reboot. The saved password was on disk and decrypted fine by hand. A LaunchAgent's PATH lacked /usr/sbin, a helper shelled out to ioreg, and the error surfaced as the wrong sentence entirely.
After a reboot, capture was off. The dashboard said:
MITM was enabled but no saved password found, skipping auto-startThe password was on disk. It decrypted correctly by hand. The sentence was wrong about the one fact it asserted — and because it was a plausible sentence, it sent everyone looking at the wrong thing.
The chain
The encryption key for the saved sudo password is derived from a machine identifier. Getting that identifier used node-machine-id, which on macOS shells out to ioreg.
ioreg lives in /usr/sbin.
A LaunchAgent does not inherit your shell's environment. This one's PATH was:
<node>/bin:/usr/local/bin:/usr/bin:/binNo /usr/sbin. Measured directly:
$ env -i PATH=<the plist's PATH> node -e 'machineIdSync()'
/bin/sh: ioreg: command not foundFrom there it degrades quietly, one honest-looking step at a time:
- The
ioregcall throws. - Key derivation catches it and falls back to hashing the salt alone — producing a different, valid-looking key.
- AES-GCM decrypts with the wrong key and rejects the authentication tag.
- The caller sees a failed decrypt and reports it as no password present.
Step 4 is where the truth is lost. "Could not decrypt" and "nothing is stored" are different facts with different fixes, and the second one is far more comforting, so that is the one that got printed.
Step 2 is where the bug actually is. A fallback that produces a different key rather than failing is not a fallback — it is a silent change of behaviour disguised as resilience. Every layer after it is working correctly on the wrong input.
Interactively, everything worked. Your shell has /usr/sbin, so ioreg runs, the real machine id comes back, the right key is derived, and the password opens. The bug exists only in the environment nobody has a terminal in.
The failure stacked with another one
MITM not auto-starting was the first bug. The second made it worse: the watchdog, finding no server running, stripped the DNS redirects it could no longer serve.
That is correct behaviour in isolation — it is the self-healing added after crashes stranded machines. But combined with a failed auto-start it means capture is not merely down after a reboot, it is actively torn down, so there is nothing half-working to notice. It is off, cleanly, until someone opens the dashboard and turns it on.
Two correct-looking behaviours composing into a silent regression is a recurring theme in this system.
The fix
The machine id now comes from a file the app already maintains at DATA_DIR/machine-id. That file exists for exactly this reason — its own helper documents it as guaranteeing that the CLI, server and middleware see the same value even when machineIdSync fails.
Reading a file needs no PATH. The entire class of failure disappears rather than being patched: no subprocess, no environment dependency, no difference between a login shell and a LaunchAgent.
Two details made it safe to change:
- Decryption tries every historical key. A password saved under the old derivation still opens, so nobody has to re-enter anything after upgrading. Changing a key derivation without this would have logged every existing user out of their own saved credential.
- The candidates are memoized. The old call ran on every decrypt attempt and printed
ioreg: command not found162 times in a single boot — which, notably, was visible the whole time in the logs and still did not lead anyone to the cause, because the headline error said something else.
What to take from it
Two things, and neither is about macOS.
A fallback that substitutes a different value is not error handling. If deriving a key can fail, the honest options are to fail loudly or to try a known alternative and say which one was used. Silently hashing something else produces a key that is wrong in a way no downstream layer can detect — it just looks like bad data.
An error message that states a fact should state a fact you verified. "No saved password found" was a conclusion inferred from a failed decrypt, not an observation of the filesystem. The file was right there. Checking whether it existed before claiming it did not would have turned a multi-step investigation into a one-line contradiction.
If MITM has not been coming back after reboots, this landed in 0.5.185.
Published by Kodelyth, the team that builds kRouter. Posts are drafted with AI assistance and reviewed by a person before they go out. kRouter is free and MIT licensed.
Install kRouterRelated posts
- Fix an errorOpenCode MissingSessionID: the x-opencode-session fixOpenCode Go now returns HTTP 400 MissingSessionID for any request without an x-opencode-session header. What changed, why proxies broke, and the fix.
- Fix an errorRequest failed (404): the endpoint the page had always calledA dashboard page posted to an API route that did not exist — not in a release, not in git history. It compiled, it rendered, it was linked from the nav, and it had never once worked.
- Fix an errorA 200 that is a retirement notice is not an answerA provider replying "that model is gone, use this other one" has every marker of success: HTTP 200, finish_reason stop, real text. It was billed, logged as fine, and shown to the user as the model's own words.
Relevant docs
- TroubleshootingFixes for common kRouter problems: banned or rate-limited accounts, OAuth sign-ins, MITM certificates, localhost and Cursor, Docker logins and the CLI.
- Error referenceWhat the common AI provider errors mean, why they happen, and how to get past them.
- Combos & fallbackPut several models behind one name. kRouter falls back from one to the next, rotates them, or asks a panel of models and merges the answers.