Skip to content

fix(export): add id-based join fields to file-level exportJSON edges - #2342

Merged
carlos-alm merged 2 commits into
mainfrom
fix/issue-2144-exportjson-edge-schema
Aug 8, 2026
Merged

carlos-alm merged 2 commits into
mainfrom
fix/issue-2144-exportjson-edge-schema

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

Closes #2144

exportJSON's two modes produce edges with a different source/target schema:

  • File-level (default): edges[].source/target are file path strings, which don't join against this same payload's nodes[].id.
  • Function-level (--functions): edges[].source/target are numeric node IDs, matching nodes[].id.

Changing file-level's source/target to numeric IDs directly (matching function-level) would be a breaking change to the existing codegraph export -f json output shape, which has real consumers relying on file paths there today — flagged in the issue as needing "a consistent identifier scheme... version/document the change since it affects the public JSON export shape."

Fix

Purely additive: file-level edges now also carry sourceId/targetId (numeric, matching nodes[].id), alongside the existing source/target file-path strings. Consumers who want the same id-based join function-level mode already supports can use the new fields; anyone reading source/target as file paths today is unaffected.

Test plan

  • New test in tests/graph/export.test.ts: file-level edges' sourceId/targetId resolve against nodes[].id, while source/target remain file path strings.
  • Verified end-to-end against this repo's own graph via codegraph export -f json.
  • Full npm test suite passes (4607 tests, 287 files).
  • npx tsc --noEmit and npm run lint clean.

…2144)

File-level exportJSON edges use file path strings for source/target,
which don't join against this same payload's nodes[].id the way
function-level mode's numeric-id edges do. Fixing source/target
directly would break existing codegraph export -f json consumers who
read them as file paths today, so this adds sourceId/targetId
(numeric, matching nodes[].id) alongside the existing fields instead —
purely additive, giving consumers the same id-based join function-level
mode already supports without changing the existing shape.

docs check acknowledged.

Impact: 1 functions changed, 2 affected
@greptile-apps

greptile-apps Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR completes the file-level JSON edge fix by deriving additive sourceId and targetId fields from exported file nodes while preserving path-based source and target.

  • Keeps the existing public file-level edge schema backward compatible.
  • Ensures cross-file symbol edges join to file-node IDs without widening DISTINCT aggregation.
  • Represents directory endpoints that have no exported file node with null.
  • Adds focused regression coverage for direct file edges, cross-file calls, aggregation, and directory containment.

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported join and DISTINCT-aggregation failures are no longer present, and no blocking failure remains.

Important Files Changed

Filename Overview
src/features/export.ts Derives file-level edge IDs from the already-exported file-node set after SQL aggregation, resolving the previously reported join and row-expansion failures.
tests/graph/export.test.ts Adds regression tests for joinable IDs, preserved path fields, cross-file call aggregation, and explicit null directory endpoints.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  E["Aggregated file-level edge<br/>source/target paths"] --> M["Map exported file paths<br/>to nodes[].id"]
  M --> I["Add sourceId/targetId"]
  I --> F["File endpoint: numeric node ID"]
  I --> D["Directory endpoint: null"]
  E --> P["Preserve source/target paths"]
Loading

Reviews (2): Last reviewed commit: "fix(export): resolve sourceId/targetId a..." | Re-trigger Greptile

Comment thread src/features/export.ts Outdated
let edges = db
.prepare(`
SELECT DISTINCT n1.file AS source, n2.file AS target, e.kind, e.confidence
SELECT DISTINCT n1.file AS source, n2.file AS target, n1.id AS sourceId, n2.id AS targetId, e.kind, e.confidence

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 File edge IDs break joins

When a cross-file edge connects function or symbol nodes, sourceId and targetId contain those raw endpoint IDs even though nodes contains only file nodes, causing the advertised ID-based join to fail; including the raw IDs in DISTINCT also expands formerly collapsed file-level edges into parallel rows.

Fix in Claude Code

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

1 functions changed → 2 callers affected across 2 files

  • exportJSON in src/features/export.ts:330 (2 transitive callers)

…ndpoints (#2144 review)

The previous fix pulled sourceId/targetId from the edge query's own
n1.id/n2.id — but for a cross-file calls/receiver/etc. edge, those are
the edge's ACTUAL endpoints (function/class/... nodes), not the file
nodes this payload's nodes[] array contains. That both failed to
resolve against nodes[].id for the common case and widened this
query's DISTINCT aggregation, since different function-pairs between
the same two files would produce separate rows instead of collapsing
into one file-level edge.

Fix: look sourceId/targetId up from the already-fetched file-kind
nodes list by file path, entirely outside the SQL query, so the
existing DISTINCT aggregation is untouched. null (not omitted) when an
endpoint is a directory (contains edges), since directories have no
entry in this file-only nodes[] array to resolve against.

docs check acknowledged.

Impact: 1 functions changed, 2 affected
@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@carlos-alm
carlos-alm merged commit fc33049 into main Aug 8, 2026
23 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2144-exportjson-edge-schema branch August 8, 2026 05:38
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

follow-up: exportJSON edge source/target schema inconsistent between file-level and function-level modes

1 participant