← Back to Pull requests

fix(agent-compliance): keep the package name of a compound version specifier #4333

Closed
unknown closed this pull request without merging on Oct 15, 2026 18:47 UTC
View on GitHub
unknown unknown commented on Oct 15, 2026 17:36 UTC
Author

Related Issue


None. I found this while reading the supply-chain checks. The sections below are filled in as the template asks.

Problem & Solution


Problem. _parse_requirements_line splits a requirement into a name and a version specifier. It tries the operators in a fixed order (===, ==, ~=, !=, >=, <=, >, <) and splits at the first one that appears anywhere in the line. That is only right when there is a single specifier. With a compound specifier, the operator tried first can come later in the line, so the split lands in the middle:

| Line | name | specifier |
| --- | --- | --- |
| requests>=2.28.0,!=2.29.0 | requests>=2.28.0, | !=2.29.0 |
| requests<3,>=2.28.0 | requests<3, | >=2.28.0 |
| requests >= 2.28.0, != 2.29.0 | requests >= 2.28.0, | != 2.29.0 |

All three callers use that name:

  • check_requirements and check_pyproject report the unpinned-version / loose-constraint finding under the wrong package name, and run check_typosquatting on it. With the specifier attached, a typosquatted name is no longer similar enough to be flagged. reqeusts>=2.28.0,!=2.29.0 gives no typosquat finding, while reqeusts>=2.28.0 does.

  • scan_lockfile_drift looks for requests>=2.28.0, in the lockfile, so a package that is locked is reported as lockfile-drift.
  • Compound specifiers like >=X,!=Y and <N,>=M are common in real requirements files and pyproject.toml dependencies.

    Solution. Split at the leftmost operator, using one regex over the same operators (longest first, so === is not read as ==). The name is requests, and the specifier is the whole >=2.28.0,!=2.29.0. Single-specifier lines split the same way as before. _PEP508_PINNED still decides pinning from the full specifier, so requests!=2.30.0,==2.31.0 counts as pinned.

    Impact on Your Work


    A SupplyChainGuard scan (check_requirements, check_pyproject, scan_directory, scan_lockfile_drift) of a project that uses compound specifiers reports findings under names like requests>=2.28.0,, raises false lockfile-drift findings, and misses typosquats written that way.

    Timeline


    None.

    Alternatives Considered


  • packaging.requirements.Requirement. It parses PEP 508 fully, including extras, markers and URLs, but it would add a dependency to agent-compliance (its dependencies are pydantic, pyyaml and click), and it raises on lines the current parser tolerates. A one-line split fix keeps the current behavior for everything else.

  • Also stripping extras (pkg[extra]>=1) and parenthesized specifiers (pkg (>=1)). Both still keep extra characters in the name. They are separate problems, so I left them out to keep this PR small.
  • Type of Change


  • Bug fix (non-breaking change that fixes an issue)
  • Package(s) Affected


  • agent-compliance
  • Testing


    Unit Testing


    New tests in tests/test_supply_chain.py:
  • TestCheckRequirements::test_compound_specifier_keeps_package_name, parametrized over requests>=2.28.0,!=2.29.0, requests<3,>=2.28.0, requests >= 2.28.0, != 2.29.0 and requests>2,<3. Each gives exactly one finding, unpinned-version for requests with the full specifier.

  • TestCheckRequirements::test_compound_specifier_with_exact_pin_passes: requests!=2.30.0,==2.31.0 gives no findings.

  • TestCheckRequirements::test_compound_specifier_typosquat_flagged: reqeusts>=2.28.0,!=2.29.0 is flagged as typosquat for reqeusts.

  • TestCheckPyproject::test_compound_specifier_keeps_package_name: one loose-constraint finding for requests.

  • TestScanLockfileDrift::test_compound_specifier_found_in_lockfile: no drift when the lockfile has requests==2.31.0.
  • Six of these fail on main. requests>2,<3 and the exact-pin case already pass on main, because there the first operator tried is also the leftmost one. They are there to pin that behavior. tests/test_supply_chain.py has 89 passing.

    Manual Testing


  • agent-compliance tests/: 474 passed, 3 skipped. 13 tests in test_agt_cli.py and test_lint_policy.py fail the same way without this change in my environment, because agent_control_specification and the installed toolkit distribution aren't available. I skipped test_policy_replay_metadata.py for the same import reason.

  • ruff check reports no new findings on the changed files. supply_chain.py and the test file already have findings on main (import order, Optional), and I left those alone. cspell is clean on the added lines.
  • Checklist


  • I have linked a related issue above, or completed "Problem & Solution", "Impact on Your Work", and "Alternatives Considered"

  • My code follows the project style guidelines (ruff check)

  • I have added tests that prove my fix/feature works

  • All new and existing tests pass (pytest). The new tests and test_supply_chain.py pass; the unrelated environment failures are listed above.

  • I have updated documentation as needed (CHANGELOG)

  • I have signed the Microsoft CLA
  • Attribution & Prior Art


  • This contribution does not contain code copied or derived from other projects without attribution

  • Any external projects that inspired this design are credited in code comments or documentation

  • If this PR implements functionality similar to an existing open-source project, I have listed it below
  • AI Assistance


  • I can explain every meaningful change in this PR: what it does, why, and what tradeoffs were considered

  • I have run tests and verification appropriate for this change

  • No part of this PR was autonomously submitted by an AI agent without my review

  • I have not used AI to generate review comments on others' PRs
  • I used Claude Code (Claude Opus) to help find the bug and draft the fix and tests. I reviewed the full diff and will handle review comments myself.

    IP, Patents, and Licensing


  • This contribution does not implement patent-pending or patent-encumbered techniques

  • This contribution does not require an NDA or licensing agreement to understand or use

  • Any AI tools used have terms compatible with the MIT License
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: MohammadHaroonAbuomar Review duration: 70m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4333"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%