Skip to content

Pin a vendored Maven patch in the modules that select its version - #2101

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
fix/maven-pin-follows-mediationfrom
fix/maven-pin-per-module
Nov 16, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
fix/maven-pin-follows-mediationfrom
fix/maven-pin-per-module

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #2100 (review that one first; this branch holds its commits plus one).

What was wrong

A vendored pin was only ever written in a local root pom, which every module of the reactor inherits. In a reactor whose modules select different versions of one artifact that left two bad choices:

Shape Maven resolved before after a 5.1.0 scan --mode vendored
V3: module a declares jackson-databind 2.7.9.2, module b gets 2.9.10 through another artifact a 2.7.9.2 / b 2.9.10 a patched, b downgraded to 2.7.9.2-socket (the pin in the root pom is inherited by b)

#2100 stops the downgrade by not pinning a root one of whose modules selects another version. That is safe but leaves a module unpatched when it selects the base version only through other artifacts and a sibling selects something else (refused as nothing_wired), and a patch for the sibling's version cannot be wired either.

What changed

The pin now goes in the highest pom whose modules all select the patch's base version or do not resolve the artifact:

  • the local root when every module that inherits it agrees (what a single-module project and a uniform reactor get, as before);
  • else the poms below it that do, down to one module's own pom.xml.

So a module that resolves another version is never reached by a pin, and patches for two versions of one artifact are each pinned in the modules that select them. A pin an earlier run wrote in a pom that would move a module is taken out and written where it belongs. A pom that manages the artifact itself takes no pin (its own entry is rewritten when it names the base version). A module whose selection is not certain gets no new pin and keeps the one it has. The fallback <repository> stays in each local root. Revert, vendor --check and repair already read pins from every pom of the reactor. VEX liveness did need a change (review finding 2, below).

A literal <base>-socket.<hex8> that belongs to another patch of the same artifact is no longer reported as conflicting_literal_version when a second patch is planned: it is that other patch's wiring.

The version_not_selected reason #2100 added to vendor_jvm_degraded is gone again: there is nothing degraded about a sibling that selects another version.

Outcomes that change

  • V3: module b keeps resolving 2.9.10 (Pin a Maven patch only where Maven selects its base version #2100 already) and a module that selects the base version only transitively is now patched instead of refused.
  • Reactors whose modules disagree: exit 1 nothing_wired in Pin a Maven patch only where Maven selects its base version #2100 becomes exit 0 with the pin in the modules that select the base version.
  • Reactors whose modules all agree, and single-module projects: unchanged, byte for byte.
  • A parent pom that resolves the base version itself above a module that resolves another: no pin in the parent, vendor_jvm_degraded reason pin_would_move_module naming both. When that parent is the only pom that selects the base version: the new benign skip vendor_maven_pin_would_move_module, exit 0, nothing written (it was nothing_wired, exit 1).
  • A root that a conflicting declaration rules out: the modules below it that select the base version are now pinned (it was nothing_wired, exit 1, unless an unrelated module happened to select another version).
  • A sibling that declares another version itself no longer raises conflicting_literal_version when the selection says it resolves that version.
  • selection_undetermined is one event per plan, naming the first module and counting the rest.
  • VEX: a vendored Maven patch is attested only when every module that resolves the base version, or may, is wired. Reactors where a pin sits in one module and a sibling resolves the base version unpatched, or cannot be told on the machine that runs vex, lose the attestation, with the module named. vendor --check is unchanged.

Tests

  • Planner unit tests (vendor::jvm::maven_reactor): a root pinned when all agree; the pin in the module when a sibling selects another version, with its byte-exact revert; the pin in a shared intermediate parent; patches for two versions each pinned where they are selected and neither plan undoing the other; a misplaced root pin moved to its module; an undetermined module held.
  • Real Maven: maven_vendored_reactor_pins_each_module_at_the_version_it_selects in e2e_vendor_maven_build (already in the e2e leg). A parent with three modules: a reaches the base version two levels down, b a newer version through another artifact, c declares the base version itself. Maven resolves each module before and after. After the first patch a and c resolve the patched jar and b resolves the same bytes as before; after a second patch for b's version, b resolves its patched jar too. Then a no-op third run, vendor --check, and a revert that restores every pom.

What I ran

Locally on macOS (arm64), Maven 3.9.16, JDK 26; every cargo command through the machine-wide lock with CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 -j4. With every code change of this head (104f968b0) in place:

  • cargo fmt --all; cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • cargo test -p socket-patch-core --lib: 7809 passed, 0 failed.
  • cargo test -p socket-patch-cli --no-fail-fast --test vendor_jvm_cli --test contract_gradle_codes --test maven_sidecar_cli --test in_process_scan --test in_process_get_hosted_ecosystems --test in_process_remote_ecosystems_apply --test in_process_rollback_all_ecosystems --test e2e_maven --test scan --test rollback --test vendor --test in_process_vendor --test e2e_vex_vendor --test e2e_vex_redirect --test e2e_vex_lockfile --test cli_scan_silent --test ecosystem_dispatch_e2e: all passed.

That run failed one new real-Maven test, on the test's own setup (the local repository did not yet hold the pom that makes module b's new selection certain). After that test-only fix, on the committed head:

  • cargo test -p socket-patch-cli --no-fail-fast --test e2e_redirect_maven_build --test e2e_vendor_maven_build --test contract_gradle_codes --test vendor_jvm_cli -- --include-ignored (real Maven): 2, 7, 1 and 32 passed.

Not run: the whole workspace test suite, the docker suites, Windows and Linux, and Maven lines other than 3.9.16.

After the review of #2100

This branch merges #2100's review fixes (no rebase, nothing force-pushed). What they mean here:

  • Placement is decided once. A patch the poms already wire keeps every pin in every pom and gets no new one, on any machine; vendor --check takes the committed pins as they are. The placement above is what a first vendoring writes.
  • The exception is a pin that is certain to move a module to another version than Maven selects for it: the pins are then placed afresh for the build as it is (a_pin_that_moves_a_module_goes_to_the_module_it_belongs_in).
  • A held pom still moves an older patch's pin to the new suffix.
  • The finding about a certainly selected module beside an undetermined one cannot leave a patch unwired here: the selected module gets a pin of its own. The undetermined skip remains for a parent that resolves the artifact itself while a child cannot be told (a_plan_held_back_by_one_undetermined_module_is_a_skip).

Review of this PR (/code-review high) and what was done

All ten findings were confirmed against the code; all are fixed here.

  1. A pom was held while one of its modules was certain to resolve another version (regression against Pin a Maven patch only where Maven selects its base version #2100): fixed. Only a pom with doubt and no dissent is held; a root a declaration rules out is never held. Tests: a_pin_that_moves_a_module_is_not_held_for_an_undetermined_sibling, and the real-Maven maven_vendored_parent_pin_goes_when_a_module_moves_on_and_reverts_clean (Maven builds b on the forced version before the run and on its own version after, while a cannot be told).
  2. VEX attested while a module built the unpatched jar: fixed, by withholding. unwired_modules asks, per reactor module, whether the patch reaches it (a pin or the project's own management at the patched version on its chain, or a declaration at it); an unreached module that resolves the base version, or whose selection cannot be told, withholds the attestation and is named. This reads the local repository, so vex can answer differently on a machine that never resolved the project (it withholds there); vendor --check deliberately does not ask. Not exempted: a pom-packaged parent that resolves the base version itself (finding 4) also withholds. Test: a_module_left_without_the_patch_withholds_attestation.
  3. Revert left an empty management block where a pin had been moved out: fixed. The removal carries the section's creation record into the new ledger entry. The real-Maven test above reverts and compares all four poms byte for byte.
  4. Silent no-pin for a parent above a dissenting module: Maven's management is always inherited, so no managed pin patches the parent and leaves the child alone. A second, shielding entry in the child (managing the version it already selects) would work, but it is a new kind of edit with its own ledger records, revert and interplay with a later patch for that version; I did not add it. The parent takes no pin and the plan says exactly why, naming the module and its version; alone it is the benign skip vendor_maven_pin_would_move_module with nothing written. A parent pom is pom-packaged, so the modules that build artifacts are still each pinned. Test: a_parent_above_a_module_on_another_version_is_reported_not_pinned. Owner decision: whether to add the shielding entry.
  5. Spurious conflicting_literal_version: fixed. Test: a_sibling_declaring_another_version_is_no_conflict_under_a_selection.
  6. Warning flood: fixed, one line. Test: undetermined_modules_are_reported_in_one_line.
  7. A closed root was bypassed only by dissent: fixed, a closed root is descended like any other. Test: a_closed_root_does_not_keep_its_modules_from_their_pins.
  8. A plan without a selection pulled module pins up into the roots: fixed, it keeps the committed pins. Test: a_plan_without_a_selection_keeps_module_pins_where_they_are.
  9. Cost: each module's verdict is read once per plan and marked up its chain (Reactor::under); placement and the "does a pin move a module" test read those flags.
  10. Test duplication: stage is stage_all for one patch, the purl comes from the fixture, and the reactor fixture has one table.

Two of these also exist in #2100 on its own (a root pin the planner removes leaves its section behind on revert; a declaration-only wiring can be attested while a sibling is unpatched). I fixed them here only, since the stack lands together and #2100's CI was running.

After CI: the Linux failure of a_version_the_build_does_not_select_is_skipped_before_any_download was #2100's kept selection, checked by length and modification time instead of content; fixed there in cf3353c (see its review notes) and merged here as a8d8045.

Known gaps

  • Hosted mode still refuses multi-module reactors and ${property} versions (the third PR of the stack; not started).
  • VEX does not attest an entry while a module declares the artifact without a version and reads it from management outside the checkout at another version; that was already so for an unpinned root.
  • A parent pom that resolves the base version itself above a module on another version stays unpatched (finding 4).

Refs #595, #882.

🤖 Generated with Claude Code

A vendored pin was only ever written in a local root pom, which every
module of the reactor inherits. Where the modules select different
versions of one artifact, a root pin moved the ones that select another
version (5.1.0), or no pin was written at all and a module that selects
the base version only through other artifacts stayed unpatched (the
previous commit).

The pin now goes in the highest pom whose modules all select the patch's
base version or do not resolve the artifact: the local root when every
module that inherits it agrees, else the poms below it that do, down to
one module's own pom.xml. A module that resolves another version is
never reached by a pin, and patches for two versions of one artifact are
each pinned in the modules that select them. A pin an earlier run wrote
in a pom that would move a module is taken out and written where it
belongs. A pom that manages the artifact itself takes no pin, and a
module whose selection is not certain gets no new pin and keeps the one
it has. The fallback repository stays in each local root.

A literal <base>-socket.<hex8> of another patch of the same artifact is
no longer reported as conflicting_literal_version when a second patch is
planned, and the version_not_selected degraded reason is gone: a sibling
that selects another version is not a degradation.

Reactors whose modules agree and single-module projects are planned
byte for byte as before.

Refs #595, #882.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings in the determinism rule (pins stay where they were committed, on
every machine), the suffix update of a held pin, the undetermined skip,
the removal of a pin the build no longer selects, and the model fixes.

With per-module placement the rule reads: a patch the poms already wire
keeps every pin in every pom and gets no new one, unless a pin is
certain to move a module, in which case the pins are placed afresh. The
test for a plan one undetermined module holds back now uses a parent
that resolves the artifact itself, since a sibling that selects the base
version gets a pin of its own here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review fixes for the per-module placement of vendored Maven pins.

- A pom was held (its pin kept) whenever any module under it could not
  be told, even when another module under it was certain to resolve
  another version. A pin that moves a module now goes whatever its
  siblings are; only a pom with doubt and no dissent is held, and a
  root a declaration rules out is never held.
- vex attested a patch as soon as any pom wired it. A pin can sit in one
  module's pom, so the patch is now attested only when every module that
  resolves the base version (or may: its selection cannot be told) is
  reached by a pin, by the project's own management at the patched
  version, or by a declaration at it. `vendor --check` does not ask this.
- A pin moved out of a pom carries the record of the section the first
  run created for it, so the revert takes the empty shell out again and
  restores the pom byte for byte.
- A parent pom that resolves the base version itself above a module that
  resolves another cannot be pinned without moving that module, and
  Maven has no management that reaches a parent and not its children.
  It takes no pin and the plan says so (pin_would_move_module); when it
  is the only pom that selects the base version the patch is the
  vendor_maven_pin_would_move_module skip instead of nothing_wired.
- A sibling that declares another version itself is no
  conflicting_literal_version once the selection says it resolves that
  version.
- Undetermined modules are reported in one line, naming the first and
  counting the rest.
- A root a declaration rules out no longer keeps the modules below it
  from their pins: it is descended like a root with a dissenting module.
- A plan made without a selection keeps the pins the poms already hold,
  in whichever pom they are, instead of pulling them up into the roots.
- Each module is asked for its selection once per plan and the answer
  marked up its chain.
- Tests: one manifest staging helper, one table for the reactor fixture.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 16, 2026 22:37
@cursor

cursor Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes core Maven reactor vendoring, pin placement, and VEX attestation logic in multi-module builds; mistakes could leave modules unpatched or mis-pin versions, though extensive unit and e2e tests target the new paths.

Overview
Vendored Maven wiring no longer pins only at the reactor root. Dependency-management pins are placed in the highest pom whose subtree all agrees on the patch base version—local root when uniform, otherwise module (or intermediate) poms—so a sibling on another version is not downgraded. Stale root pins that would hold a module back are removed and rewritten where they belong; two versions of the same artifact can be vendored side by side in different modules.

New selection semantics: pin_would_move_module / benign skip vendor_maven_pin_would_move_module when only parent poms select the base version above a dissenting child; version_not_selected degraded reason removed; selection_undetermined collapsed to one event; socket-suffixed literals from another patch no longer trip conflicting_literal_version.

VEX now withholds Maven attestations unless every module that resolves (or may resolve) the base version is actually wired (unwired_modules), without changing vendor --check.

Docs (CLI_CONTRACT.md, maven-vendoring.md), planner unit tests, and real-Maven reactor e2e (maven_vendored_reactor_pins_each_module_at_the_version_it_selects, parent-pin migration + clean revert) cover the new behavior.

Reviewed by Cursor Bugbot for commit 104f968. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 104f968. Configure here.

});
if reactor.wired_before(patch) && !moves {
// (A local root a declaration ruled out stays ruled out.)
held.extend(reactor.scope.iter().filter(|rel| !closed(rel)).cloned());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Freeze path drops committed root pins

High Severity

When a patch is already wired and no pin is certain to move a module, every pom except those in unpinned or managed_roots is held, place() never runs, and a pin on a closed pom is deleted. management_unresolved closes a root from this machine's local repository, so a re-vendor of a uniform reactor can drop the committed root pin on a cold checkout and then treat the patch as unwired, which breaks the invariant that the same poms plan the same on every machine.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 104f968. Configure here.

…-module

Brings in the selection kept by the content of every read it was made
from (a pom rewritten to the same length within one tick of the file
system's clock was taken for the old one), which fixes the Linux failure
of `a_version_the_build_does_not_select_is_skipped_before_any_download`
on this branch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) merged commit a8d8045 into fix/maven-pin-follows-mediation Nov 16, 2026
12 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/maven-pin-per-module branch November 16, 2026 23:21
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Folded into #2100: that PR's branch was fast-forwarded to this branch's head (a8d8045), so the per-module placement, its review fixes and the selection-cache fix now land together with full CI. Nothing here has reached main yet; review #2100 instead.

🤖 Generated with Claude Code

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