Skip to content

feat(sql): make tree-sitter-sql a core dependency so default installs parse .sql (#1745) - #2959

Closed
egarcia74 wants to merge 6 commits into
Graphify-Labs:v8from
egarcia74:fix/sql-core-dependency
Closed

egarcia74 wants to merge 6 commits into
Graphify-Labs:v8from
egarcia74:fix/sql-core-dependency

Conversation

@egarcia74

@egarcia74 egarcia74 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A default uv tool install graphifyy / pipx install graphifyy contributes nothing for .sql files: the grammar lives behind the [sql] extra, so extract_sql bails with an error result and the #1745 warning is the only signal. SQL is a mainstream corpus language — schemas, migrations, stored procedures — and the failure mode is exactly the silent-skip shape #1745 was about: the operator sees a graph, just one with an entire language missing, and nothing tells them at install time.

We hit this in the field: a 391-file T-SQL data-migration corpus produced zero SQL object nodes on a fresh default install, and the fix was discoverable only by reading extractor source.

Why core rather than a better hint

tree-sitter-sql ships prebuilt abi3 wheels for every supported platform (Windows/macOS/Linux glibc+musl, x86_64+arm64) from 0.3.9, so promoting it keeps the default install toolchain-free — the reason tree-sitter-dm stays optional (#1104) does not apply here. The pin >=0.3.9,<0.4 carries an upper bound like every other grammar pin.

What this PR does

  • tree-sitter-sql>=0.3.9,<0.4 moves from the [sql] extra into [project.dependencies], with a comment recording the wheel-availability rationale so the packaging policy stays legible.
  • The sql extra is kept as an alias, so existing graphifyy[sql] install commands and scripts keep resolving; it now adds nothing beyond the core install.
  • .sql is removed from _EXTRA_FOR_EXTENSION, so the .sql files silently extract 0 nodes when the [sql] extra is missing #1745 warning no longer sends users to a now-redundant extra; the extractor's missing-grammar error now says the install is incomplete and names the direct repair.
  • README extras table updated; the sql row is replaced with a note explaining the move and that a normal upgrade is all an existing [sql]/pipx inject install needs.
  • Version bump and changelog entry are deliberately not included — those look like maintainer release-commit territory here (chore: bump to 0.9.48), so comments and messages describe the grammar as a core dependency without naming a release.

Tests

New tests/test_sql_core_dependency.py pins the fix at the packaging layer so a regression (the dependency sliding back into an extra) fails the suite rather than resurfacing as a field report:

  • the grammar must be in [project.dependencies], with an upper bound;
  • .sql must not be mapped to an optional extra in the hint map;
  • the dev environment itself must satisfy the dependency;
  • an end-to-end table/view/procedure corpus must produce object nodes, contains/references/reads_from edges, and no dangling edge sources.

Existing SQL tests in tests/test_multilang.py convert from importorskip (which would silently skip the whole SQL surface if the grammar went missing — the exact failure mode this PR removes) to a hard import that fails instead. test_extract_warns_when_sql_grammar_missing now simulates genuine absence via both sys.modules and a find_spec monkeypatch, and asserts the new message names the direct repair, not the extra.

Validation

  • Fresh-venv wheel install pulls tree-sitter-sql transitively; a SQL fixture produces nodes/edges with no extra or pipx inject involved; the missing-grammar warning path proven live by blanking the module.
  • Full suite: 6 failed, 4835 passed, 28 skipped — the 6 (test_ollama.py, test_ollama_retry_cap.py) fail identically on unmodified v8 in this environment (local Ollama config), none touch SQL or packaging.
  • ruff check graphify/ tests/: all checks passed.
  • uv.lock regenerated.

Note

Independent of my companion PR #2960 fixing T-SQL routine recovery in graphify/extractors/sql.py; both touch tests/test_multilang.py, and a local merge of the two branches resolves trivially (we run the combined branch in production against the 391-file corpus).

egarcia74 and others added 4 commits August 23, 2026 00:13
A default install (uv tool install graphifyy / pipx install graphifyy)
shipped without SQL parsing: tree-sitter-sql lived behind the [sql]
extra, so every .sql file silently contributed nothing until the user
found the extra or ran pipx inject (Graphify-Labs#1745). The grammar ships prebuilt
abi3 wheels for every supported platform from 0.3.9, so the reason
tree-sitter-dm stays optional does not apply.

- promote tree-sitter-sql>=0.3.9,<0.4 into [project.dependencies];
  keep the [sql] extra as an alias so existing install scripts resolve
- drop .sql from _EXTRA_FOR_EXTENSION: a missing grammar now means a
  broken install, so the Graphify-Labs#1745 warning must not point at an extra
- reword the extractor's missing-grammar error to say the install is
  incomplete and name the direct repair

Bumps version to 0.9.49.

Co-Authored-By: Claude Fable 5 <[email protected]>
- new test_sql_core_dependency.py: tree-sitter-sql must sit in
  [project.dependencies] with an upper bound, .sql must not map to an
  optional extra, and a table/view/procedure corpus must produce
  structural nodes plus contains/references/reads_from edges
- convert every importorskip("tree_sitter_sql") to a hard import: the
  grammar is core now, so its absence must fail the suite, not skip it
- update the Graphify-Labs#1745 warning test: the dev environment now ships the
  grammar, so genuine absence is simulated by blanking find_spec, and
  the message must say "core dependency" instead of hinting at
  graphifyy[sql]

Each packaging guard was mutation-tested (dep removed from pyproject,
.sql re-added to the extras map) and failed as required.

Co-Authored-By: Claude Fable 5 <[email protected]>
Remove the sql row from the optional-extras table, add an upgrade note
(existing extra/pipx-inject users just run the normal upgrade), and add
the 0.9.49 changelog entry.

Co-Authored-By: Claude Fable 5 <[email protected]>
Upstream cuts versions and batches changelog entries in maintainer
commits (see 'chore: bump to 0.9.48'), so a contributor PR should not
claim the next version number. Comments and messages now describe the
grammar as a core dependency without naming a release.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Promotes tree-sitter-sql from the sql extra to a core dependency in pyproject.toml, so .sql files extract on a default install (#1745); the sql extra stays as a harmless alias for old install scripts. Drops .sql from _EXTRA_FOR_EXTENSION and rewords extract_sql's missing-grammar error to name a broken install / direct reinstall rather than an optional extra, with README updated to match. Replaces the importorskip/_extract_sql_or_skip skips in the SQL tests with hard import tree_sitter_sql so absence fails instead of silently skipping.

Worth a look

  • SQL dependency is only added to the lockfile, not the packaging source — uv.lock:1338 · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1897 functions depend on the 710 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 476 callers, 42 callees
  • new: _rebuild_code() — 98 callers, 50 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_js() — 80 callers, 3 callees
  • new: dispatch_command() — 2 callers, 119 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: collect_files() — 17 callers, 6 callees
  • …and 25 more — each is listed as a finding

Verification — 1897 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 1749 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify extract\_sql.

The verifier did not have enough to check extract\_sql, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

· 33 more finding(s) on lines outside this diff (see the check run).

@egarcia74

Copy link
Copy Markdown
Contributor Author

On the Graphify-review finding ("SQL dependency is only added to the lockfile, not the packaging source", flagged high at uv.lock:1338): this doesn't match the diff. tree-sitter-sql>=0.3.9,<0.4 is added to [project.dependencies] in pyproject.toml (line 50 on the branch tip) — the lockfile change is downstream of that. The PR also ships test_tree_sitter_sql_is_a_core_dependency, which pins exactly this invariant by parsing pyproject.toml and fails if the dependency ever slides back into an extra; it passes on this branch. (The review itself notes the finding was "agreed but NOT verified".) Happy to adjust if a maintainer sees something I'm missing.

Review findings on the fork PR:

- The missing-grammar error now names pip install
  'tree-sitter-sql>=0.3.9,<0.4' — the unpinned command could pull a
  grammar outside the supported range; the warning test asserts the
  pinned form.
- The end-to-end corpus test now passes cache_root=tmp_path so it
  cannot write cache state under the working directory.
- Renamed an ambiguous 'l' loop variable this PR introduced (E741);
  pre-existing occurrences upstream are left untouched to keep the
  diff scoped.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Promotes tree-sitter-sql from the sql extra to a core dependency in pyproject.toml, keeping sql as a no-op alias for old install commands. Rewrites the missing-grammar error in extract_sql and drops .sql from _EXTRA_FOR_EXTENSION so a missing grammar reports a broken install with a direct pip install repair rather than pointing at an extra. Updates the README table plus the SQL tests to require the grammar (import instead of importorskip) and assert the new message wording.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1897 functions depend on the 710 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 476 callers, 42 callees
  • new: _rebuild_code() — 98 callers, 50 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_js() — 80 callers, 3 callees
  • new: dispatch_command() — 2 callers, 119 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: collect_files() — 17 callers, 6 callees
  • …and 25 more — each is listed as a finding

Verification — 1897 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 1749 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify extract\_sql.

The verifier did not have enough to check extract\_sql, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

· 33 more finding(s) on lines outside this diff (see the check run).

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Promotes tree-sitter-sql from the [sql] extra to a core dependency so .sql schema extraction works in every default install, keeping sql as a no-op alias extra for existing install scripts. When the grammar is genuinely missing, extract_sql and the #1745 warning now report a broken install and name the direct pip install 'tree-sitter-sql>=0.3.9,<0.4' repair instead of pointing at the extra, and .sql is dropped from _EXTRA_FOR_EXTENSION. Tests now hard-require the grammar via import tree_sitter_sql rather than importorskip, and the missing-grammar case is simulated by patching find_spec.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 2157 functions depend on the 785 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 522 callers, 43 callees
  • new: _rebuild_code() — 113 callers, 50 callees
  • new: extract_js() — 85 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: dispatch_command() — 2 callers, 123 callees
  • new: extract_sql() — 20 callers, 9 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • …and 26 more — each is listed as a finding

Verification — 2157 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 1992 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify extract\_sql.

The verifier did not have enough to check extract\_sql, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

· 34 more finding(s) on lines outside this diff (see the check run).

@febryo-sc

Copy link
Copy Markdown

Second field data point for this, from a default uv tool install graphifyy (0.9.5, later
0.9.56) on a TypeScript codebase that keeps every statement in its own .sql file:

  • 270 .sql files → 0 nodes, across roughly 30 graph builds over a month. Every file was
    scanned (each had both ast_hash and semantic_hash in manifest.json), and .sql is in
    CODE_EXTENSIONS, so nothing in the pipeline looked wrong from the outside.
  • uv tool install --force --with tree-sitter-sql graphifyy + a rebuild: 0 → 312 nodes
    (a file node per statement, plus table nodes with FK references edges from the migrations).
  • The only trace of the failure anywhere was the discarded error string inside
    extract_sql's ImportError branch. GRAPH_REPORT.md's Corpus Check counted the files as
    part of the corpus.

Worth noting the shape generalizes past SQL: extractors/terraform.py (.hcl) and
extractors/robot.py return the same {"nodes": [], "edges": [], "error": "... not installed"}, so whatever surfacing lands here (install-time check, one warning per run, or a
line in Corpus Check) would ideally cover any extension that is in CODE_EXTENSIONS but whose
grammar is absent — not just .sql.

mlgitdev added a commit to mlgitdev/graphify that referenced this pull request Nov 2, 2026
…action works on a plain install

tree-sitter-hcl lived behind the [terraform] extra, so a default
`pip install graphifyy` / `uv tool install graphifyy` could not parse
.tf/.hcl files: extract_terraform returned an error, the Graphify-Labs#1745 warning
went to stderr, the run exited 0, and the resulting graph silently lacked
the whole Terraform corpus until the user reinstalled with the extra
(Graphify-Labs#187, Graphify-Labs#1745).

The extra was made optional in the original Terraform PR purely for install
footprint. The reasons the other grammars stay optional do not hold here:
tree-sitter-hcl 1.2.0 ships prebuilt cp310-abi3 wheels for macOS
(arm64/x86_64), Linux glibc x86_64/aarch64, Linux musl x86_64 and Windows
amd64, so no C toolchain is needed, and it declares no runtime pin that
could conflict with tree-sitter>=0.25,<0.26. The only uncovered targets
(musllinux aarch64, win32) already have no wheel for tree-sitter itself and
for tree-sitter-json. This mirrors the tree-sitter-sql treatment proposed
in Graphify-Labs#2959.

- pyproject: add "tree-sitter-hcl>=1.2.0,<2" to the core dependencies; keep
  the `terraform` extra as a no-op alias so existing install commands keep
  resolving; drop the now-redundant dev-group entry that masked the gap.
- extractors/terraform: split "genuinely absent" from "installed but fails
  to load" (as sql.py does, Graphify-Labs#2602). The absent message now says the grammar
  is a core dependency and gives the exact repair.
- extract: drop .tf/.tfvars/.hcl from _EXTRA_FOR_EXTENSION so the Graphify-Labs#1745
  warning no longer advertises a redundant extra.
- README/CHANGELOG: extras row replaced by a note; changelog entry added.
- uv.lock: only the tree-sitter-hcl metadata move plus the graphifyy
  version line (0.9.99 -> 0.9.100) that was already stale on v8.

*.tf.json is untouched: it still routes to the JSON extractor via
effective_suffix, with or without the HCL grammar, and a test pins that.
No AST cache schema bump: the installed grammar set is part of the cache
key (_grammar_fingerprint), so it re-keys by itself.

AI-assisted; reviewed and tested by the author.
@egarcia74 egarcia74 closed this Nov 22, 2026
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