Skip to content

Pin a Maven patch only where Maven selects its base version - #2100

Merged
Mikola Lysenko (mikolalysenko) merged 13 commits into
mainfrom
fix/maven-pin-follows-mediation
Nov 18, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 13 commits into
mainfrom
fix/maven-pin-follows-mediation

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

Scope of this PR

This PR also carries the per-module pin placement that was #2101. On 2026-11-16 this branch was fast-forwarded to that branch's head (a8d8045), so the selection model, the placement, both rounds of code-review fixes and the selection-cache fix land together and were run through full CI as one change. #2101's description has the placement details: the reactor case (module a patched, module b left on the version it resolves), the vendor_maven_pin_would_move_module skip, VEX withholding unless every module that resolves the base version is wired, and that round's review notes. Please review this PR as the whole change.

What was wrong

scan --mode hosted and scan --mode vendored could change which version of a dependency a Maven build resolves, exit 0, and say nothing about it. Reproduced with the released 5.1.0 and Maven 3.9.16 on the one live Maven patch (jackson-databind 2.7.9.2):

Shape Maven resolved before after a 5.1.0 scan
V1: 2.9.10 nearer the root, 2.7.9.2 deeper 2.9.10 2.7.9.2-socket (downgrade)
V2: 2.6.0 nearer, 2.7.9.2 deeper 2.6.0 2.7.9.2-socket (forced up)
V4: the project declares 2.9.10, 2.7.9.2 is transitive 2.9.10 unchanged, but vendored exited 1 saying Maven "keeps resolving 2.7.9.2"
V5: 2.7.9.2 has only a .pom in the local repository 2.9.10 2.7.9.2-socket; agent mode exited 1 "not found on disk"
V6: the only path to 2.7.9.2 is <exclusions>-excluded 2.9.10 2.7.9.2-socket
V7: no pom names 2.7.9.2; a range [2.9.0,2.9.10]; 2.7.9.2 cached by another project 2.9.10 2.7.9.2-socket

Two defects combined. The candidates are a superset of the build (every version any pom of the graph declares, and every cached version behind a range or an undefined property). And a <dependencyManagement> pin is a force: it makes every occurrence of the artifact that version, so pinning a version that lost mediation replaces the one that won.

What changed

The rule now: a patch of g:a:v is pinned only where Maven selects v already. A version no module selects is not part of the build: nothing is written, the run exits 0, and one line names the version Maven selects instead. A patch for the version that is selected is still looked up and applied.

  • A model of what Maven selects (crawlers/maven_selection.rs), read per module from the project's poms and the poms the local repository holds; Maven is never run. It follows Maven 3's resolver: own and inherited <dependencies>, compile/runtime non-optional transitives, <exclusions>, a declared version else the managed one (parent chain, then imported BOMs), the module's management over every transitive version, ranges through the cached maven-metadata-*.xml, and mediation with parents settled first (nearest wins, first declared on a tie, what a losing version depends on leaves the graph; ranges are hard requirements). Maven's version order and range grammar are in formats/maven/version.rs.
  • Every answer is certain or not. Not certain: a pom missing from the local repository, a property that is undefined or that a profile redefines, a profile with dependencies or management, a relocation, a dependency cycle, a range the cached metadata does not resolve, a module that cannot be read, a Maven 4 build. A version selected as the highest of a range is never pinned (the pin would freeze the range).
  • Hosted: the pom rewriter skips a dep the build does not select (redirect_maven_version_not_selected) and writes no new pin when the selection is not certain (redirect_maven_selection_undetermined).
  • Vendored: the patch is skipped before any download when no module selects its base version (vendor_maven_version_not_selected, a skipped event, exit 0). The planner pins a local root only when every module that inherits it selects the base version or does not resolve the artifact; vendor --check accepts the pins either answer writes.
  • A declaration that already names the base version is rewritten under any answer. That replaces a version where it stands and cannot move what resolves, so it does not need the model. Only new pins do.
  • Agent mode patches the cached jar in place under its own coordinates, so it cannot change resolution and stays as it was, except that a version directory holding a pom and no artifact is left out of an agent scan instead of failing it (V5).
  • The nothing_wired refusal no longer claims that Maven "keeps resolving" the base version (V4).

Outcomes that change

  • V1, V2, V6, V7 (hosted and vendored): exit 0 as before, but nothing is written and the output names the selected version. Before: a pin that changed the build.
  • V4 vendored: exit 1 (nothing_wired) becomes exit 0 with a vendor_maven_version_not_selected skip.
  • V5 agent mode: exit 1 ("1 not found on disk") becomes exit 0; the pom-only version is not scanned.
  • A transitive-only dep in a project whose poms are not in the local repository (never resolved there): hosted and vendored used to pin it; now they report it as undetermined with the remedy (mvn -q dependency:resolve, or declare the dep) and exit 0.
  • A project that does not resolve the artifact at all: used to be pinned through <dependencyManagement>; now skipped.
  • Existing refusals are unchanged: an unwired plan with a reason of its own (property_unresolved, conflicting_literal_version, ...) still refuses with nothing_wired.
  • In this PR alone, a reactor where module A reaches the base version only through other artifacts and a sibling B selects another version ends in the nothing_wired refusal, exit 1 (5.1.0 exited 0 with the pin that downgraded B). Pin a vendored Maven patch in the modules that select its version #2101 places the pin in A's pom and exits 0; the two are meant to land together.
  • A reactor where one module's selection cannot be told and nothing else wires the patch is the vendor_maven_selection_undetermined skip, exit 0, whatever the other modules select.
  • A pin for a version the build no longer selects (a dependency was added or upgraded after vendoring) is removed from the poms by the next run, which reports the not-selected skip and says the pin was removed. The ledger entry and tree stay for vendor --revert or scan --mode vendored --prune.
  • Pins are placed when a patch is first wired and kept where they are afterwards: a re-run never adds a pin to an already wired patch, on any machine. A patch first vendored where a module could not be told gets that module's pin only after vendor --revert and a new run.

Missing poms: the owner's answer to the PR shepherd's question

The PR shepherd asked whether a pom missing from the local repository below the winning declaration should hold a pin back: it may declare a version range, and a range binds at any depth. The owner answered yes on 2026-11-17 (option b). Commit 30a07a3.

  • The rule. A module that resolves through a file the local repository lacks never answers "selects the base version", so nothing new is pinned there. The files are the pom of an artifact the module resolves, a parent pom, an imported BOM, and the version list of a range. The run reports the selection_undetermined skip, exits 0, and names the missing file, so the remedy shown is mvn -q dependency:resolve.
  • The scenario from the question is now a_pom_missing_below_the_winner_leaves_it_undetermined: app → lib-a → victim 1.0, app → lib-y → lib-r with no cached pom. Before: selected, and pinned. Now: undetermined, naming lib-r.
  • "Selects another version" is still answered. It writes no new pin: the patch is skipped before any download, and a pin of that version already there is taken out. A fresh CI checkout that declares 1.11.0 still gets "Maven selects 1.11.0, not 1.10.0".
  • An earlier vendored pin does not hold the next patch back. A build pinned to a <base>-socket.<hex8> copy fetches the copy's pom and never the base version's. The model reads the project without its pins, so on a fresh machine it found no pom for the base version, and with the new rule that would have blocked every later patch in the module. The base version now reads the copy's pom when its own is not cached.
  • Unchanged. A declaration that names the base version is rewritten where it stands. The pom of a version that loses mediation casts no doubt. Each module of a reactor keeps its own answer. A range on a module of the reactor with no version list is that module's own doubt only.

Tests

  • Unit: the mediation model (crawlers::maven_selection, 30 tests: each rule above and each source of doubt), the version order and ranges, the reactor planner and the hosted rewriter under a selection, the pre-download refusal.
  • Real Maven, in the existing e2e leg (the two Maven suites already run there with Maven 3.9.16): maven_hosted_pins_follow_the_version_maven_selects in e2e_redirect_maven_build and maven_vendored_pins_follow_the_version_maven_selects in e2e_vendor_maven_build. Each resolves V1, V2, V4, V6 and V7 with Maven before and after the scan and asserts the resolved jars are identical and the project is byte for byte unchanged; the vendored one also runs the V5 agent scan. Both include the control where the base version is the one selected two levels down: the scan pins it, Maven resolves the patched jar, and the resolved set is the same once the -socket.<hex8> suffix is stripped. The fixture artifacts are generated in the test and served by its own wiremock server; nothing new is fetched from Maven Central or the patch service.

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. After the review fixes, on this branch (82d923985):

  • cargo fmt --all; cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • cargo test -p socket-patch-core --lib: 7799 passed, 1 failed (production_code_classifies_purls_through_from_purl, a lint on one line of the new crawler helper); fixed, then -- crawlers::: 844 passed. The same suite on the head of Pin a vendored Maven patch in the modules that select its version #2101, which contains this branch: 7802 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.
  • cargo test -p socket-patch-cli --no-fail-fast --test e2e_redirect_maven_build --test e2e_vendor_maven_build -- --ignored (real Maven): 2 and 5 passed.

Not run: the whole workspace test suite, the docker suites, Windows and Linux, and Maven lines other than 3.9.16 (the nightly tier runs these suites on 3.6.3, 3.8.9 and 4.0.0-rc-7).

For 30a07a3, same machine and settings:

  • cargo fmt --all --check; cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • cargo test -p socket-patch-core --lib: 7,818 passed, 0 failed.
  • The 17 CLI suites listed above: 1,194 passed, 0 failed.
  • The two real-Maven suites with --ignored (Maven 3.9.16): 2 and 5 passed.
  • The four tests of the new rule fail on the model as it was at 7795510 and pass on 30a07a3: a_missing_pom_leaves_no_base_version_selected, a_pom_missing_below_the_winner_leaves_it_undetermined, each_file_the_local_repository_lacks_holds_the_base_version_back, a_base_version_only_its_patched_copy_is_cached_for_reads_the_copy.
  • One existing test needed a fuller fixture: a_parent_on_no_registry_is_read_from_the_local_repository pins a transitive commons-text, and its local repository had no pom for commons-lang3, which commons-text depends on.

Review findings (/code-review high) and what was done

  1. Selected + undetermined mix ended in nothing_wired: confirmed, fixed. A plan left unwired only because a module's answer holds the root back is the undetermined skip; the line names the module. Test: a_plan_held_back_by_one_undetermined_module_is_a_skip.
  2. A held root kept an older patch's pin: confirmed, fixed. A pin of a superseded patch moves to the new suffix in place, held or not. Test: a_held_pin_moves_to_the_suffix_of_a_superseding_patch.
  3. vendor --check and a re-scan depended on the checking machine's ~/.m2: confirmed, fixed. Rule: pin placement is decided when a patch is first wired and the committed poms are its record. A later plan over poms that already wire the patch keeps every pin and adds none; vendor --check takes every pin, and every absence of one, as committed and never reads the local repository to judge placement. Only two things change a wired pom: a suffix update for a superseding patch (read from the poms alone) and the removal of a pin that is certain to move a module, which no correct run leaves. Tests: a_wired_patch_keeps_its_pins_on_every_machine and the real-Maven maven_vendored_wiring_checks_clean_and_stays_put_on_any_machine (vendored against a cold local repository, then checked, re-run and built against a warm one).
  4. PR 1 alone exits 1 for the A/B reactor: confirmed; stated under "Outcomes that change" (fixed by Pin a vendored Maven patch in the modules that select its version #2101).
  5. A pin already on disk was never removed once the build moved on: confirmed, fixed. The not-selected skip takes the pin out of the poms and says so; the pre-download refusal leaves such a patch to the backend so that it runs. Tests: unpin_plan_takes_the_pins_of_a_version_out and the real-Maven maven_vendored_pin_is_removed_when_the_build_selects_another_version (Maven resolves the forced version before, the selected one after, and the revert restores the user's pom byte for byte).
  6. Ranges read every cached maven-metadata-*.xml: confirmed, fixed. Only the lists of repositories the module's poms declare (plus central and local) count; a list cached for any other id leaves the range undetermined. Test: a_version_list_of_a_repository_the_build_does_not_declare_resolves_no_range.
  7. One remedy for every cause: confirmed, fixed. "Resolve the project" is offered only when a pom or version list is missing from the local repository; otherwise the line says resolving will not help and names the declaration that will. Test: the_remedy_fits_the_cause.
  8. A third copy of property lookup, bare ${version} read from the model first: confirmed, fixed. The model uses formats::maven::lookup_property; only the profile-doubt check is local. Test: a_bare_model_reference_reads_a_property_of_that_name_first.
  9. pom_only_version_dir duplicated holds_artifact, applied in the CLI on the runtime: confirmed, fixed. One holds_artifact with one list; the agent scan filters through MavenCrawler::with_an_artifact on the walk pool. Left as is, on purpose: apply and get with an explicit target keep their documented "matched no installed package" answer for a version with no jar, since the user named it.
  10. The selection was rebuilt per patch and stage, on the runtime: confirmed, fixed. MavenSelection::of keeps its last answer while every file it read (project poms and config, each repository pom looked up, each version list) is unchanged; the vendored gate and the hosted scan read it through spawn_blocking; vendor --check no longer reads it; hosted does not read it for a reactor root it refuses anyway.

After CI (Linux coverage (1), a real failure): the kept selection was checked by each file's length and modification time, so a pom rewritten to the same length within one tick of the file system clock was taken for the old one (and a version list rewritten in place, an uncommitted write of a vendored run, and a subproject Maven 4 discovers were not checked at all). Fixed in cf3353c: the walk notes every read it makes (the SHA-256 of the bytes or directory entries it went on to use, through the run's own readers), and a kept selection is given again only when repeating each read returns the same digest. Tests, each failing on the old check: a_file_rewritten_to_the_same_length_is_read_again, a_file_that_appears_is_read, a_write_the_run_has_not_committed_is_read.

Reviews of 30a07a3 (/code-review high, two rounds, nine findings each)

Fixed:

  • The cause was read from the message text (round 1), and a second cause in the same pom overwrote it. A missing parent pom plus a coordinate through a property that parent defines was reported as the undefined property and held nothing back. The models of management, dependencies and edges now carry the missing file beside the text. Test: the parent-pom case of each_file_the_local_repository_lacks_holds_the_base_version_back.
  • The first version withheld "selects another version" too (round 1). That dropped the skip before download on a fresh checkout, kept a stale pin above a module that had moved on, and made vex withhold a wired patch because of a sibling that declares another version. Only "selects the base version" is withheld now.
  • An earlier vendored pin blocked every later patch of its module on a fresh machine (round 2). Fixed by reading the copy's pom, as above. Test: a_base_version_only_its_patched_copy_is_cached_for_reads_the_copy.
  • The remedy was wrong when a missing file hid behind another cause (round 2): the line said resolving would not help. Every undetermined answer of such a module now names the missing file.
  • A range on a reactor sibling that was never installed counted as a missing file (round 2), which no mvn dependency:resolve fills. It is that module's own doubt, as before. Test: a_range_on_a_module_of_the_reactor_is_no_gap_in_the_local_repository.
  • The docs overstated the rule (both rounds): "anywhere in the graph", "no module", "never leads to a pin". Reworded in CLI_CONTRACT.md, docs/ecosystems.md, docs/design/maven-vendoring.md and the module doc.
  • Two redundant fallbacks in the new plumbing (round 2).

Tried and taken out:

  • Reading Maven's "not found" note for an artifact published without a pom. Round 1 pointed out that such an artifact now holds its module back for good, since no resolve ever creates the pom. I checked with Maven 3.9.16 that it builds the artifact as one with no dependencies and leaves <artifact>-<version>.pom.lastUpdated, and modelled that. Round 2 pointed out the note is specific to the machine: a private repository that answers 404 without credentials leaves the same note, and a pin made on it would be wrong where the pom is visible. The note is not read; see "Known gaps".

Not fixed:

  • The other unread causes keep the depth rule (both rounds): a relocation, a profile that declares dependencies, an undefined property, a version list cached for a repository the build does not declare. A range could hide below them too. See decision 6.
  • "Selects another version" stays certain in a module with a missing file, and it takes pins out (round 2). See decision 7.
  • A parent pom that is present but unreadable, or whose coordinates do not interpolate, is reported as not in the local repository (round 2). Older than this commit; it now holds the module back, which is the safe direction, and the line also offers the declaration remedy.
  • One cause type with a kind instead of paired fields (round 2). It would touch about forty sites of the model; not in this commit.

Decisions for the owner

  1. Declarations that name the base version are rewritten even when the selection is not certain, whether they sit in <dependencies> or in the project's own <dependencyManagement>. Replacing a version where it stands cannot change what resolves, so I did not limit it to direct declarations. Only new pins need a certain answer. Say so if a managed declaration should wait for a certain answer too.

  2. A version selected as the highest of a range is not pinned (reported as undetermined): a pin would freeze the range at that version.

  3. Maven 4: with a wrapper that pins Maven 4, or a model 4.1.0 pom, nothing is pinned on the model (its transitive dependency management differs). Without a wrapper the model assumes Maven 3.

  4. Vendored pins that 5.1.0 wrote in a build that does not select their version are now removed by the next vendored run (finding 5). Hosted pins carry no mark that tells them from the project's own management, so the model reads them as management and cannot find its own bad ones.

  5. Pins are never added to an already wired patch (finding 3). That is what makes a re-run a no-op on every machine, at the price that a module left unpinned by a first run on an unresolved project stays unpinned until vendor --revert and a new run.

  6. Causes that resolving the project does not change still cast doubt only from their depth down: a relocation, a profile that declares dependencies, an undefined property, a version list cached for a repository the build does not declare. The argument you accepted for missing poms applies to them as well. I left them because no command the user can run lifts the hold, and profiles that declare dependencies are common in published poms, so the cost in pins could be large. Say so if they should hold a module back too; it is a few lines.

  7. A module with a missing file still answers "selects another version", and that answer takes out a pin of the base version. If the missing pom hides a range that selects the base version after all, a correct pin is removed and the patch is not applied until the next run on a resolved machine. The other choice is to keep such pins until the project is resolved, which also keeps a stale pin that is moving the build. I ranked a build moved by a stale pin above a patch not applied.

  8. An artifact published without any pom holds its module back for good (see "Known gaps"). The alternative needs a way to tell "no repository has a pom" from "this machine could not see it".

Known gaps

  • After a pin is removed because the build moved on, the ledger entry and vendored tree are left behind (vendor --check reports the entry as no longer wired) until vendor --revert or scan --mode vendored --prune.
  • Vendored reactors where one module selects the base version only transitively and a sibling selects another version are not pinned by this PR (Pin a vendored Maven patch in the modules that select its version #2101, stacked on this one, places the pin in the module pom).
  • The selection is read again for each Maven patch of a vendored run (two or three walks of the project's poms per patch). A per-run cache is a follow-up.
  • A root that holds both a pom.xml and a Gradle build is not skipped as a whole (the Gradle half may still resolve the base version); only the planner's Maven pins follow the selection there.
  • Maven 4, profiles that add dependencies or management, relocations and cycles are reported as undetermined, not modelled.
  • Hosted mode still refuses multi-module reactors and ${property} versions.
  • An artifact that no repository has a pom for is a missing file to the model, so the module that resolves it gets no new pin, and mvn dependency:resolve does not change that. Declaring the patched artifact at the base version in the module's pom is the way through, and the line says so. Rare with artifacts from Maven Central, which requires a pom.
  • The other unread causes (decision 6) can still hide a version range below a nearer declaration.

Refs #595, #882.


Generated by Claude Code

A hosted or vendored scan could change which version of a dependency a
Maven build resolves and exit 0 without saying so. The candidates were a
superset of the build (every version any pom of the graph declares, and
every cached version behind a range or an undefined property), and a
<dependencyManagement> pin makes every occurrence of the artifact one
version. A patch for a version that lost mediation, was excluded, or was
only cached by another project therefore replaced the version that won:
a downgrade when the winner was newer, an upgrade when it was older.

A pin is now written only where Maven selects the patch's base version
already.

- crawlers/maven_selection reads what Maven selects in each module from
  the project's poms and the poms the local repository holds, without
  running Maven: own and inherited dependencies, compile/runtime
  non-optional transitives, exclusions, declared or managed versions (the
  module's management over every transitive one), ranges through the
  cached maven-metadata files, and mediation with parents settled first
  (nearest wins, first declared on a tie, what a losing version depends
  on leaves the graph). formats/maven/version holds Maven's version order
  and range grammar.
- Every answer is certain or not. A missing pom, a property that is
  undefined or that a profile redefines, a profile with dependencies or
  management, a relocation, a cycle, an unread module and a Maven 4 build
  are not certain, and nothing is pinned on them.
- Hosted: redirect_maven_version_not_selected when the build selects
  another version (or none), redirect_maven_selection_undetermined when
  it cannot be told and no declaration names the base version.
- Vendored: vendor_maven_version_not_selected, a skip decided before any
  download; the planner pins a local root only when every module under it
  selects the base version or does not resolve the artifact, and leaves a
  pin alone when it cannot tell. vendor --check accepts either answer.
- A declaration that already names the base version is rewritten under
  any answer: that replaces a version where it stands.
- Agent mode patches cached jars in place and is unchanged, except that a
  version directory holding a pom and no artifact is left out of an agent
  scan instead of failing it as a targeted patch not found on disk.
- The nothing_wired refusal no longer says Maven keeps resolving the base
  version.

Outcomes that change: the six shapes above exit 0 with nothing written
and one line naming the version Maven selects; vendored used to exit 1
on a project that declares another version itself; agent mode used to
exit 1 on a pom-only version; a transitive-only dependency of a project
whose poms are not in the local repository is reported as undetermined
instead of pinned.

Refs #595, #882.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The version_not_selected and selection_undetermined warnings lost the
line continuation in their format strings and carried a run of spaces
in the middle of the sentence. The planner test now compares the whole
warning.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Maven builds a pom that declares one dependency twice from its last
declaration, in the place of the first (and warns). The selection model
kept the first, which could call a version selected that Maven does not
select.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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>
Review fixes for the Maven selection work.

Determinism. Where the pins go is decided when a patch is first wired,
and the committed poms are the record. A later plan over poms that
already wire the patch keeps every pin and adds none, whatever the local
repository of that machine can tell, so one checkout plans the same
everywhere and a re-run is a no-op. `vendor --check` no longer judges
where a pin belongs: it takes every pin, and every absence of one, as
committed. Before, a project vendored where nothing could be told (the
declaration rewritten, no pin) drifted in `--check` and was rewritten by
a re-scan on a machine with a full local repository.

- A held pom still moves an older patch's pin to the new suffix: the
  tree the old suffix names is replaced by the same run.
- A plan left unwired because one module's answer holds the root back is
  the vendor_maven_selection_undetermined skip, whatever the other
  modules select. It used to be the nothing_wired refusal.
- A pin for a version the build no longer selects is taken out of the
  poms when the patch is skipped as not selected, and the skip says so.
  It used to stay and keep forcing that version.
- A range is resolved only on the version lists cached for the
  repositories the module's poms declare (and central and local). A list
  cached for any other repository id leaves it undetermined.
- The undetermined line names the remedy that fits its cause: resolving
  the project only when something is missing from the local repository.
- Property lookup goes through the shared lookup_property, so a bare
  ${version} reads a property of that name before the project's own.
- One artifact check for Coursier and Maven directories; the agent scan
  filters pom-only versions through the crawler, off the async runtime.
- The selection is read off the async runtime, kept between the stages
  and patches of one run while every file it read is unchanged, and not
  read at all for a hosted reactor root, which is refused whole.

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>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 16, 2026 22:11
@cursor

cursor Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes Maven hosted/vendored pinning semantics and POM writes, but failures are skips/warnings rather than silent downgrades; agent crawl filtering is a narrower behavioral tweak.

Overview
Maven hosted and vendored flows now read a static version-selection model (MavenSelection, plus formats/maven/version.rs) from project POMs and the local repository—without running Maven—and only write or keep pins when the build already resolves the patch’s base version. Otherwise the run stays exit 0 with new codes (redirect_maven_version_not_selected, redirect_maven_selection_undetermined, and vendored twins), and POMs are left unchanged (vendored can drop stale pins that would force an unwired version).

Hosted scan loads selection once on a blocking task and passes it into RewriteOptions for the Maven rewriter; agent scan filters crawled packages with MavenCrawler::with_an_artifact so POM-only local-repo dirs don’t fail as “not found on disk”. vendor --check treats committed POM wiring as authoritative instead of re-deriving placement from the machine’s ~/.m2.

CLI contract documents the selection rules and codes; e2e mediation suites (maven_mediation_common, hosted/vendored capstones) assert resolution and bytes stay the same when the base version isn’t selected.

Reviewed by Cursor Bugbot for commit 82d9239. 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 82d9239. Configure here.

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>
…olds

The selection of a project is kept between the calls of one process and
was given again while each file it was read from had the same length and
modification time. That is not the same as the same content:

- a pom rewritten to the same length within one tick of the file
  system's clock (a few milliseconds on Linux) has both unchanged, so the
  old selection was returned for the new pom. This is what failed on CI:
  `a_version_the_build_does_not_select_is_skipped_before_any_download`
  rewrites the project pom from 1.11.0 to 1.10.0 and asks again at once;
- a version list was checked by its directory's length and time, which
  rewriting a `maven-metadata-*.xml` in place never changes;
- a vendored run holds its writes to the project in memory until it
  commits them, and its readers answer from them: the selection read
  such a pom, the check looked at the file on disk;
- the subprojects Maven 4 finds by listing a directory were not part of
  the check at all, so one that appeared was not seen.

The walk now notes every read it makes of the file system (`Reads`): the
path, whether it was a file or a directory listing, and the SHA-256 of
the very bytes or entries it went on to use, through the readers the
check repeats. A kept selection is given again only when repeating each
read returns the same digest, so it cannot be older than the files: a
missing file, a listing, and an uncommitted write of the run are reads
like any other, and there is no gap between a read and its record. The
selection touches the file system only through the walk (a test holds
`maven_selection.rs` to that), and the one listing the walk does not
note, the scope queue's, asserts it is never made on a noting walk.

Reading the noted files again and hashing them costs a fraction of
parsing them and walking the graph.

Tests, each failing on the old check when run alone: a project pom, a
repository pom and a version list rewritten to the same length with no
delay and with the modification time put back; a pom, a version list and
a discovered subproject that appear; a pom written inside an open group
commit and read before it is committed. The selection fixture keeps its
own answer, so another test's selection no longer replaces it and hides
a stale one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…-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>
A range is a hard requirement at any depth: Maven's resolver backtracks
to a version inside it even when a plain version sits nearer the root.
A range the model could not resolve (its only version list is cached
for a repository the build does not declare, such as a settings.xml
mirror; it cannot be parsed; or no listed version is in it) became an
unread version that only cast doubt when it was no deeper than the
winner. A nearer plain version outside the range was then reported as
certainly selected, and hosted or vendored mode pinned it through
<dependencyManagement>, downgrading what Maven resolves.

Mark such edges as hard and make any of them leave the pick
undetermined. Also restore the spaces lost in the three unpin messages.

Assisted-by: Claude Code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeRJTv8HGEveVfgkPgS
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review found one silent-downgrade path, fixed in 7795510; one question for the owner before a final brief

Fixed (7795510). A range is a hard requirement at any depth: Maven backtracks into it even past a nearer plain version (a_range_overrules_a_nearer_version_outside_it). If the model could not resolve a range, it became an unread version, and that only cast doubt when it was no deeper than the winner. Common example: the only cached version list is maven-metadata-nexus.xml from a mirrorOf * mirror. Scenario: app → lib-a → victim 1.0 (depth 2), app → lib-y → lib-r → victim [2.0,3.0) (depth 3). Maven resolves 2.5. The model reported 1.0 as certainly Selected, so hosted and vendored mode would pin 1.0 in <dependencyManagement> and downgrade the build. Such edges are now marked hard and leave the pick undetermined. The new test an_unresolved_deeper_range_leaves_a_nearer_version_undetermined fails without the change. I also restored the spaces lost in the three unpin messages in vendor/maven_repo.rs ("would be removed").

Ran: cargo test -p socket-patch-core --lib -- crawlers:: vendor:: patch::redirect (4816 passed), cargo clippy --locked --workspace --all-features -- -D warnings (clean), and cargo fmt --check on the touched crate.

Question (agent:needs-human). The same gap remains, by design, for a pom missing from the local repository below the winner. a_missing_pom_leaves_only_what_it_could_change_undetermined asserts that a missing pom leaves only its own depth and deeper undetermined, "and nothing nearer". But a missing pom deeper than the nearest declaration can hold a range for the patched artifact. Maven then selects a version inside that range, while the model says the nearer version is certainly selected and pins it, which is a downgrade. Treating any missing pom below the module as doubt for every artifact would close this. It would also make most never-resolved projects report "undetermined" (the PR's V5-style cases), losing coverage. Which do you want: (a) keep the current trade-off (ranges in published poms are rare), or (b) any missing pom below the module leaves every pick undetermined?

Please answer and remove agent:needs-human. CI is running on 7795510; the review brief follows on the next shepherd run.


Generated by Claude Code

A version range is a hard requirement at any depth: Maven selects a
version inside it even past a nearer plain version. A pom the local
repository does not hold may declare such a range, so the nearest
version the model reads may not be the one Maven selects. The model
counted a missing pom as doubt only for artifacts declared at its depth
or deeper and called a nearer version certainly selected, and hosted
and vendored mode pinned it. With app -> lib-a -> victim 1.0 and
app -> lib-y -> lib-r (not cached) -> victim [2.0,3.0), Maven resolves
2.5 and the pin moved the build to 1.0.

A module that resolves through a file the local repository lacks (the
pom of an artifact it resolves, a parent pom, an imported BOM, the
version list of a range) now never answers "selects the base version",
so nothing new is pinned there until the project is resolved. The
reason given names the missing file, whatever else is in doubt, so the
remedy offered is the one that works. The owner chose this over
keeping the narrower rule (the PR shepherd's question on #2100).

What stays as it was:

- "Selects another version" is still answered. It writes no new pin:
  the patch is skipped before any download, and a pin of that version
  already there is taken out. A stale pin that moves the build is worse
  than a patch not applied, which is the most a hidden range can cost
  here.
- A declaration that names the base version is rewritten where it
  stands.
- The pom of a version that loses mediation casts no doubt.
- Causes resolving does not change (a relocation, an undefined
  property, a profile, a version list cached for a repository the build
  does not declare) cast doubt only from their depth down. The same
  range could hide there; closing that costs pins no command can win
  back, so it is left for a decision of its own.
- A range on a module of the reactor with no version list is that
  module's own doubt only: Maven lists it from the build.

A build pinned to a `<base>-socket.<hex8>` copy fetches the copy's pom
and never the base version's, so on a fresh machine an earlier vendored
pin would have held every later patch of its module back. The base
version now reads the copy's pom when its own is not cached.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] Owner's answer to the missing-pom question: (b). Implemented in 30a07a3.

The answer. The owner chose (b) on 2026-11-17: while a pom is missing from the local repository among what a module resolves, nothing new is pinned in that module.

What changed. A module that resolves through a file the local repository lacks (an artifact's pom, a parent pom, an imported BOM, the version list of a range) never answers "selects the base version". The scenario from the question is now a test: app → lib-a → victim 1.0, app → lib-y → lib-r with no cached pom is undetermined for victim 1.0, names lib-r, and offers mvn -q dependency:resolve.

Narrower than the question's wording, on purpose.

  • A module with a missing file still answers "selects another version". That writes no new pin: it skips the patch before any download and takes out a pin of that version already there. Making it undetermined too would have left stale pins in place on unresolved machines.
  • The pom of a version that loses mediation casts no doubt.
  • A build pinned to a <base>-socket.<hex8> copy never fetches the base version's pom. Without a fix, an earlier vendored pin would have blocked every later patch of its module on a fresh machine. The base version now reads the copy's pom.

Left for the owner (decisions 6 to 8 in the description): the other unread causes (relocation, profile dependencies, undefined property, foreign version lists) still cast doubt only from their depth down; "selects another version" can take out a correct pin if a missing pom hides a range; an artifact published without any pom holds its module back for good.

Ran. Core lib 7,818 passed; the 17 Maven-related CLI suites 1,194 passed; the two real-Maven suites 2 and 5 passed (Maven 3.9.16); fmt and clippy clean. The four tests of the new rule fail on the model at 7795510. /code-review high ran twice on this commit; the description lists all eighteen findings and what was done with each.

I removed agent:needs-human. #2114 is stacked on this branch; the commit applies cleanly on its head.


Generated by Claude Code

…nside the repository

- hosted scan: a failed selection task (panic or cancel) turned into
  `None`, which the pom rewriter reads as "no selection" and pins
  unchecked. Map it to `MavenSelection::unavailable`, so the rewriter
  treats it as undetermined like any other unreadable selection.
- `repo_pom` and `listed_versions`: a coordinate with a leading or
  trailing `.` became a leading `/` (or a trailing one) after the
  `.` -> `/` mapping, and `PathBuf::join` with an absolute path drops the
  repository root, so a pom in the local repository could point the
  read-only walk at any directory. Reject leading/trailing `.` and `:`
  (a Windows drive) too. Test added.
- CLI_CONTRACT: taking out an existing pin of a version Maven does not
  select is vendored-only; a hosted pin a scan wrote earlier carries no
  marker and is not re-checked.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: final review of 30a07a3 found two small fail-open/escape paths, fixed in e0442f5:

  1. Hosted mode pinned unchecked if the selection task failed. scan/hosted.rs turned a join error (panic or cancel) of the selection task into None with .ok(), and the rewriter reads None as "no selection" and pins as before. It now becomes MavenSelection::unavailable(..), so the rewriter treats it as undetermined.
  2. A coordinate with a leading or trailing . escaped the local repository (read-only). In repo_pom and listed_versions, ".x".replace('.', "/") gives /x, and PathBuf::join with an absolute path drops the repository root. A leading or trailing . and a : are now rejected. A unit test covers this.
  3. CLI_CONTRACT.md was corrected. It said a pin of a version Maven doesn't select is taken out; that is vendored only. Hosted pins carry no marker, so a hosted pin an earlier scan wrote is read as the user's own management and is never re-checked. That is unchanged from main, so it isn't a regression.

Open question for the owner, not blocking: should a later hosted scan find and drop its own earlier pin once the build moves to another version? That would need a marker on hosted pins. It's a follow-up and doesn't block this PR.

Verified: cargo test -p socket-patch-core --lib maven passed 501 tests (500 existing plus 1 new), and cargo check -p socket-patch-cli passes. The review brief will follow once CI is green on e0442f5.


Generated by Claude Code

@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for e0442f5

What it does: scan --mode hosted|vendored could silently change which version of a Maven dependency the build resolves, either a downgrade or a forced upgrade. A <dependencyManagement> pin forces its version even where that version had lost mediation. This PR adds a static model of Maven 3's per-module version selection (nearest-wins, ranges, exclusions, properties, reactors). A patch of g:a:v is now pinned only in modules where Maven already selects v. Anywhere the model is unsure, it does not pin.

Risk: Medium. The new model is large (about 1.6k lines) and has to match Maven exactly. Every vendored path fails closed. In hosted mode, an undetermined selection only rewrites a declaration that already names the base version.

Look here:

  • [maven_selection.rs:185](https://github.com/SocketDev/socket-patch/blob/e0442f584951e83f7075c114c4c0747d3fbc0ea9/crates/socket-patch-core/src/crawlers/maven_selection.rs#L185): verdict(), the uncached-file guard and the range-freeze rule
  • [maven_selection.rs:1387](https://github.com/SocketDev/socket-patch/blob/e0442f584951e83f7075c114c4c0747d3fbc0ea9/crates/socket-patch-core/src/crawlers/maven_selection.rs#L1387): settle, nearest-wins with range backtracking (with nearest at :1571)
  • [maven_selection.rs:1122](https://github.com/SocketDev/socket-patch/blob/e0442f584951e83f7075c114c4c0747d3fbc0ea9/crates/socket-patch-core/src/crawlers/maven_selection.rs#L1122): edges, how a range expands to versions
  • [maven_reactor.rs:229](https://github.com/SocketDev/socket-patch/blob/e0442f584951e83f7075c114c4c0747d3fbc0ea9/crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs#L229): plan_with_selection, where each module's pin goes and which pins are held back
  • redirect/mod.rs:9098: the hosted gate

Verified:

  • Reviewed the source changes, with a focus on the last three commits (missing pom, unresolved deeper range, selection cache).
  • Version ordering and range parsing follow Maven's GenericVersion / GenericVersionRange.
  • cargo test -p socket-patch-core --lib maven: 501 passed.
  • CI on e0442f5: all 49 checks pass, including ci-ok and clippy.
  • CHANGELOG.md is untouched.

Changes I made (e0442f5, details in the comment above):

  1. A failed selection task in hosted mode is now treated as "undetermined" instead of pinning without the check.
  2. A Maven coordinate with a leading or trailing ., or a :, is rejected, so the read-only walk can't leave the local repository. A test covers this.
  3. CLI_CONTRACT now says that only vendored mode removes an existing pin of a version Maven doesn't select.

Open questions (follow-ups, not blocking):

  1. A hosted pin from an earlier scan has no marker, so a later scan never re-checks it. This is unchanged from main. Should hosted pins get a marker so a later scan can drop them?
  2. By design, a relocation, a dependency-declaring profile, or a cycle deeper than the winning declaration still yields "selected". A range hidden behind one of those could still move the build. The commit message of 30a07a3 acknowledges this.

Update: the head is now e061876, which only merges main into the branch. The CLI_CONTRACT.md conflict was resolved with both sides kept, and CI is green.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 18, 2026
@mikolalysenko Mikola Lysenko (mikolalysenko) removed the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 18, 2026
Resolve the CLI_CONTRACT.md conflict in the hosted rewriter paragraph:
keep main's bun lockfileVersion 3 wording and this branch's Maven
version-selection sentence.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 18, 2026
Merged via the queue into main with commit 6eaa807 Nov 18, 2026
49 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/maven-pin-follows-mediation branch November 18, 2026 16:46
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Nov 18, 2026
#2100 was squash-merged to main, with two commits this branch never had
(the selection failing closed when it is unreadable, and a pom the local
repository lacks holding a module's pins back) and the rest of main since.
This branch still carried #2100's individual commits as of the point it
forked from it (7795510).

The tree is main plus this branch's own changes: the three-way merge was
taken with that fork point as its base, so what #2100 became on main wins
over the copy carried here. The diff against main is the same 66 files and
the same line counts as this branch's diff against the fork point. One
conflict: a single long line of CLI_CONTRACT.md, where main changed the
Bun lock versions and this branch the Maven clauses; both are kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Nov 18, 2026
…aven-hosted-mirror-guard

#2100 landed on main and the #2114 branch took main in. This brings that
forward. No conflicts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Nov 18, 2026
…aven-hosted-repo-scoping

#2100 landed on main and the #2114 branch took main in. This brings that
forward. One conflict, the same long line of CLI_CONTRACT.md that main's
Bun change and this branch's Maven clause both touch; both are kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants