Skip to content

fix(search): find a symbol by its docstring (#985) - #4504

Draft
SrijanSriv wants to merge 2 commits into
Graphify-Labs:v8from
SrijanSriv:docstring-search
Draft

SrijanSriv wants to merge 2 commits into
Graphify-Labs:v8from
SrijanSriv:docstring-search

Conversation

@SrijanSriv

@SrijanSriv SrijanSriv commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Related to #985.

A function whose name shares no words with a question was unreachable by search, even when its docstring answers the question ("which function resolves generic call sites?"). AST extraction keeps a docstring as its own rationale node, linked by rationale_for, and its label is cut at 80 characters.

  1. fix(extract): when the 80-character label had to truncate a Python docstring or a JS/TS WHY/NOTE comment, the rationale node also carries the whitespace-collapsed full text in text, capped at 600 characters. Short docstrings add no field. AST cache schema bumped to 18.
  2. fix(search): before the trigram index is built, _attach_docstrings copies each rationale node's text (text, else label) onto the symbol it documents as in-memory _docstring, and _node_rationale_text includes it. Every search path (CLI query, MCP, find_node) builds the index first. Idempotent per graph object; never written back to graph.json.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: a symbol is findable by the words of its own docstring, and graph.json does not grow without bound. Search behaviour for nodes without a docstring is unchanged.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Limitations: only Python docstrings and JS/TS rationale comments get text, the extractors that already produce rationale nodes. The cache schema bump re-extracts ASTs once.

How was this tested?

python -m pytest tests/test_docstring_search.py tests/test_rationale.py
# 42 passed

python -m pytest tests            # whole suite, this branch vs. a clean upstream v8 worktree, same venv
# rebased on 0.9.92 (86c57be8)
# branch:   46 failed, 8160 passed, 192 skipped
# upstream: 46 failed, 8151 passed, 192 skipped
# identical failure set (optional grammars / environment), 9 new tests pass

ruff check graphify/serve.py graphify/extract.py graphify/cache.py tests/test_rationale.py tests/test_docstring_search.py
# All checks passed!

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @SrijanSriv. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 16, 2026

@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.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 4 changed function(s) (2 sampled, not proven, 2 not verified).

Formal verification. PR-changed functions: 2/4 verified (0 proven, 2 may-equivalent, 0 distinguished) · 2 not verified (2 unsupported).

Not verified on this run: \_extract\_js\_rationale (unsupported), \_extract\_python\_rationale (unsupported).


Graphify review — findings

Makes search find a symbol by words that appear only in its docstring (#985): previously a function whose name shared nothing with the question was unreachable even when its docstring answered it. Truncated Python and JS rationale nodes now keep their whitespace-collapsed full text (capped at 600 chars) in a text field, while untruncated ones add nothing. At search time, _attach_docstrings copies that text onto the documented symbol as an in-memory _docstring, which the rationale scoring tier matches, falling back to the truncated label for graphs built before text existed. The attachment is never written back to graph.json, and the AST cache schema is bumped to 17 so existing caches re-extract.

No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3866 functions depend on the 641 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _query_graph_text() — 49 callers, 5 callees
  • worse: _query_terms() — 20 callers, 3 callees
  • worse: _build_server() — 2 callers, 18 callees
  • worse: _get_trigram_index() — 6 callers, 3 callees

Verification — 3866 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: 3655 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

231 of 423 test file(s) selected (55%) via static blast radius.

  • tests/test_affected_overrides.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cpp_template_type_params.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_foreach_loop_variable.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_chain_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_csharp_underscore_collisions.py — impact
  • tests/test_csharp_var_call_return_type.py — impact
  • tests/test_csharp_verbatim_interpolation.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_docstring_search.py — impact, changed-test
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_elixir_defdelegate.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_keyword_def_calls.py — impact
  • … and 181 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Docs that may be stale (advisory)

Formal verification

Could not verify: Could not verify \_extract\_js\_rationale.

The verifier did not have enough to check \_extract\_js\_rationale, 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: no capturable inputs from the test suite; property tier: not verifiable: the input domain has 59 values but only 24 distinct were tested — a small finite domain must be EXHAUSTED, not sampled (an untested input could invert the result)

Could not verify: Could not verify \_extract\_python\_rationale.

The verifier did not have enough to check \_extract\_python\_rationale, 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: no capturable inputs from the test suite; property tier: not verifiable: the input domain has 59 values but only 24 distinct were tested — a small finite domain must be EXHAUSTED, not sampled (an untested input could invert the result)

No difference found (not proven): No behavior difference found in \_get\_trigram\_index (not a proof).

The verifier ran both versions of \_get\_trigram\_index on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in \_node\_rationale\_text (not a proof).

The verifier ran both versions of \_node\_rationale\_text on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

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

SrijanSriv and others added 2 commits October 17, 2026 00:21
… node (Graphify-Labs#985)

A docstring or WHY comment longer than the 80-character label lost every word
past the cut, and those are often the words a question uses. Python and JS/TS
rationale nodes now carry the whitespace-collapsed full text in `text` when the
label had to truncate it, capped at 600 characters to bound graph.json growth.
Short docstrings add no field. AST cache schema bumped to 18.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AST extraction stores a docstring as its own rationale node linked by a
`rationale_for` edge, so a function whose name shares no words with a question
("which function resolves generic call sites?") was unreachable even when its
docstring answers it. Before building the trigram index, copy each rationale
node's text onto the symbol it documents as in-memory `_docstring`, and let the
rationale tier match it. Idempotent per graph object; never written back to
graph.json. Every search path (CLI query, MCP, find_node) goes through the index.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant