Skip to content

fix(cli): align divergent CLI/MCP paths with canonical resolvers#306

Open
andreybavt wants to merge 6 commits into
mainfrom
divergent-implementation-audit
Open

fix(cli): align divergent CLI/MCP paths with canonical resolvers#306
andreybavt wants to merge 6 commits into
mainfrom
divergent-implementation-audit

Conversation

@andreybavt

Copy link
Copy Markdown
Contributor

This branch audits divergent parallel implementations in the CLI, where behavior depended on which entry point a caller used rather than on its inputs. ktx sql and the MCP server now honor KTX_SQL_ANALYSIS_URL/KTX_DAEMON_URL, ktx connection test supports a local dbt source_dir, and ktx status checks now match the actual runtime resolvers. Looker client_secret_ref is resolved through the canonical config resolver instead of a forked path. Finally, createManagedPythonSemanticLayerComputePort is now synchronous and installs the managed Python runtime lazily on the first semantic-layer call, so an MCP session that only searches never triggers an eager install at boot.

ktx ingest resolved the SQL-analysis port via resolveKtxCliSqlAnalysis,
which honors the external-daemon env overrides, but `ktx sql` and the MCP
server built their port by calling createManagedDaemonSqlAnalysisPort
directly. On a uv-less host with an external daemon and the override set,
ingest worked while `ktx sql` and MCP sql_execution ignored the override
and tried to install the managed Python runtime — contradicting the
documented contract and runtime-requirements, which already skip the
managed runtime when those vars are set.

Collapse the three call sites onto one env-override-aware resolver:
add externalDaemonSqlAnalysisBaseUrl + resolveSqlAnalysisPort in
managed-python-http.ts and route sql.ts, mcp-server-factory.ts, and
resolveKtxCliSqlAnalysis through it. createManagedDaemonSqlAnalysisPort
becomes @internal (test-only export).
Extract readGitRepoConnectionFields as the single reader of where the git-repo
context-source drivers store their fields (dbt's snake_case repo_url/source_dir,
lookml's camelCase repoUrl, metricflow's nested metricflow.*). `ktx connection
test` now routes through it and, when a dbt connection points at a local
source_dir, verifies the directory exists instead of running a remote repo
reachability check that can never apply.
Route status config references through resolveKtxConfigReference so file: keys
are read (not reported as ready by trusting the raw path), read git-repo
connection fields through the shared readGitRepoConnectionFields, and stop
reporting openai embeddings as ready from a bare OPENAI_API_KEY since
resolveLocalKtxEmbeddingConfig requires a resolved openai.api_key.
…esolver

The local Looker adapter understood only env: references, so a client_secret_ref
written by `ktx setup` as a file: secret silently failed to resolve. Route it
through resolveKtxConfigReference so file: and env: refs both work, matching the
other connector paths.
…r call

createManagedPythonSemanticLayerComputePort is now synchronous and resolves
the managed runtime lazily on the first query/validate/generate call, caching
the port on success. An MCP session that only searches never installs the
Python runtime at boot, avoiding the eager-install crash loop on uv-less hosts.
@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ktx-docs-site Ready Ready Preview, Comment Jun 18, 2026 12:23pm

Request Review

Reconciles this branch's audit fixes with main's independently-landed work
where they overlapped:

- MCP Python-runtime install: main's #297 (createLazyManagedPython-
  SemanticLayerComputePort + self-provisioned uv, shipped in 0.12.0)
  supersedes this branch's redundant 96fb94c. Adopted main's canonical lazy
  port; dropped the duplicate single-function lazy fix.
- mcp-server-factory.ts: kept main's lazy semantic-compute port AND this
  branch's resolveSqlAnalysisPort (honors KTX_SQL_ANALYSIS_URL/KTX_DAEMON_URL,
  a strict superset of main's createManagedDaemonSqlAnalysisPort).
- doctor.test.ts: configured embeddings.openai.api_key on the ready-path
  tests to match 7692d92's corrected status semantics (status no longer
  reports openai embeddings ready from a bare OPENAI_API_KEY env var).

Verified: type-check, build, default suite (3010 tests), connection/sl/
mcp-port excluded tests (67 tests), dead-code gate — all green.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.35714% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/cli/src/connection.ts 0.00% 17 Missing ⚠️
packages/cli/src/status-project.ts 66.66% 1 Missing and 3 partials ⚠️
...s/cli/src/context/project/git-connection-fields.ts 81.81% 1 Missing and 1 partial ⚠️
packages/cli/src/local-adapters.ts 33.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants