Repository navigation
Commit fb790dc
authored
* fix(python): resolve module imports to files and aliased module calls (#2387)
Python emitted zero `imports` edges, leaving `deps`, `impact` and `map`
blind on every Python repo, and `import lib as L` + `L.f()` resolved to
nothing, so the callee was reported as dead code.
Two defects sat behind that:
1. Neither resolver had a Python branch. A dotted module path is not a
filesystem path, so it fell through to the bare-specifier fallback and
was echoed back unchanged, matching no file node. Python's relative
imports share JS's leading-dot spelling but mean "climb the package
tree", so they were mis-resolved by the generic relative branch too.
2. The extractor put the alias in `Import.source` for `import lib as L`,
which can never resolve to a file, and `import a, b` collapsed into one
record naming only `a`.
Resolution derives the import root from package layout — walk up while
each level has `__init__.py` — so the PyPA "src layout" and a flat layout
work under one rule with no configuration, and honours pyproject-declared
roots (`pythonpath`, `package-dir`, poetry `from`, setuptools `where`) for
roots no convention implies.
Module bindings are now recorded in a new `namespaceBindings` field, which
call resolution reads to resolve `L.f()` as "f, as declared in the module L
refers to". `from pkg import submod` is resolved as a submodule when
`pkg/submod.py` exists, so it both binds a namespace and depends on the
module that actually changed rather than only on `pkg/__init__.py`.
Mirrored in crates/codegraph-core; both engines verified to produce
identical edge sets on the fixtures.
* fix(roles): classify Python __main__ entrypoints as entry (#2392)
Role classification recognized neither of Python's canonical entrypoint
conventions, so a repo whose only entrypoints are Python reported zero
`entry` symbols and `codegraph roles --role entry` came back empty —
precisely the "where does this start?" question a new agent asks first.
Neither existing signal could see them: Python has no `export` keyword, and
a guard can sit in any file (`app/oio.py:1786` on data-ingestion-pipe), so
no path pattern covers it either. The convention is a property of the call
site, not the declaration — a guard routinely invokes a `main` imported
from another module — so the extractor flags the call and the build sets a
new `nodes.entrypoint` column on whatever that call resolves to.
Covered: a call inside an `if __name__ == "__main__":` block anywhere, and
a module-level call in a `__main__.py` (`python -m pkg`). Both require
module level — a call nested in a function the module defines is invoked by
that function, not by the runtime.
Entrypoints are also seeded as reachability roots, so the transitive
dead-code pass no longer treats a `main()`-only call tree as a dead-code
candidate.
The column is added in the idempotent ensure-columns block rather than as a
numbered migration: a bare ALTER ... ADD COLUMN is not replay-safe against a
database stamped back to an earlier schema_version.
Mirrored in crates/codegraph-core; both engines verified to agree on the
entrypoint flag and the resulting roles.
Console-script entrypoints (`[project.scripts]`) are the third convention,
tracked as a follow-up in #2408.
* fix(roles): scope entrypoint marking to Python files, clear stale cross-file attribution (#2411)
Addresses two issues found in Greptile review of #2411:
- mark_entrypoint_targets ran an UPDATE-with-JOIN for every file in the
build, even though only the Python extractor ever flags a call as an
entrypoint. On a full build of this repo (954 files, effectively none
Python), that showed up as a 66% full-build regression in the
pre-publish benchmark gate (4844ms -> 8032ms, threshold 25%). Scoping
the clear/mark queries to `.py` files only is always correct (no other
extractor ever sets `call.entrypoint`) and restores full-build time to
parity with the pre-#2392 baseline (measured locally: 1986ms vs the
4844ms baseline, native engine, dist build).
- Clearing a stale `entrypoint` flag was keyed on the file's *current*
outgoing `calls` edges, which cannot find a target declared in a
*different* file once that file's guard call is deleted or renamed: the
edge is already purged (as part of reprocessing the changed file) by
the time the clear query runs. Added `nodes.entrypoint_source_file`, set
whenever a target is marked and read back (not re-derived from edges)
when clearing, so the clear survives the edge's lifecycle.
- That fix alone left `nodes.role` stale even though `nodes.entrypoint`
cleared correctly: incremental role classification only reclassifies
changed files plus neighbours discovered via a live-edge join, and a
cross-file entrypoint target is invisible to that join for the same
reason the clear query was — the connecting edge may have just been
deleted. mark_entrypoint_targets now returns every touched target's
file, which run_role_classification folds into the incremental
classification scope alongside removal_reverse_deps (same class of gap
as #1027's removal-reverse-deps seeding).
Single-file attribution (one entrypoint_source_file per target) doesn't
handle two different files both legitimately claiming the same target as
their entrypoint; tracked as a follow-up (#2419) rather than solved here
with a many-to-many table, since it needs a second target to legitimately
share an entrypoint call name.
docs check acknowledged: bug fix only, no new language/CLI/architecture surface.
* fix(extractors): exclude nested __main__ guards from entrypoint detection (#2411)
Greptile review finding on #2411: a `__main__` guard syntactically nested
inside a function or class definition is only executed if and when that
function is later called — never automatically by the runtime — but
visit_entrypoint_calls treated its consequence as module-level regardless.
The bug: `guarded` is `false` both at true module level (before any guard
is seen) and inside a nested def, so the guard-recognition branch had no
way to tell those two situations apart — it sets `guarded`, it doesn't
read it.
Adds `at_module_level`, a second flag that starts `true` and (unlike
`guarded`) never turns back on once a function/class boundary is crossed.
A guard's consequence is now only recognized while `at_module_level` holds.
docs check acknowledged: bug fix only, no new language/CLI/architecture surface.
* fix(roles): mirror Rust's entrypoint scope, staleness, and role-scope fixes (JS/WASM) (#2411)
TS/WASM-engine mirror of the same fix landed for the native engine:
- Scope markEntrypointTargets's clear/mark statements to `.py` files —
call.entrypoint is only ever set by the Python extractor, so running
them for every file was a guaranteed no-op for anything else and the
source of the 66% full-build regression in the pre-publish benchmark
gate (measured locally: 6350ms dev vs the 15537ms wasm baseline —
restored to well under baseline, not just under threshold).
- Add nodes.entrypoint_source_file (migrations.ts) and use it to clear a
stale entrypoint flag, instead of re-deriving the target from the file's
current outgoing `calls` edges — which can't find a target declared in
a *different* file once the guard call that pointed to it is deleted or
renamed, because that edge is already purged by the time the clear
query runs.
- Add PipelineContext#entrypointTouchedFiles, populated by
markEntrypointTargets and folded into classifyRoles's incremental file
scope: a touched target's own file is frequently not one of the
reparsed files, and classifyNodeRolesIncremental's neighbour-expansion
join can't discover it either, for the same live-edge-only reason the
clear query couldn't. Without this, nodes.entrypoint clears correctly
but the cached nodes.role for the same row stays stale at "entry".
docs check acknowledged: bug fix only, no new language/CLI/architecture surface.
Impact: 4 functions changed, 12 affected
* fix(extractors): exclude nested __main__ guards from entrypoint detection, JS/WASM (#2411)
TS/WASM mirror of the Rust fix: a `__main__` guard syntactically nested
inside a function or class is only executed if and when that def is later
called, never automatically by the runtime, but collectEntrypointCallLines
treated its consequence as module-level regardless — `guarded` reads
`false` both at true module level and inside a nested def, so the branch
that recognizes a guard had no way to tell those two situations apart.
Adds `atModuleLevel`, a second flag that starts `true` and (unlike
`guarded`) never turns back on once a function/class boundary is crossed.
A guard's consequence is now only recognized while it holds.
docs check acknowledged: bug fix only, no new language/CLI/architecture surface.
Impact: 2 functions changed, 5 affected
* test: cover nested __main__ guard exclusion and cross-file entrypoint staleness (#2411)
Regression coverage for the two Greptile-review fixes on #2392, run
against both engines (native and wasm) via the existing describe.each:
- a guard nested inside a function, and one nested inside a class, must
not be treated as module level;
- an incremental rebuild that deletes a guard whose target lives in a
*different* file must clear both nodes.entrypoint and nodes.role on
that target, not just the raw flag.
docs check acknowledged: test-only change.
* fix(extractors): recognize a guard nested in a module-level class body (#2411)
Greptile review finding: a class body, unlike a function body, is a
normal statement sequence Python executes immediately while evaluating
the `class` statement, so a guard directly inside a module-level class
body runs exactly when the module does. The at_module_level/atModuleLevel
fix landed earlier in this same review round treated class_definition the
same as function_definition for "leaves runtime scope", which wrongly
excluded this case (and, on inspection, so did the pre-existing `guarded`
flag itself, whose reset also included class_definition — the same class
of bug repo-wide, not something the at_module_level addition introduced).
Both flags now only reset on function_definition. A guard nested inside a
class defined inside a function is unaffected and stays excluded — the
class's own body only runs once that function is called.
docs check acknowledged: bug fix only, no new language/CLI/architecture surface.
Impact: 2 functions changed, 5 affected
* fix(roles): clear entrypoint attribution owned by a deleted file (#2411, #2425)
Greptile review finding, matching a follow-up I had already filed as
#2425 before this review round flagged it independently:
mark_entrypoint_targets/markEntrypointTargets only iterates fileSymbols —
the files actually reparsed this build — to clear a stale entrypoint flag
when its attributing call is edited or removed from an existing file. A
file that is deleted outright is never a member of fileSymbols in any
build, so that clear path never runs for it: a cross-file target
attributed to a deleted guard file kept entrypoint=1/role="entry"
indefinitely.
Added clear_entrypoint_attribution_for_removed_files (Rust) /
clearEntrypointAttributionForRemovedFiles (TS), called from the same
pre-purge point as the existing capture_removed_file_neighbors /
captureRemovedFileNeighbors (#1839) — the last point a removed file's
owned data is still live evidence. Returns the cleared targets' files,
folded into the same incremental role-reclassification scope
removal_reverse_deps/entrypointTouchedFiles already feed.
docs check acknowledged: bug fix only, no new language/CLI/architecture surface.
Impact: 4 functions changed, 6 affected
* test: cover module-level class guards and file-deletion entrypoint staleness (#2411)
Regression coverage for the two Greptile findings addressed in the
preceding two commits, run against both engines:
- a guard nested inside a module-level class body must be marked entry;
one nested inside a class defined inside a function must not;
- deleting a guard's source file outright (not just editing it) must
clear the cross-file target's entrypoint flag and role the same way
editing the guard already did.
docs check acknowledged: test-only change.
1 parent 12ec6a3 commit fb790dc
16 files changed
Lines changed: 1264 additions & 12 deletions
File tree
- crates/codegraph-core/src
- db
- domain/graph/builder
- stages
- extractors
- graph/classifiers
- src
- db
- domain/graph/builder
- stages
- extractors
- features
- graph/classifiers
- tests/integration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
921 | 921 | | |
922 | 922 | | |
923 | 923 | | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
924 | 955 | | |
925 | 956 | | |
926 | 957 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
277 | 293 | | |
278 | 294 | | |
279 | 295 | | |
| |||
437 | 453 | | |
438 | 454 | | |
439 | 455 | | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
440 | 579 | | |
441 | 580 | | |
442 | 581 | | |
| |||
447 | 586 | | |
448 | 587 | | |
449 | 588 | | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
450 | 597 | | |
451 | 598 | | |
452 | 599 | | |
453 | 600 | | |
454 | 601 | | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
461 | 609 | | |
462 | 610 | | |
463 | 611 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
881 | 881 | | |
882 | 882 | | |
883 | 883 | | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
884 | 933 | | |
885 | 934 | | |
886 | 935 | | |
| |||
1577 | 1626 | | |
1578 | 1627 | | |
1579 | 1628 | | |
| 1629 | + | |
| 1630 | + | |
1580 | 1631 | | |
1581 | 1632 | | |
1582 | 1633 | | |
| |||
1982 | 2033 | | |
1983 | 2034 | | |
1984 | 2035 | | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
1985 | 2099 | | |
1986 | 2100 | | |
1987 | 2101 | | |
| |||
0 commit comments