Skip to content

fix(pkgmap): keep one manifest's candidates in its parser's order (regression from #2974) - #2989

Merged
DeusData merged 1 commit into
mainfrom
fix/pkgmap-keep-manifest-candidate-order
Nov 14, 2026
Merged

DeusData merged 1 commit into
mainfrom
fix/pkgmap-keep-manifest-candidate-order

Conversation

@DeusData

Copy link
Copy Markdown
Owner

What does this PR do?

Fixes a regression that #2974 introduced in the package map (commit cd318253e, mine).

That commit made the package map independent of worker scheduling by sorting every candidate of a package name by
depth and path before the first-wins insertion. The sort also reordered the candidates of one manifest: a
pyproject.toml pushes src/<name> first and <name> second, the first had always won, and after the sort the
shallower second one did, for every Python package. Imports that used to bind their own package then fell to the
same-name fallback.

Measured with the frozen call-graph metric, main before #2974 against main today against this branch:

Repo Before #2974 Main today This branch
fastapi 1,845 of 3,149 true pairs found; 3,323 of 3,397 judged edges correct 1,741; 3,219 1,845; 3,323
httpx 381 found; 752 of 762 correct 377; 748 381; 752
flask 425 found; 658 of 732 correct 423; 656 425; 658
pandas 9,379 of 9,776 correct 9,374 of 9,777 9,379 of 9,776

In flask the wrong binding is visible directly: examples/tutorial/tests/conftest.py does
from flaskr import create_app, and main today binds it to the celery example's create_app. On the 23 Python
truth repos this branch gives the pre-#2974 found and correct counts everywhere. The CALLS counts that still differ
from before #2974 (pydantic, matplotlib, airflow and a few smaller ones) are the same with and without this change
and come from #2977.

The fix

cbm_pkgmap_try_parse stamps each entry with the manifest that yielded it and its position among that manifest's
entries. The merge orders by package name, then the manifest's depth and path, then that position. Different
manifests are still ordered by the repository and not by the run, which is what #2974 was for: cli/cli gives 3,869
IMPORTS edges in 12 of 12 runs with this branch. One manifest's entries keep the order its parser chose.

Tests

Suite Test On main today
edge_imports ei_pkgmap_one_manifest_keeps_its_candidate_order (a pyproject.toml and a sibling's, handed to the merge in both worker orders) fails: the second candidate wins
edge_imports ei_python_example_project_import_binds_its_own_package (the flask shape, checked by the import's target file) fails: the import binds the sibling example

On main today edge_imports gives 88 passed, 2 failed; with the change edge_imports, pipeline, lang_contract
and registry give 755 passed, 0 failed under ASan and UBSan. The two #2974 tests for go.mod manifests pass
unchanged. clang-format on the changed lines, the memory-core and NOLINT lints. The full local ladder was not run.

Why #2974 did not catch it

Its tests covered go.mod manifests only and no Python repository was scored before the merge. The scoring run that
found this now exists as a script and is run before a resolver or package-map change merges.

Checklist

  • Every commit is signed off (git commit -s)
  • Tests pass locally (make -f Makefile.cbm test): only the affected suites were run locally, PR CI runs the rest
  • Lint passes on the changed files
  • New behavior is covered by a test (reproduce-first for bug fixes)

cd31825 made the package map independent of worker scheduling by
sorting every candidate of a package name by depth and path before the
first-wins insertion. That also reordered the candidates of ONE manifest:
a pyproject.toml pushes src/<name> first and <name> second, the first had
always won, and after the sort the shallower second one did, for every
Python package. Imports that used to bind their own package then fell to
the same-name fallback: in flask, `from flaskr import create_app` in
examples/tutorial bound the celery example's create_app.

The dispatcher now stamps each entry with the manifest that yielded it and
its position among that manifest's entries, and the merge orders by package
name, the manifest's depth and path, and that position. Different manifests
are still ordered by the repository, not by the run; one manifest's entries
keep the order its parser chose.

ei_pkgmap_one_manifest_keeps_its_candidate_order hands a pyproject.toml and
a sibling's to the merge in both worker orders;
ei_python_example_project_import_binds_its_own_package indexes the flask
shape and checks the import's target file. Both fail without this change.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData
DeusData merged commit cdfdf26 into main Nov 14, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant