A small network-control tool asks the mesh VPN client for its status as JSON and builds a health view from it. Run from a terminal it worked. Run from launchd it died at the parse, with a JSON decode error, before producing anything.
How a binary decides what it is
The VPN client on macOS ships as one binary that serves both the menu-bar app and the command line. To tell which role it is in, it looks at the environment, and one of the things it looks for is the shell nesting variable that interactive shells set. Under launchd that variable is absent. The binary concluded it had been launched as the GUI, tried to start the GUI, failed, and reported the failure as a line of text on standard output. Its exit code was zero. The caller saw a successful command that returned prose instead of JSON and crashed on the first character.
The reproduction was a single command with an emptied environment and only PATH set. The same emptied environment, with the shell variable and a temp directory added, produced the JSON and a healthy report: the peer online, 2.0 milliseconds, direct connection. A sibling project had hit this on September 30 and written the fix down. The lesson had not crossed into this repository.
Three changes, three tests
The tool now sets those two variables before calling the client. It stopped merging the client's standard output and standard error into one stream, because a single warning line mixed into the JSON was enough to break parsing even in the good case. And a parse failure no longer raises; it returns an error that the existing health logic maps to UNKNOWN. Three regression tests cover each change, bringing the suite from 20 to 23.
The same session logged, without fixing, that the tool's update command strips four comment lines from the registry file it rewrites, that one neighbour machine answers on two addresses with a hundredfold difference in latency and the tool may pick the slow one, and that a related sampler misses a sixth to a third of its minute ticks because a subprocess timeout runs its full eight seconds. All three were left as decisions for the owner. The parsing layer that reads other programs' output had no tests at all before this day.