Repository navigation
feat(query): --learned starts from nodes that past useful answers to a similar question cited (#4477) - #4478
devkancheti4-design wants to merge 2 commits into
Conversation
…a similar question cited graphify save-result --outcome useful and graphify reflect --graph already record which nodes answered which questions (.graphify_learning.json), but the query never used it: a question asked again in other words started from scratch. With learned (CLI --learned, MCP query_graph learned=true), nodes whose useful provenance questions are covered at least 40% by the new question's query terms (sharing two or more of them) become start nodes ahead of the keyword seeds, ranked by coverage, shared terms, then lesson score; at most 3. Only preferred and tentative lessons count, stale ones (code changed since) never do, explicit --seed values are never overridden, and the header names the learned nodes. No embeddings: the terms are _query_terms. End to end through save_query_result -> reflect -> query on SWE-bench Lite (12 repos, older half taught by title, cited node = the fixed file): the same issue asked in other words, right file first 26 -> 98 of 140, top 5 50 -> 105; new issues (never taught) 44 -> 42 and 70 -> 70. Default output is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the pull request, @devkancheti4-design. 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. |
There was a problem hiding this comment.
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.
Not checked: tests were not run; formal verification proved 0 of 5 changed function(s) (2 sampled, not proven, 3 not verified).
Formal verification. PR-changed functions: 2/5 verified (0 proven, 2 may-equivalent, 0 distinguished) · 3 not verified (3 vacuous).
Not verified on this run: dispatch\_command (vacuous: never exercised), \_build\_server (vacuous: never exercised), \_render\_query (vacuous: never exercised).
Graphify review — findings
Adds an opt-in --learned flag to graphify query that prepends nodes cited by past useful answers to similar questions ahead of the keyword seeds, so the answer they found renders first. A past question matches when the new one covers at least 40% of its query terms (and shares at least two), counting only non-stale preferred or tentative lessons; explicit --seed values are never overridden and default output is unchanged. Exposes the same learned option on the MCP query tool and lists the matched labels in the result header, but the MCP path coerces the argument with bool() and never loads the reflect overlay that the CLI attaches to the graph.
Worth a look
- MCP
learnedflag is a silent no-op: overlay never loaded —graphify/serve.py:2374· Escalate · medium · 2 independent checks- 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 — 848 functions depend on the 276 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_query_graph_text()— 52 callers, 6 callees - worse:
_query_terms()— 19 callers, 3 callees
Verification — 848 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: 848 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
47 of 423 test file(s) selected (11%) via static blast radius.
tests/test_affected_cli.py— impacttests/test_agents_platform.py— impacttests/test_benchmark.py— impacttests/test_benchmark_raw_graph.py— impacttests/test_benchmark_real_query.py— impacttests/test_cloud_cta.py— impacttests/test_codebuddy.py— impacttests/test_compact_graph_json.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_devin.py— impacttests/test_explain_cli.py— impacttests/test_explain_same_file_tie.py— impacttests/test_extract_cli.py— impacttests/test_file_label_disambiguation.py— impacttests/test_global_add_tag_inference.py— impacttests/test_god_nodes_cli.py— impacttests/test_hollow_chunks_arm_shrink_guard.py— impacttests/test_hook_guard_token_match.py— impacttests/test_hook_out_of_project_paths.py— impacttests/test_hook_strict.py— impacttests/test_incomplete_build_guard.py— impacttests/test_install.py— impacttests/test_install_references.py— impacttests/test_install_version_warning.py— impacttests/test_lookup_exit_codes.py— impacttests/test_mcp_graph_view_cache.py— impacttests/test_merge_chunks_validation.py— impacttests/test_multigraph_diagnostics.py— impacttests/test_no_dedup_flag.py— impacttests/test_opencode_plugin_refresh.py— impacttests/test_partial_cache.py— impacttests/test_path_cli.py— impacttests/test_query_cli.py— impacttests/test_query_induced_edges.py— impacttests/test_query_learned.py— impact, changed-testtests/test_query_mcp_direction.py— impacttests/test_query_names_its_graph.py— impacttests/test_query_seed_order.py— impacttests/test_query_seeds.py— impacttests/test_serve.py— impacttests/test_serve_http.py— impacttests/test_skill_auto_refresh.py— impacttests/test_skill_version_warning.py— impacttests/test_stale_prune.py— impacttests/test_terraform.py— impacttests/test_truncation_full_answer.py— impacttests/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
No difference found (not proven): No behavior difference found in \_run\_cli (not a proof).
The verifier ran both versions of \_run\_cli 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.
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 \_build\_server.
The verifier did not have enough to check \_build\_server, 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 ValueError — names the real obstacle, not a sampling gap)
No difference found (not proven): No behavior difference found in \_query\_graph\_text (not a proof).
The verifier ran both versions of \_query\_graph\_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.
Could not verify: Could not verify \_render\_query.
The verifier did not have enough to check \_render\_query, 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 223 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)
· 2 more finding(s) on lines outside this diff (see the check run).
… startup The MCP graph cache keys each graph on graph.json's stat, and the work-memory overlay is read when the graph loads. `graphify reflect` writes only the sidecar, so a server started before it never saw the new lessons, and `query_graph` with `learned: true` (and the NODE-line annotations) kept the memory the server started with. The cache now also stats the sidecar and, when only the sidecar changed, re-reads the overlay onto the cached graph without reloading it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the check. I tested the MCP path directly, and the main finding doesn't hold. The server loads every graph through It did point me at a real gap next to it, though. The context cache keys each graph on graph.json's stat, and
|
|
Thanks for the PR — reviewed and tests pass (10/10). One minor hardening note on the MCP side: Also, the bot's "MCP learned is a silent no-op" finding appears to be a false positive: the overlay is attached in Integration note: #4481 also edits the same |
What does this PR do?
Closes #4477. It adds
learnedtographify query(CLI--learned, MCPquery_graphlearned: true): the query starts from nodes that past useful answers to a similar question cited. This closes the loopsave-resultandreflectalready open: the memory steers where the traversal starts, instead of only labelling nodes._learned_seeds(G, question)reads the work-memory overlay (the.graphify_learning.jsonsidecar fromgraphify reflect --graph). A node qualifies when all of these hold:Up to 3 such nodes become start nodes ahead of the keyword seeds. They're ranked by coverage, then shared terms, then lesson score, then node id, so the order is deterministic. The header names them:
Learned (past useful answers): [...]. Explicit--seedvalues are never overridden.A running MCP server picks up new memory too. The graph cache keyed each graph on graph.json's stat, and
reflectwrites only the sidecar, so a server started before areflectkept its old memory. The cache now also stats the sidecar, and when only the sidecar changed it re-reads the overlay onto the cached graph without reloading the graph. This also keeps the existinglearning=annotations current.No embeddings: the terms are
_query_terms, the same ones keyword seeding uses._subgraph_to_textis untouched.learneddefaults to false, and the CLI only reads the sidecar when it's set, so default output is unchanged.Measured, end to end through the real pipeline
SWE-bench Lite, 12 repos, default BFS depth 2, 2,000-token budget.
save_query_result(question=title, source_nodes=[the fixed file's node], outcome="useful"), thenreflect(..., graph_path=...).Where the 40% comes from: the same issue in other words covers a median 0.44–0.50 of the taught question's terms, and a different issue covers 0.20–0.25. I chose 0.4 on django and checked it on sympy and matplotlib, which it wasn't tuned on.
Type of change
Verification & Invariants
Invariants:
learned, the output is unchanged;The sidecar is still a derived, read-only overlay: nothing is written to graph.json, and the query never writes the sidecar.
How was this tested?
The new tests cover:
learned=Falsegives the default answer even with a memory;save_query_result→reflect --graph→ query;reflectdone after it loaded (fails without the cache fix).Graphify-specific checklist
Start:line.This continues the same SWE-bench Lite work on
graphify query: #4358 (seed order), #4289 (--seed) and #4470 (--compact). I'm happy to walk through the evaluation or extend it, for example to weighpreferredlessons more, or to make this the default once the memory loop is in wider use.🤖 Generated with Claude Code