@doublemeat I suspect that the nitty gritty details need to be described.
1) "socket" in this context is a unix domain socket, somewhat like a TCP socket, but restricted to the same machine and appears in the filesystem namespace. But its not a plain file, its a communication endpoint.
2) When Geany is started from the command line with filenames it looks for a socket of an existing instance which it then uses to communicate the filenames from the command line so they open in the other instance. So the socket has to have a name that can be found, a unique temp file is no good [1]. So Geany looks in `~/.config/geany` for an object named `geany_socket_<hostname>_<display>` so it will only try to open files in an instance on this host and this display. If it finds such a file it uses it to send the filenames to open, and then it exits. So without the annoying test, your root instance would find a user instance socket and it would open the files in the user instance, which isn't of course what you want.
3) The config directory can be specified on the command line with `-c` and then it looks in that config directory for the socket. This is to ensure that the files are opened in an instance using the right configuration. The annoying test also to ensures this won't open files in the instance of another user that happens to be using this configuration directory already. This capability of having differing configurations is generally not supported by other simple editors.
4) And then (with or without -c) geany can be started with `-i` which will not look for the socket and will not create one, it is always an independent instance.
5) And finally, not only but also, the socket file can be specified with `--socket-file=` so it can be completely independent of selected config, username, host, whatever.
Since you are running from a script, using extra command line options should be no problem. Are you sure that you can't find a combination of options here that makes your root instance suitably separate from a preceding user instance? Using `--socket-file=/tmp/geany_root_socket` maybe?
Note also that Geany rolls its own here because of its unique requirements, its ability to work on windows as well, and its independence of the various incompatible session management mechanisms used by different distros.
[1] technically the socket is created in /tmp with a unique name, but a link with a known name pointing to the temporary is placed in the config dir. The link is what Geany looks for.