Skip to content

v0.8.22 regression of #760: fresh /graphify build round-trips correct AST output into reversed calls edges (build_from_json -> to_json undirected round-trip) #1061

Closed

Description

@peteratx14

graphifyy v0.8.22 — fresh /graphify <path> round-trips correct AST output into reversed-direction calls edges (regression of #760, distinct entry point from #801/#849)

Package: graphifyy v0.8.22 (uv tool install)
Skill: bundled skill.md as shipped
Environment: Windows 11, Python 3.12, fresh /graphify packages/db on a Next.js / Prisma monorepo subfolder
Related (closed): #760 (extractor fix), #801 (skill --update merge bypass), #849 (graphify path undirected render)

Summary

Raw graphify.extract.extract() correctly emits calls edges as (caller_id → callee_id). But the fresh-build pipeline that the bundled skill walks — build_from_json(extraction) → to_json(G, communities, 'graphify-out/graph.json') — round-trips through nx.Graph (undirected) and writes back graph.json with caller and callee swapped on 7 of 8 calls edges in a 77-node graph. Only edges where the callee identifier is nested inside another call expression (outer(callee(...))) survive with correct direction.

This is not the --update path #801 fixed and not the renderer-only #849 bug. The wrong direction is persisted into graph.json itself, on first build, with no merge step involved.

Reproduction

uv tool install graphifyy==0.8.22
mkdir repro; cd repro
# Drop in any TS project with >=1 caller->callee pair, e.g. the snippet below
/graphify .

Minimal TS reproducer (4 functions, 8 call sites):

// seed.ts
import { seedDefaults, provisionOrganizationRoles } from "./seed-defaults";
import { seedCommsConversations } from "./seed-comms-conversations";
async function main() {
  await seedDefaults(prisma);              // expect: main --calls--> seedDefaults
  await provisionOrganizationRoles(org.id, prisma);
  await seedCommsConversations(prisma, org.id, parkId);
}
main();
// db-for.ts
import { orgScopeExtension } from "./org-scope-extension";
export function dbFor(session) {
  return db.$extends(orgScopeExtension(() => orgId));  // nested-as-argument
}
// org-scope-extension.ts
function buildOrgFilter(...) {}
function mergeWhere(...) {}
export function createOrgScopeAllOperations(...) {
  return async function $allOperations(params) {
    const scope = buildOrgFilter(...);     // expect: createOrgScopeAllOperations --calls--> buildOrgFilter
    return query({ where: mergeWhere(...) });
  };
}

Evidence

Step 1 — raw extractor output is correct

graphify.extract.extract([files]) returns edges with source = caller, target = callee for every case:

prisma_seed_defaults_main                            -->  prisma_seed_defaults_seeddefaults
src_org_scope_extension_createorgscopealloperations  -->  src_org_scope_extension_buildorgfilter
src_org_scope_extension_createorgscopealloperations  -->  src_org_scope_extension_mergewhere
prisma_seed_main                                     -->  prisma_seed_defaults_seeddefaults
prisma_seed_main                                     -->  prisma_seed_defaults_provisionorganizationroles

Extractor is fine post-#760.

Step 2 — round-trip via build_from_json + to_json inverts 7/8 edges

After Step 4 of the skill (G = build_from_json(extraction); to_json(G, communities, 'graphify-out/graph.json')), iterating the persisted graph.json edges:

# Stored source --calls--> target in graph.json Verified source-of-truth direction OK?
1 seedCommsConversations() -> main() main() -> seedCommsConversations() (seed.ts:844, inside async function main()) NO
2 seedDefaults() -> main() main() -> seedDefaults() (seed-defaults.ts L271->L185, same file) NO
3 seedDefaults() -> main() (cross-file) main() (seed.ts:20) -> seedDefaults() NO
4 provisionOrganizationRoles() -> main() main() (seed.ts:36) -> provisionOrganizationRoles() NO
5 dbFor() -> orgScopeExtension() dbFor() (db-for.ts:24) -> orgScopeExtension() — nested-as-argument call YES
6 buildOrgFilter() -> createOrgScopeAllOperations() createOrgScopeAllOperations() -> buildOrgFilter() (org-scope-extension.ts:184) NO
7 mergeWhere() -> createOrgScopeAllOperations() createOrgScopeAllOperations() -> mergeWhere() (org-scope-extension.ts:188) NO
8 createOrgScopeAllOperations() -> makeCallback() makeCallback() (test) -> createOrgScopeAllOperations() NO

7/8 reversed. Only #5 (nested outer(inner(...)) call) survives.

Likely root cause

build_from_json in build.py defaults to undirected (nx.Graph). When the skill subsequently calls to_json(G, communities, ...), the writer iterates G.edges() and emits each edge as (u, v) in whichever orientation NetworkX returns — which on an undirected graph is canonical / insertion-determined, not the original source/target preserved on the edge dict.

This is the same class of bug as #801 (the --update inline merge bypassed build_merge()), but the entry point is different: here it is the fresh-build path the skill walks unconditionally on first /graphify <path>. No merge involved. Every fresh build of a TS codebase via the skill ships graph.json with inverted calls directions.

Why the one nested-call edge survives is unclear — possibly the AST extractor emits that edge in (alphabetical / hash) order that happens to coincide with caller->callee for that specific node-pair, and survives the undirected round-trip; the other 7 happen to lose.

Suggested fix

Either:

  1. Build directed. Change build_from_json default to directed=True (or have the skill pass directed=True), and ensure to_json writes source/target from the edge dict, not from NetworkX's undirected iteration order. This also fixes any downstream query / path / explain direction reporting that consumes graph.json.

  2. Preserve direction on undirected edges. When to_json writes an edge, look up the original source/target already stored on the edge attribute dict and use those, instead of taking the NetworkX (u, v) tuple.

Option 1 is cleaner and also unblocks impact-radius / blast-radius / callers_of / callees_of queries that currently cannot trust direction.

Severity

Same class as #760 — every assistant that reads graph.json and reports caller->callee will report it backwards. God-node centrality is degree-based so it is unaffected, but every "X is called by Y" / "Y depends on X" narrative is inverted. Surfaces immediately to any user asking "how does X reach Y?" via the skill BFS query path.

Activity

  1. safishamsi commented on May 29, 2026

    @safishamsi
    Member

    Fixed in 66acfd8 (shipped in v0.8.24) — build_from_json now preserves first-seen direction on bidirectional node pairs, preventing the lexicographic sort from clobbering _src/_tgt on the second write.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions