fix(jac-gpt): don't crash startup when MCP tool categorization LLM call fails#666
Merged
Merged
Conversation
…ll fails jac-gpt made a blocking `by llm()` call (categorized_mcp_tools) at glob-init to categorize MCP tools. After jaseci-labs/jaseci#7042 folded `jac mcp` into core, the MCP client now connects and discovers tools, activating this previously dormant call. When the LLM is unreachable or no API key is set (as in CI), the call raised and aborted module load, so the server never bound its port and startup hung. Build the cache defensively: - Load .env up front so credentials are available before any LLM call. - Wrap categorization in try/except and fall back to an empty cache; the MCP chat abilities already read it via .get(..., []), so empty is safe. - Initialize the cache after `llm` is configured so the intended model is used.
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.
Problem
The jaseci
test-pypi-buildCI job (Run tests for jaseci) has been red onmainsince jaseci-labs/jaseci#7042, failing at "Wait for jac-gpt server to be ready" (example run). The jac-gpt server never binds its port and the wait step times out.That job scaffolds jac-gpt from the published jacpack (generated from this
jac-gpt-fullstack/) and runsjac start main.jac.Root cause
services/jacServer.jacmade a blockingby llm()call (categorized_mcp_tools) at module / glob-init time to categorize the MCP tools, gated on the MCP client having discovered tools:This call was dormant until #7042: jac-gpt has no
jac-mcpdependency, so before the foldjac mcpwas an unknown command,McpClientgot 0 tools,available_mcp_tools_descriptionswas empty, and theelsebranch ran (no LLM call). #7042 madejac mcpa built-in command, so the client now connects, discovers 19 tools, and theby llm()call fires at startup.Two further problems made that call fragile:
load_dotenv()and beforeglob llm = Model(...), so it used the default model with credentials not yet loaded;The "missing credentials" error is not jaseci dropping the key: the jac-gpt CI step has no real LLM key, and byllm reads the key from the environment at call time. This is a jac-gpt startup-ordering / resilience bug that #7042 merely exposed.
Fix
.envup front (ownwith entry) so credentials are available before any LLM call.build_mcp_tools_cache()helper wrapped in try/except that falls back to the empty cache. The MCP chat abilities already read it via.get(..., []), so an empty cache is safe and the feature degrades gracefully.glob llmis configured, so the intended model is used when a key is present.Net effect: the server always boots; tool categorization is best-effort and only runs when both MCP tools and a working LLM are available.
Verification
Reproduced and verified against a jac binary built at a red commit (
f6aed53e, which includes #7042):by llm()at glob-init with no key ->AuthenticationError->Error loading <module>(server never starts), matching the CI trace.jac checkpasses on the changed constructs;jac formatparses the file cleanly.Once merged to
main, theGenerate jac-gpt Jacpackworkflow republishes the jacpack tojaseci-labs/jacpacks, which unblocks the jaseci CI job.