Skip to content

Conversation

@AmberArcadia
Copy link
Member

Summary

This PR fixes a critical bug in the APK resolver that was causing numpy and pytorch packages to fail building in Wolfi/Chainguard. The resolver wasn't correctly handling version constraints when packages were found via their provides entries.

The Problem

When migrating from py3-numpy to versioned packages like py3.12-numpy, we hit an issue:

  1. Package structure:

    • py3.12-numpy (version 2.1.0) provides py3-numpy=2.1.0
    • py3.12-numpy (version 1.26.4) provides py3-numpy=1.26.4
    • PyTorch requires py3-numpy<2.0
  2. The bug:

    • When resolving py3-numpy<2.0, APK would find packages providing py3-numpy
    • But it incorrectly checked the package's own version (e.g., py3.12-numpy version 2.1.0) against the constraint
    • It didn't check the version specified in the provides clause (py3-numpy=2.1.0)
    • Result: APK couldn't find ANY package satisfying py3-numpy<2.0, even though py3.12-numpy-1.26.4 provides py3-numpy=1.26.4

The Solution

This PR adds context awareness to the package filtering logic:

  1. Query context tracking: Added queryName to track which name was used to find packages
  2. Proper version checking:
    • When querying py3-numpy<2.0, only checks versions relevant to py3-numpy
    • Checks the version in the provides clause when a package was found via provides
    • Only checks the package's own version when querying by its actual name
  3. Backward compatibility: For provides without explicit versions, falls back to the package's version

Why This Matters

This fix is critical for:

  1. Unblocking builds: PyTorch and other packages depending on numpy can now build
  2. Python package migration: Enables migration from py3-* to py3.XX-* versioned packages
  3. Preventing future conflicts: Each Python version can have its own package versions without conflicts
  4. Proper constraint solving: APK can now correctly resolve complex version constraints on virtual packages

Testing

  • Added comprehensive test case TestNumpyVersionConstraintWithProvides that reproduces the exact scenario
  • All existing tests pass
  • Verified the fix handles:
    • Direct version constraints on provided names
    • Transitive dependencies with version constraints
    • Provides with and without explicit versions

Impact

This fixes the current build failures in:

And enables the planned migration away from py3-* packages as discussed in the incident.

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

AmberArcadia and others added 2 commits September 16, 2025 15:40
This fixes the issue where packages with version constraints weren't
properly resolved when the package name was provided by another package
with a version in the provides clause.

Problem:
- When resolving constraints like `py3-numpy<2.0`, the resolver would find
  packages that provide `py3-numpy` (e.g., `py3.12-numpy` with version 2.1.0)
- The filterPackages function would incorrectly check the package's own
  version (2.1.0) against the constraint instead of checking the version
  specified in the provides clause
- This caused APK to fail to find packages even when valid versions existed

Solution:
- Added queryName context to filterPackages to track which name was queried
- Modified filtering logic to only check versions relevant to the queried name
- For packages found via provides, check the version in the provides clause
- For provides without explicit versions, fall back to package version

This enables proper migration from py3-* packages to versioned Python
packages (py3.XX-*) while maintaining correct dependency resolution.

Fixes the numpy/pytorch build failures in Wolfi/Chainguard packages.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@justinvreeland
Copy link

As far as I can tell the tests added here work with the current version of apko: #1862

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.

3 participants