Expand description
Headless mode: srv started directly — a container entrypoint, a server, CI — with no launcher or desktop host. docs/specs/SPEC_SRV_HEADLESS_MODE_2026_09_26.md.
Normally the launcher prepares srv’s world before spawning it: the data-path
env (DataPaths::to_env_vars), a per-launch auth key, and a stdin pipe and
parent process whose end means “shut down”. Headless srv does that itself:
- resolves and exports the data-path env when it isn’t already set;
- takes srv’s data-dir lock early (the same lock every srv takes), so no two servers — headless or launcher-started — share a set of databases;
- takes its auth key from
AGENTMUX_AUTH_KEY,--auth-key-file, or generates one and writes it to<data dir>/srv-auth-key(0600) — the key is never printed, only the file’s path; - keeps secrets in owner-only files under the shared dir instead of the OS
keychain, which a container usually doesn’t have (
--secret-store keychainto use the keychain anyway); - joins the LAN and the cloud relay as the desktop app does, on the same settings and the same checks:
network:lan_discovery(off until the person turns it on) adds the LAN listeners and the mDNS advertisement, and the relay connects once the channel has its own sign-in; - is not tied to stdin or a parent process (
mainskips those watchers); SIGINT/SIGTERM still shut it down.
Its startup listeners are loopback (--web-port / --ws-port fix the ports), and the web UI is
served there only. Another AgentMux reaches it over the LAN or the relay the way it reaches a desktop
one: through the LAN listeners the supervisor adds on those ports when network:lan_discovery is on,
behind the LAN key and the pins. A browser on another machine is a reverse proxy’s job, not srv’s. For a
client behind such a proxy, --frontend-dir serves the built frontend and
--allowed-origin names the proxy’s origin for CORS and the /ws check.
Structs§
Enums§
- Listener
- Which startup listener a bind address is for.
Constants§
- ALLOWED_
ORIGIN_ ENV - The environment variable a launcher that starts srv per run gives its one allowed origin in (a hosted
workspace is served at a host of its own), as
--allowed-originwould. - AUTH_
KEY_ FILE_ NAME - File name of the generated auth key, beside the databases.
- MIN_
PROVIDED_ 🔒KEY_ CHARS - The fewest characters a key srv did not generate may have when srv serves its own UI. The
sign-in’s proof (
/auth/hello) is a MAC under the key over values anyone can send, so a short key could be guessed offline from it; a generated key is 64 characters.
Statics§
- ACTIVE 🔒
- Set once
prepare_envsucceeded: this process is the headless server. - DATA_
DIR 🔒 - The directory srv keeps its databases in (
--wavedata, else the resolved data dir), set once headless started. - KEY_
FILE 🔒 - The file the key was read from or written to, when it came from a file (not the environment).
- PORTS 🔒
--web-port/--ws-port, held in-process (never in the env, so a launcher-spawned srv or an agent can’t inherit them — ReAgent P1 on #3893).- SESSION_
BINDING 🔒 - What the file of kept browser sessions is bound to: nothing for a key srv generated (new at every start), the key itself for one the person provided.
- WEB 🔒
--frontend-dir/--allowed-origin, held in-process like the ports.
Functions§
- active
- Is this process running headless (after
prepare_env)? - bind_
addr_ 🔒with - bind_
exclusive 🔒 - Bind a listener for this server’s own use of its address. Windows lets programs share an address when they ask to
(
SO_REUSEADDR), and a program that did could then receive connections meant for this server, the sign-in among them; withSO_EXCLUSIVEADDRUSEthe address is this server’s alone and any other bind of it is refused, whatever it asks for. Elsewhere the system already refuses a second bind. - bind_
exclusive_ 🔒to - check_
env_ 🔒key - The key from the environment, when there is one, held to the floor.
- check_
key_ 🔒floor - data_
dir - The data directory this headless srv uses (the one its databases and key file are in), when headless.
- effective_
data_ 🔒dir - The directory srv will open its databases in:
--wavedataif given (the same precedenceConfig::from_env_and_argsapplies), elseresolved. - env_key 🔒
AGENTMUX_AUTH_KEY, as the launcher or the operator gave it (stashed at start, or still in the environment).- frontend_
dir - The directory
--frontend-dirnamed, when headless and given. - is_
extra_ allowed_ origin - Is
originone--allowed-originnamed? Always false for a srv that isn’t headless. - key_
file_ path - Where this user’s headless srv keeps its generated key:
<data dir>/srv-auth-key, with the data dir resolved the wayprepare_envdoes. - local_
sign_ in - Does this headless srv serve its own UI, so a browser signs in to it? (
--frontend-dir.) - normalize_
origin 🔒 - An origin as browsers send it, via the WHATWG URL parser browsers use:
http or https, a host, an optional port — no path, user, query or
fragment. Serialized the way
Originis: lowercase, IDNA hosts in punycode, canonical IPv4/IPv6, and no default port, so every spelling of one origin compares equal (Codex P2s on #3900). A trailing/is fine. - normalize_
public_ 🔒origin - The one origin a loopback sign-in accepts besides srv’s own:
http://127.0.0.1:<port>, the other end of a tunnel. Never a real host name,localhost, another address orhttps: a browser on a non-loopback origin needs a design of its own (SPEC_HEADLESS_SERVER_PACKAGE_AND_LOCAL_WEB_UI §3). - origin_
in 🔒 - per_
run_ 🔒origin - The origins to allow once
AGENTMUX_ALLOWED_ORIGINis taken into account. Unset or empty:--allowed-originas given. Set: exactly that one origin, and nothing else (so a request from any other origin, including one an earlier launch allowed, is refused). It must be onehttpsorigin (a host, an optional port, no path, no wildcard, no list), and a--allowed-origingiven too must name the same origin: srv refuses to start on a launch whose two forms disagree, rather than pick one. - port_
file_ 🔒path - The file that holds a headless srv’s web port, beside its key file:
<key file>.port. One name per key file, so the port is read for the server that key belongs to. - prepare_
env - Prepare the environment the launcher would normally provide. Runs before
logging is initialized, so problems are returned for
mainto print. Returns the path the auth key was written to, when it generated one. - public_
origin --public-origin, when given.- publish_
port 🔒 - Write the web port beside the key file (owner-only), so
agentmux-srv openfinds this server without being told the port. Only a headless srv that serves its own UI and whose key came from a file. The file is replaced at every start and removed at a clean exit; after a crash it can name a port nobody listens on, or one another program now holds, whichopenmeets with its proof of the key and refuses. - read_
key_ 🔒file - Read a key from a file the operator provided; surrounding whitespace is ignored.
- read_
port_ 🔒file - The web port the server that owns
key_filewrote beside it. - read_
provided_ 🔒key_ file - A key file the operator provided, held to the floor.
- requested
- Is this the headless server starting (
--headlessorAGENTMUX_HEADLESS=1)? Never for a subcommand such asmigrate: it needs none of the headless setup, and its lock would refuse amigrate --verifyrun beside a running headless server (ReAgent P1 on #3893). - requested_
from 🔒 - session_
file 🔒 - Where the browser sessions are kept across a restart (the data root’s
sessions.bin) and what the file is bound to. Only a headless srv that serves its own UI. - startup_
bind_ addr - The address a startup listener binds:
STARTUP_BIND_ADDR(loopback, OS-chosen port) — or, headless only, the same loopback host with the port--web-port/--ws-portgave. A non-headless srv always gets the default. - web_
options 🔒 - withdraw_
port_ 🔒file - Remove the port file at a clean exit.
- write_
generated_ 🔒key - Generate a fresh key and write it to
<dir>/srv-auth-key, readable by the owner only. A new key every start, like a launcher-spawned srv.