fix(cli): pass non-nil context through namespace tool dispatch#85
Open
chiplay wants to merge 1 commit into
Open
fix(cli): pass non-nil context through namespace tool dispatch#85chiplay wants to merge 1 commit into
chiplay wants to merge 1 commit into
Conversation
Namespace commands (live/comment/doc/artifact) delegate to callCmd by invoking its RunE directly rather than through cobra's Execute, so callCmd's context is never populated. runCall then passed cmd.Context() — nil — into http.NewRequestWithContext, producing "net/http: nil Context" on every tool invocation and every per-tool --help. Only version, auth whoami, and namespace-level --help (which use context.Background() explicitly) worked. Propagate the namespace command's context to callCmd before delegating, and guard runCall with a context.Background() fallback so the HTTP request builders never receive a nil context. Add an integration test that drives the real namespace dispatcher against a stub MCP server — the path the stubbed unit tests never exercised. It fails with the exact nil-context error on unpatched code and passes with the fix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
|
@jurassix I tried using the CLI 1.0.0 and hit this issue. Can you take a look next week and see if this is the right fix? |
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
In the shipped Go CLI (
@subtextdev/subtext-cli@1.0.0), every tool invocation across every namespace fails:Only
version,auth whoami, and namespace-level--helpwork. The CLI cannot call a single MCP tool — its core purpose is non-functional.Root cause
Namespace commands (
live/comment/doc/artifact) useDisableFlagParsingand delegate by callingcallCmd.RunE(callCmd, …)directly (namespaces.go), never through cobra'sExecute. SocallCmd's context is never set.runCallthen passescmd.Context()— nil — intoc.GetTool/c.CallTool→http.NewRequestWithContext(nil, …)→net/http: nil Context.auth whoamiand namespace listing survived only because they callListTools(context.Background())explicitly (help.go).Fix
namespaces.go: propagate the namespace command's context tocallCmdbefore delegating.call.go: guardrunCallwith acontext.Background()fallback and use it at all three call sites, so the HTTP request builders never receive a nil context (defense-in-depth; also makesrunCallcorrect when called directly).Test
Added
integration_test.go— drives the real namespace dispatcher (namespaceRunE→callCmd) against a stubhttptestMCP server, exercising thecmd.Context()→HTTP path the stubbed unit tests never reached. Verified it fails with the exactnet/http: nil Contexterror on unpatched code and passes with the fix.Verification
go build ./...+go test ./...clean. Locally-built binary verified against the production na1 endpoint:doc listreturns real proof docs ✅--helpfetches schemas ✅live connect→screenshot→artifact upload→comment add→disconnectfull round-trip ✅version/auth whoami/ namespace--helpunaffected ✅Warrants a
v1.0.1patch release once merged.🤖 Generated with Claude Code
Note
Low Risk
Small, localized CLI dispatch fix with a regression test; no auth or server changes.
Overview
Fixes broken MCP tool calls for namespace commands (
doc,live,comment,artifact). Those paths delegate to internalcallCmdwithout going through CobraExecute, socallCmdhad a nil context and everyGetTool/CallToolfailed withnet/http: nil Context.namespaceRunEnow copies the namespace command’s context ontocallCmdbefore delegating.runCallalso normalizes context (usescontext.Background()when still nil) and routes help, schema fetch, and tool invocation through thatctx.Adds
TestNamespaceDispatchCallsTool, an httptest integration test that runsnamespaceRunE→callCmdand asserts a fulltools/list+tools/callround trip—covering the path unit tests did not hit.Reviewed by Cursor Bugbot for commit 6084902. Bugbot is set up for automated code reviews on this repo. Configure here.