Repository navigation
fix(tui): let gaia daemon start take the start lock on a cold start - #4261
Conversation
With no daemon running, the TUI could never start one: it held the start lock while running `gaia daemon start`, which waits on that same lock, so every cold start timed out after 30 s and blamed a stuck port or import. The TUI now holds the lock only to re-check the registry and refuse a wedged daemon, then releases it before spawning. The launcher serialises the actual start under the same lock, so concurrent callers still get one daemon. Fixes amd#4200
|
Verdict: Approve This fixes a real cold-start deadlock: the TUI was holding the daemon start lock while running the command that waits on that same lock, so with no daemon already running the TUI could never start one and failed after 30 seconds with a misleading "stuck binding a port" message. The new flow holds the lock only long enough to re-check for a running daemon, then hands it off to the launcher. Single-instance behaviour is preserved because the launcher still serialises the actual start. No blocking issues. I confirmed the fix and its test independently (below). One thing worth the author's attention: the new end-to-end test can only run on a machine that already has GAIA's Python environment, so in CI it will always skip — the unit test is what actually guards the regression there. Either give that test a lane with the Python env, or say in the CI workflow that it is a local-only check, so nobody later assumes CI covers it. Real-world evidenceNo The new unit test is a genuine regression guard — swapping in the pre-fix The new e2e test skips in an environment without GAIA's Python deps, which is what CI will hit: The TUI cold start itself (launching the TUI with no daemon and opening 🔍 Technical detailsDesign check. The premise holds end to end: 🟢 The new e2e test will never run in CI ( 🟢 Concurrent callers can burn 2× 🟢 The e2e assertion hardcodes two callers ( Strengths
|
With no daemon running, the TUI could never start one. It held the start lock while it ran
gaia daemon start, and that command waits on the same lock, so/agentsand daemon-agent preflight failed after 30 s with an error that blamed a stuck port or import. Now the TUI holds the lock only long enough to re-check for a running daemon and refuse to replace a wedged one. It releases the lock before spawning. The launcher still serialises the real start under that lock, so two TUIs starting at once still get one daemon.Test plan
go vet ./... && go test -race ./...intui/mainand passes with this change:go test ./internal/daemon -run StartOrAttachgaia daemon startwithGAIA_DAEMON_HOME=<tmp>. Both get the same daemon pid. Onmainit times out after 30 s.GAIA_E2E_PYTHON=<venv python> go test ./test -run ColdStart(it skips when no Python can import the daemon)pytest tests/unit -k daemon(551 passed)Fixes #4200