feat(server): a discovery file so the CLI can find the running server - #91
Merged
Conversation
One server per workspace writes its host/port/pid to server.json at the workspace root. serve refuses to start when a live server for the workspace already answers, so two processes cannot write the same project dbs. The file is a hint, never proof of liveness — a TCP connect is; a crash leaves a stale file that the next serve's liveness check discards. Foundation for routing 'claw run' through the server (TODO item 2).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The first slice of TODO item 2 (the CLI talks to the server, not to the database). Before the CLI can be made a thin client of the server, it needs to find a running server, and the workspace needs to stop two servers from writing the same project dbs at once.
ServerLocator(src/ServerLocator.php): records{host, port, pid}toserver.jsonat the workspace root, reads it back, and offersalive()— a TCP connect to the address.Server::run()records the address after startup and drops the file on a clean stop only.claw serverefuses to start when a live server for the same workspace already answers, with a message naming the address and pid.Why this shape
serve's liveness check, and overwritten by the next successful start./api/healthprobe. Discovery does not need one — forservethe liveness test is the TCP connect; for the futureclaw runcutover the real request is itself the liveness test.serveon the same port collide on the OS bind. The guard catches the commoner case (a secondservewhile one already runs) with a clear message instead of a rawEADDRINUSE.Failure modes handled
alive()fails, the record is ignored and replaced.clear()is additionally owner-checked by pid).serve --host 0.0.0.0) → recorded and probed as the loopback address a client can actually reach.Not in this PR
Routing
claw runthrough the server (POST/start+ streaming the trace to the console) is the next slice. This one only lands the discovery file and the duplicate-guard.Checks
composer qagreen locally — cs, PHPStan level 8, and Testo (445 tests). New tests intests/ServerLocatorTest.phpcover the record round-trip, the missing/malformed/wrong-type records, the owner-checked clear, and the connect-based liveness.