fix(cli): restart daemon when console requested host/port don't match - #11138
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Resolved Issues (from previous reviews)
What changed in this update
Files Reviewed (5 files)
Reviewed by claude-4.6-sonnet-20260217 · 1,048,861 tokens Review guidance: REVIEW.md from base branch |
b02dfd3 to
8609707
Compare
When `kilo console --port 4321` reuses an already-running daemon on a different port (e.g. 4097), the new options were silently ignored. Now `kilo console` checks if the running daemon matches the requested host/port, and restarts if they differ. The restart only occurs when explicit `--port` or `--hostname` options are provided via CLI, not when using default values.
8609707 to
63294a4
Compare
| } | ||
| } | ||
|
|
||
| async function port() { |
There was a problem hiding this comment.
WARNING: TOCTOU race — port() closes the server before the daemon binds it
The helper probes an OS-assigned free port by listening on port 0, then immediately closes the server and returns the port number. Between server.close() completing and the daemon calling bind(), another process (or another concurrent test) can grab that port. On a loaded CI host this is a low-probability but real flake source.
The port: 0 auto-assign path used elsewhere (e.g. lines 92, 111) avoids this entirely — the OS holds the binding until listen() succeeds. If the test genuinely needs to verify that the daemon binds a specific user-supplied port, consider passing port: 0 and then asserting result.state.port !== 0, or accept the small risk given the narrow test-only scope.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
…-on-port-mismatch fix(cli): restart daemon when console requested host/port don't match
Issue
Fixes #11137
Context
kilo consolewith explicit--portor--hostnameoptions silently reuses a running daemon on a different host/port, ignoring the user's request. Since the server binds once at startup, there is no way to change the bind address of a running process — a restart is required.Implementation
Extracted daemon startup logic into an exported
startDaemonhelper that checks whether the returned state is a reuse and whether it differs from the requested options. When a mismatch is detected andrestartOnMismatchis true, it logs a warning, callsDaemon.stop(), and restarts withDaemon.start(opts).The
restartOnMismatchflag is only enabled when explicit--portor--hostnameCLI arguments are detected inprocess.argv, preventing unnecessary restarts when the user runskilo consolewithout flags (which defaults to port0for auto-assignment).Also added tests to verify functionality in the future.
Key design decisions:
opts.port === 0(auto-port) to avoid restarts on default invocationsScreenshots / Video
How to Test
Manual/local verification
kilo console --port 4097starts daemon on 4097, thenkilo console --port 4321shows a warning and restarts on 4321kilo consolewithout flags reuses the existing daemon without restartingReviewer test steps
kilo daemon stopto ensure clean statekilo console --port 4097— confirm URL shows port 4097kilo console --port 4321— confirm a warning is printed, daemon restarts, and URL shows port 4321kilo console— confirm it reuses the daemon on port 4321 without restartingChecklist
Get in Touch
Discord: @IamCoder18