Repository navigation
fix(cli): recover managed daemon requests after connection refusal - #375
Open
ashwinkrkumar wants to merge 1 commit into
Open
ashwinkrkumar wants to merge 1 commit into
ashwinkrkumar wants to merge 1 commit into
Conversation
|
@ashwinkrkumar is attempting to deploy a commit to the Kaelio Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
fix(cli): recover managed daemon requests after connection refusal
Summary
Long-running ktx processes (notably ktx mcp) cached the managed daemon's base URL for their lifetime.
After the daemon was replaced or stopped, every daemon-backed HTTP request (for example sql_execution read-only validation) failed with connect ECONNREFUSED 127.0.0.1: until restart.
Managed requests now re-resolve the daemon and retry once, only after a structured ECONNREFUSED on connect, which proves the request was never delivered.
Daemon startup is hardened: spawn errors and early exits are reported instead of crashing or waiting out the deadline, health probes are bounded, a version mismatch fails fast, and a failed or stale start never removes or stops a daemon recorded by another attempt.
Changes
managed-python-http.ts: per-daemon endpoint coordinator (single-flight acquisition with generations, shared across runners in a process), refused-connect classifier, single retry, stderr diagnostics.
managed-python-daemon.ts: child error/exit watch, bounded readiness probes, classified start errors, ownership-safe cleanup, and publish-or-yield before recording a new daemon.
Never retried: resets, timeouts, aborts, HTTP status errors, invalid JSON, permission errors, a denied runtime install, and semantic-query rejections.
Tests
Real-socket and unit coverage for stale endpoints, replacement reuse, same-port recovery, concurrent starts and recoveries, late failures, bounded failure with later recovery, error classification, readiness bounds, ownership, and diagnostics.
Integration test through createKtxMcpServerFactory with an in-memory MCP client: sql_execution recovers after daemon replacement, a persistent failure is reported as a tool fault, and sl_query stays on the subprocess path with its rejections still treated as expected errors.
Against the previous implementation, 28 of these tests fail; the production-wiring test returns connect ECONNREFUSED 127.0.0.1:.
Known Limits
No cross-process lock exists; separate processes starting at the same moment can still both spawn a daemon.
sl_query does not use daemon HTTP, so this does not explain every sl_query report in the issue. The managed embedding provider keeps a fixed daemon URL and is a likely source of the fetch failed variant (follow-up).
Refs #338