`jarvis start` / `jarvis gui` can never start the server on Windows: the daemon kills itself with `Another server is already registered`
Component: src/openjarvis/cli/daemon_cmd.py
Severity: jarvis start, jarvis gui, jarvis restart, jarvis status and jarvis stop are all broken on Windows + uv. Deterministic — not a race, not stale state.
Environment
| OS | Windows 11 Home Single Language, build 26200 |
| Python | 3.12.10 |
| uv | 0.12.19 |
| Version | jarvis, version 1.0.5.dev53+g8acafed |
What happens
> jarvis gui --no-browser
OpenJarvis server starting (PID 28532)
Requested URL: http://127.0.0.1:8000
Log: C:\Users\Sagar\.openjarvis\server.log
VITE v8.3.0 ready in 649 ms
➜ Local: http://127.0.0.1:5173/
OpenJarvis graphical mode is ready: http://127.0.0.1:5173Vite comes up and the CLI reports success, but port 8000 is never listening and the UI has no backend. ~/.openjarvis/server.log:
File "...\openjarvis\server\daemon.py", line 24, in startup
record_server_state(os.getpid(), host, port)
File "...\openjarvis\cli\daemon_cmd.py", line 157, in record_server_state
_write_pid(pid, host, port)
File "...\openjarvis\cli\daemon_cmd.py", line 97, in _write_pid
raise RuntimeError(f"Another server is already registered (PID {existing})")
RuntimeError: Another server is already registered (PID 28532)Note the PID in the error is the same one the launcher just printed. There is no other server. Deleting server.pid / server.json / server.lock and retrying from a completely clean state reproduces it identically, every time.
Root cause
start spawns the server and registers the PID that Popen reports:
cmd = [sys.executable, "-m", "openjarvis.cli", "serve"]
proc = subprocess.Popen(cmd, ...)
_write_pid(proc.pid, bind_host, bind_port, ready=False)The assumption is that proc.pid is the server's PID. On Windows with a uv-created venv it is not. uv's venv python.exe is its own launcher binary that re-execs the base interpreter in a separate process:
venv .venv/Scripts/python.exe : 274424 bytes <- uv launcher
base Python312/python.exe : 104952 bytes <- real CPython>>> p = subprocess.Popen([sys.executable, '-c', 'import os; print(os.getpid())'], ...)
Popen.pid=6448 child os.getpid()=25100 match=False
Popen.pid=29564 child os.getpid()=28500 match=False
Popen.pid=25284 child os.getpid()=31196 match=False3/3, and the launcher stays alive for the child's lifetime. So:
startwritesserver.pid = <launcher pid>,ready: false- uvicorn's startup hook calls
record_server_state(os.getpid())with the real PID _write_pidseesexisting != pidand_pid_alive(existing)— true, because the launcher is still running — and raises- the server dies during startup; the launcher reports success anyway
The existing guard for the reverse ordering doesn't help, because it requires the PIDs to be equal, which is precisely what never holds here:
if not ready and current.get("pid") == pid and current.get("ready", True):
returnKnock-on effects
Even setting the crash aside, recording the launcher's PID breaks the rest of the daemon commands: jarvis stop would kill the launcher and orphan the real server, and jarvis status reports on the wrong process.
Suggested fix
Two changes.
1. Treat a ready=False entry as a reservation, not an ownership claim. A server that has actually bound is authoritative and may take it over — by definition no server had bound when the reservation was written:
existing = _read_pid_file()
current = _read_state()
existing_ready = (
current.get("ready", True) if current.get("pid") == existing else True
)
if not ready:
# Launcher reserving the slot. `start` verified the slot was free before
# spawning, so a server that has since registered itself IS that child;
# it knows its real PID and bound address. Don't overwrite them.
if existing is not None and existing_ready and _pid_alive(existing):
return
elif existing is not None and not existing_ready:
# Real server taking over a launcher's reservation.
existing = None
if existing is not None and existing != pid and _pid_alive(existing):
raise RuntimeError(f"Another server is already registered (PID {existing})")Comparing state against a bare pid file with no matching server.json still counts as "ready", so an interrupted older writer is never silently taken over.
2. Have start adopt the PID the server reports for itself, rather than trusting proc.pid, and stop announcing success for a server that died during startup:
server_pid = proc.pid
deadline = time.monotonic() + _START_TIMEOUT
while time.monotonic() < deadline:
state = _read_state()
if state.get("ready", True) and state.get("pid"):
server_pid = state["pid"]
bind_host, bind_port = state["host"], state["port"]
break
if proc.poll() is not None:
clear_server_state(proc.pid)
raise click.ClickException(
f"Server exited with code {proc.returncode} during startup. "
f"See {_LOG_FILE} for the traceback."
)
time.sleep(0.2)This does make start block until the server is up, which is a behaviour change — but reporting a PID and URL for a process that has already crashed is worse.
Verification
Applied locally and exercised against the real code:
| Scenario | Result |
|---|---|
| Trampoline case: launcher reserves live PID, server registers a different PID | takeover succeeds, state holds the server's PID |
| Second real server tries to bind | still rejected |
Concurrent jarvis start |
still rejected |
| Server registers before the launcher records the spawn | real bound address preserved |
End to end after the patch:
> jarvis gui --no-browser
OpenJarvis server started (PID 21348)
URL: http://127.0.0.1:8000netstat shows PID 21348 owning port 8000 — matching server.pid — GET /health returns {"status":"ok"}, jarvis status correctly reports the running server (it never could before), and the chat UI completes round-trips against a local Ollama model.
Note on reproducing
This will not reproduce in an environment where the venv's python.exe is a real CPython copy — e.g. a python -m venv venv, or a container. It needs Windows and a uv-created venv, which is exactly what install.ps1 produces, so every Windows user following the documented install path hits it.
A fix is proposed in #1057.
Source: open-jarvis/OpenJarvis