feat(mcp): pre-execution lint scanner and namespace pre-injection for catalog code#25
Open
paddymul wants to merge 2 commits into
Open
feat(mcp): pre-execution lint scanner and namespace pre-injection for catalog code#25paddymul wants to merge 2 commits into
paddymul wants to merge 2 commits into
Conversation
4e1557d to
d47bca1
Compare
… catalog code Add a static AST scanner that catches bad import patterns before any user code executes, and pre-inject the four canonical names (ibis, xo, from_catalog, from_project) into the module namespace so catalog scripts need zero import statements for common usage. Session analysis showed `import ibis` and `import xorq as xo` caused 3 of 5 MCP failures — both required 1-2 retries to recover from runtime errors with cryptic AttributeErrors. The scanner now returns a clear rejection before exec; the pre-injection means well-written code works without imports. Also fix the summary-stats sandbox: Exception and common exception types were missing from _SAFE_BUILTIN_NAMES, forcing `except Exception:` to fail with NameError. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
d47bca1 to
77b67ca
Compare
paddymul
added a commit
that referenced
this pull request
Jun 25, 2026
…cess in src) git_revision shelled out via subprocess.run(["git", ...]), which the no-bare-subprocess-git guard (test_no_bare_subprocess_git_in_src, #25/G1) forbids: bare git forks, and forking from the multithreaded server can crash on macOS. Use the sanctioned fork-safe git_util.run_git (posix_spawn). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
lint_catalog_code) runs before any user code executes and immediately rejectsimport ibis,from ibis import X,import xorq(bare), andimport xorq as xowith actionable error messages_inject_prelude) loadsibis,xo,from_catalog,from_projectinto the module namespace beforeexec_module, so catalog scripts need zero import statements for common usageExceptionand 7 other exception types were missing from_SAFE_BUILTIN_NAMES, causingexcept Exception:to fail withNameErrorat validation timecatalog_runnow leads with the pre-injected names and the zero-import minimal pattern, and lists forbidden imports explicitlyMotivation
Session transcript analysis found
import ibisandimport xorq as xocaused 3 of 5 MCP call failures across two sessions — both patterns required 1-2 retries to recover via runtime hint. The scanner now rejects them immediately before exec; the pre-injection means a well-written script with no imports at all just works.Test plan
tests/test_build.py— 14 new tests: 9lint_catalog_codeunit tests, 1 end-to-endbuild_and_persistlint-fires-before-exec test, 1 pre-injection test (ibis/xo available without import), 3 existing tests unchanged (error messages still match)test_build.pytests pass locallytest_buckaroo.pyandtest_diff.pyare unrelated (caused by in-progress uncommitted changes toresult_cache.pyandapp.py)🤖 Generated with Claude Code