Skip to content

fix(serve): print confidence_score in path, explain and neighbors output - #4888

Closed
SyedFahad7 wants to merge 2 commits into
Graphify-Labs:v8from
SyedFahad7:cursor/inferred-confidence-score-output-57d2
Closed

SyedFahad7 wants to merge 2 commits into
Graphify-Labs:v8from
SyedFahad7:cursor/inferred-confidence-score-output-57d2

Conversation

@SyedFahad7

@SyedFahad7 SyedFahad7 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

graph.json stores a confidence_score on INFERRED edges. For example, C# interface dispatch (interface_dispatch.py, _dispatch_confidence) writes 0.85, 0.75 or 0.65 depending on how many implementers there are. The text renderers printed only the bare tag, though, so [INFERRED] didn't tell you whether an edge was a strong or a weak inference.

This adds one shared helper, _confidence_tag() in serve.py. Wherever an edge's confidence is printed in path, explain and neighbors output, it now shows [INFERRED 0.75] when the edge has a score:

  • CLI path (cli.py)
  • CLI explain (cli.py)
  • MCP shortest_path (serve.py _shortest_path_text)
  • MCP get_neighbors (serve.py _neighbor_lines)

Repro from the issue (Report.cs, then graphify update .):

before:  --> .Build() [dispatches_to] [INFERRED] Report.cs:L2
after:   --> .Build() [dispatches_to] [INFERRED 0.75] Report.cs:L2

before:  .Run() --calls [INFERRED]--> .Build() --dispatches_to [INFERRED]--> .Build()
after:   .Run() --calls [INFERRED 0.85]--> .Build() --dispatches_to [INFERRED 0.75]--> .Build()

I've since merged v8 (0.9.98) into this branch. The score now sits alongside what landed there: the weaker also_seen evidence shows as [AMBIGUOUS 0.40/INFERRED 0.75], and the weakest-hop Path confidence: line gets the score too. EXTRACTED hops still print no score. The test expectations now use the new C# owner labels, like PdfReport.Build(). The query EDGE lines and affected (#2352) are out of scope and unchanged.

Fixes #4882

Type of change

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

Verification & Invariants

Invariant: inference stays visibly separate from extracted fact, and the output never shows more precision than graph.json actually stores.

  • A score is printed only for a non-EXTRACTED edge whose stored confidence_score is a finite int or float. EXTRACTED edges stay [EXTRACTED] because they are 1.0 by definition, and showing that everywhere would only add noise.

  • A missing, None, string, boolean or NaN score leaves the bare tag. The fallback is the old output, not a guessed number.

  • Scores are formatted as {:.2f}, which matches the two-decimal tiers in the extraction rubric.

  • Display only: no persisted graph or cache state changes, and no AST cache schema bump is needed.

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

Limitation: a score stored as a numeric string (for example "0.75") is not coerced and renders bare.

How was this tested?

tests/test_confidence_score_output.py runs the issue's Report.cs repro through extract → build_from_json → to_json. It asserts the stored scores (0.85 and 0.75), then checks CLI explain, CLI path, MCP shortest_path and MCP get_neighbors. It also has parametrized boundary cases for _confidence_tag. On v8 without the fix, the four output tests fail.

uv run pytest tests/test_confidence_score_output.py -q   # 15 passed
uv run pytest tests/ -q                                  # 9161 passed, 18 skipped, 1 xfailed (after merging v8 0.9.98)
uv run ruff check .                                      # All checks passed
uv run pyright                                           # no new errors (667 vs 668 on v8 base)
graphify update /tmp/repro && graphify explain report_ireport_build && graphify path report_exporter_run report_pdfreport_build

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments touched)
  • 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.
Open in Web Open in Cursor 

graph.json stores a confidence_score next to every INFERRED edge (C#
interface dispatch writes 0.85 / 0.75 / 0.65 by implementer count), but
`path`, `explain` and the MCP shortest_path / get_neighbors renderers only
printed the bare tag, so `[INFERRED]` hid whether an edge was a strong or
a weak inference.

A shared _confidence_tag() now renders a scored non-EXTRACTED edge as
`[INFERRED 0.75]` at all four sites. EXTRACTED stays bare (it is 1.0 by
definition), and a missing, non-numeric, boolean or non-finite score
keeps the bare tag instead of printing a guess.

Tests: tests/test_confidence_score_output.py runs the issue's Report.cs
repro through extract/build and checks CLI explain, CLI path, MCP path and
MCP neighbors; the four output tests fail without the fix.

Fixes Graphify-Labs#4882

Co-Authored-By: Claude <[email protected]>
Co-authored-by: Syed Fahad <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @SyedFahad7. 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 30, 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 3 changed function(s) (3 not verified).

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

Not verified on this run: dispatch\_command (vacuous: never exercised), \_neighbor\_lines (vacuous: never exercised), \_shortest\_path\_text (vacuous: never exercised).


Graphify review — findings

Adds the stored confidence_score to edge output in path, explain, and the MCP shortest_path and neighbor listings, so a scored non-EXTRACTED edge now reads [INFERRED 0.75] instead of a bare [INFERRED]. A new _confidence_tag helper in serve.py builds the label and is shared by the CLI and MCP renderers. EXTRACTED edges stay bare since their score is 1.0 by definition. Edges with a missing, boolean, string, or non-finite score fall back to the bare label rather than printing a guess. New tests cover the helper's edge cases and check the output end to end on a C# interface-dispatch graph.

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

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 818 functions depend on the 254 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: dispatch_command() — 5 callers, 136 callees
  • worse: main() — 116 callers, 3 callees
  • worse: _shortest_path_text() — 15 callers, 4 callees
  • worse: _neighbor_lines() — 6 callers, 4 callees

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

Test selection

Test selection

49 of 470 test file(s) selected (10%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_cloud_cta.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_confidence_score_output.py — impact, changed-test
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_devin.py — impact
  • tests/test_explain_cli.py — impact
  • tests/test_explain_same_file_tie.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_extract_cost_ledger.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_global_add_tag_inference.py — impact
  • tests/test_god_nodes_cli.py — impact
  • tests/test_hollow_chunks_arm_shrink_guard.py — impact
  • tests/test_hook_guard_token_match.py — impact
  • tests/test_hook_nudge_wording.py — impact
  • tests/test_hook_out_of_project_paths.py — impact
  • tests/test_hook_strict.py — impact
  • tests/test_incomplete_build_guard.py — impact
  • tests/test_install.py — impact
  • tests/test_install_references.py — impact
  • tests/test_lookup_exit_codes.py — impact
  • tests/test_mcp_graph_view_cache.py — impact
  • tests/test_merge_chunks_validation.py — impact
  • tests/test_multigraph_diagnostics.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_opencode_plugin_refresh.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_query_cli.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_query_mcp_direction.py — impact
  • tests/test_query_names_its_graph.py — impact
  • tests/test_query_seed_order.py — impact
  • tests/test_query_seeds.py — impact
  • tests/test_serve.py — impact
  • tests/test_serve_http.py — impact
  • tests/test_skill_auto_refresh.py — impact
  • tests/test_stale_prune.py — impact
  • tests/test_terraform.py — impact
  • tests/test_truncation_full_answer.py — impact
  • tests/test_unverified_semantic_shrink.py — impact

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.

Formal verification

Could not verify: Could not verify dispatch\_command.

The verifier did not have enough to check dispatch\_command, 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: all 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_neighbor\_lines.

The verifier did not have enough to check \_neighbor\_lines, 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: all 153 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_shortest\_path\_text.

The verifier did not have enough to check \_shortest\_path\_text, 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: all 35 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly KeyError — names the real obstacle, not a sampling gap)

· 1 grounded finding(s) anchored inline below; 3 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/serve.py
return conf


def _shortest_path_text(G: nx.Graph, arguments: dict) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — _shortest_path_text()

15 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Keep v8 path behavior (also_seen evidence, weakest-hop confidence,
Type.Member endpoints, and C# owner labels) and print confidence_score
on non-EXTRACTED hops in path, explain, and neighbor output. EXTRACTED
hops stay bare.

Update expected path and explain strings for the owner-qualified C# labels.

Co-authored-by: Syed Fahad <[email protected]>
safishamsi added a commit that referenced this pull request Oct 30, 2026
…4888)

#4888 was built on 0.9.97, before #4881 (path weakest-hop refactor),
#4889 (qualified C# method labels) and #4891 (also_seen) landed. Its
cherry-pick dropped the merge commit that reconciled expectations. Update
the per-hop confidence assertions to carry scores ([INFERRED 0.85]) and
the C# path/explain/neighbor labels to their owner-qualified form
(Exporter.Run, IReport.Build) - the correct composed output of all four
features. Resolved the serve.py conflict by keeping #4881's _path_weakest/
_path_confidence_line and adding only #4888's _confidence_tag, applied over
edge_evidence so parallel/also_seen evidence keeps its scores.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
safishamsi added a commit that referenced this pull request Oct 30, 2026
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.99, now on PyPI (pip install graphifyy==0.9.99). path, explain and neighbors now print an edge's confidence_score alongside its tag; EXTRACTED stays bare. Thanks for the fix, @SyedFahad7.

@safishamsi safishamsi closed this Oct 30, 2026
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.

[Feature]: print confidence_score in path and explain

3 participants