Repository navigation
Patch Maven reactors and ${property} versions in hosted mode - #2114
Mikola Lysenko (mikolalysenko) merged 23 commits into
Conversation
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>
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
Hosted mode read only the root pom.xml. A multi-module reactor was
refused whole (`redirect_maven_multimodule_unsupported`), and so was a
declaration whose version is a `${property}`
(`redirect_maven_dep_unpinned`), so the default mode patched nothing in
either, where vendored mode patches both.
The pom rewriter now hands both to a hosted entry point of the reactor
planner vendored mode already uses (`maven_reactor::plan_hosted`), with
the same selection model and the same placement:
- a declaration that names the base version is rewritten where it
stands, in whichever pom holds it;
- the `<dependencyManagement>` pin goes in the highest pom whose modules
all select the base version or do not resolve the artifact, down to
one module's own pom; a module that resolves another version is never
reached, and a module a declaration already wires has no say;
- a `${property}` version only the patched artifact's declarations read
has the property's value rewritten (the declarations keep their text,
no sibling is stranded); any other one takes the literal suffixed
version, with the text it replaced recorded in a comment right after
the element (`<!-- socket-patch:version ${x} -->`); a property a
parent outside the checkout defines is read from what Maven selects
for the modules that read the declaration;
- the `<repository>` goes in each local root a wired pom inherits from,
and the Trusted Checksums files stay at the project root.
Hosted mode keeps no ledger, so each edit says what it replaced by its
own text, and `unwire_hosted` reads it back. The planner unwires every
pom it would change before returning and leaves a pom alone when that
does not give the text it had, so no edit is written that could not be
taken back byte for byte (a pin in an empty `<dependencyManagement>` is
the case found; reported as `redirect_maven_edit_not_reversible`).
The engine reads every pom the planner reads by asking it until it asks
for nothing new, and confirms a planned dep from the planner's own
report: a pin in a module pom, a property or a recorded declaration is
no substring of the root pom.
The placement code is shared with vendored mode (`place_pins`, moved out
of `plan_with_selection` unchanged), `Reactor::under` can leave modules
out, and `rewrite_declarations` can be told what a version the checkout
does not define reads.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Discovery read only the root pom.xml, and restore only undid a pin
there: a pin in a module pom was invisible to `list`, `vex`, `rollback`
and `remove`, and a reactor root's pin was withheld from `vex` whatever
the modules did.
Discovery now reads a reactor whole (the poms the reactor planner
reads, asked until it asks for nothing new): a pin's comment names its
patch, any other suffixed version is tied to a `socket-patch-<uuid>`
repository by its 8-hex suffix as before, and a `${property}` version is
read through the properties of the declaring pom's chain. Every pom
that carries part of the wiring (the pin, a rewritten declaration, the
property, the repository) is a file of the ref. The patch is attested
by the rule vendored mode uses: no declaration may still build the base
version, and every module that resolves it, or may, is reached by a pin
or a declaration of the patch. What Maven selects is read from the
local Maven repository, on disk only. A reactor whose poms cannot all
be read falls back to its root pom, whose pin stays a ref and is not
attested, as before.
Restore undoes a pin in every pom discovery found it in, or in none: the
planner's edits through `unwire_hosted` (the tagged pin, the recorded
`${...}` version, the property), the `<repository>` in whichever pom
declares it, and the `.mvn` files at the project root. A suffixed
declaration in a reactor, or in a pom that carries one of the planner's
marks, is a rewritten one and gets its base version back; only a single
pom with no mark is read as an earlier release wrote it, where an added
`<dependencyManagement>` entry is told from a rewritten one by its
shape. A project's own management entry that happens to have that shape
is therefore no longer removed in a reactor.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two capstones on the hosted suite's harness and fake registry, each
checking the invariant (the artifacts Maven resolves after the scan are
the ones it resolved before, the patched one in its patched build), that
a second scan writes nothing, and that `rollback` restores every file
byte for byte and leaves none behind:
- a reactor (the V3 shape): the module that reaches the base version
through another artifact is pinned in its own pom, the module that
declares it has the declaration rewritten, the module that resolves a
newer version is untouched and resolves what it resolved before; a
Maven started in a module directory resolves the patched jar too;
`vex` attests the patch, and withholds it naming the module once a
module declares the base version itself;
- a `${property}` version: a property only the patched artifact reads, a
property a sibling artifact reads too, and a property a parent pom
from the repository defines.
The fixture repository gains a sibling artifact at the victim's version
and a parent pom that defines a version property.
Docs: the CLI contract and the ecosystem guide describe hosted reactors
and property versions (where the pins, the repository and the Trusted
Checksums go, how a `${...}` version is wired and restored, what `vex`
attests, what happens to a pin an earlier release wrote), with the new
warning codes `redirect_maven_pin_would_move_module` and
`redirect_maven_edit_not_reversible`, the edit kind
`redirect_maven_property`, and the narrowed meaning of
`redirect_maven_multimodule_unsupported` and `vex_maven_reactor_root`.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t tell A hosted scan over a cold local Maven repository rewrites the declarations that name the base version and pins nothing where what Maven selects cannot be told, saying so with the remedy: resolve the project once and scan again. That second scan then found the patch already wired and, by the rule vendored mode keeps (pins are placed when a patch is first wired), added nothing, so the reactor stayed half patched whatever was done. A patch the poms already wire still keeps every pin where it is. A module that no pin or declaration reaches and that is now certain to select the base version is pinned all the same, by the usual placement over the unreached modules only. A scan told nothing new still writes nothing. The pieces of `place_pins` this needs are split out (`keeps_placement`, `undetermined_note`); vendored planning is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Module poms were read as rewrite targets, so one that is a link out of the repository, not UTF-8, or (in memory) linked or without content refused the whole hosted run with exit 1, as an unreadable root pom does. Before module poms were read at all, such a reactor was left alone with exit 0. They are now read as advisory input, and a module pom that is a symbolic link is not read at all (the rewrite would replace the link with a copy). The planner then finds the reactor incomplete and leaves it as it is, `redirect_maven_multimodule_unsupported` with the reason, exit 0. The guard on linked or unreadable rewrite targets is unchanged and has nothing to refuse. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Restore told a reactor from a single pom by the root's model alone, so a Maven 4 root that could discover subprojects but has none was read as a reactor: an entry an earlier release added to its `<dependencyManagement>` was put back at the base version instead of removed. It now asks what discovery asks (the root lists modules, or Maven 4 finds a subproject under it), so such a root is restored as the single pom it is. A test pins both readings: the added entry goes from a single pom, and in a reactor a managed entry at the suffixed version keeps its place at the base version, since there it cannot be told from the project's own. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review of the hosted reactor work found six ways a scan or a rollback could leave a pom naming a `-socket.<hex8>` version with nothing to serve it, or wiring no rollback would find, and two ways a large reactor was not read. They share one invariant, now enforced in one place. The invariant: once a plan is written, no pom names the suffixed version unless the repository that serves it is declared in that pom's local root and a declaration Maven always reads resolves to it (so discovery finds the patch, and every pom that carries part of it); a rollback returns every pom the plan first wired to its bytes; when no pom names the suffixed version any more its repository and checksum lines go too, and an earlier patch's go only once no pom of the reactor names it. `HostedReactor::plan` plans declarations, properties, pins and the `<repository>` together, checks the result against that (running the rollback's own restore over each pom it would write), and returns the whole plan or a refusal that leaves every pom as it was: - a declaration only a `<profile>` holds was rewritten with no repository and no way for a rollback to find it: now refused whole; - a root the repository could not be added to was skipped while the modules below kept their pins: now refused whole; - an earlier patch's repository and checksum lines were dropped by looking at the poms the plan changed, while an unchanged pom still named that patch: now every pom of the reactor is asked; - a scan that took out the last pin left its repository and checksum lines, which no rollback could clear: they go with the pin; - the warning for a module with a `.mvn` of its own was given only by the scan that wrote the pin: now by every scan. Reading. The engine learned the reactor one module per round, parsing every pom again each round, and stopped after 64 rounds, so a reactor of more than 64 modules was refused. `read_reactor` walks the files itself: each pom is fetched and parsed once, and a missing file stops nothing. The engine, discovery and restore read through it, with one rule for what is read (a module pom that is a symbolic link is not), so what one plans over the others find. The rewriter reads the reactor once per run and plans every patch over it; discovery reads it once for all pins. Discovery reads a single pom together with the parent poms it inherits from inside the checkout, where a property rewrite and the repository may sit. A reactor one of whose poms cannot be read is read for the pins of the others (found, never attested), where it fell back to the root pom alone. Restore reads the reactor itself and restores a pin in every pom that carries part of it, whatever discovery listed, or in none: a pin found through the root alone no longer leaves a module naming a version whose repository the rollback just removed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Three more capstones on the hosted suite: - a reactor whose only declaration of the version sits in a module's profile: the scan exits 0, says why, writes nothing, and the build with that profile resolves what it did; - a single pom whose version is a property a parent pom of the checkout defines: the property and the repository are written in the parent, Maven resolves the patched jar, and a rollback restores both poms byte for byte; - a newer patch superseding an earlier one while a module still reads the earlier version through a property a profile may redefine: the earlier patch keeps its repository and checksum lines, and Maven resolves each module from the repository of the patch its pom names. The CLI contract and the ecosystem guide state the rule a hosted plan is held to (written whole or not at all), what refuses a plan and under which code, what a later scan removes with the last pin, how rollback and remove read a reactor, and how a single pom is read with a parent pom of the checkout. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview A new Contract and UX updates: Tests: large real-Maven e2e coverage for reactors, property-only/shared/parent cases, profile-only refusals, superseding patches, rollback; shared mediation fixtures extended. Reviewed by Cursor Bugbot for commit 56ae4ee. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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 56ae4ee. Configure here.
…en fixtures
The shared `redirect/maven/pom` golden still expected a `${property}`
version to be left alone (`property-version-warn`: no file, no edit), which
the hosted rewriter no longer does, so `redirect_golden_fixtures_match`
failed in CI. Only `--lib` and the CLI suites had been run before the push;
this time every core test target was.
Each expectation below was written from the behaviour the change intends,
then compared with what the rewriter does; none was regenerated unread.
- `property-version-warn` becomes `property-version`: a property that is
defined once and read only by the patched artifact takes the suffixed
version as its value, the pom gets the repository, and nothing warns.
- `property-shared-sibling` (new): a second artifact reads the property,
so the property stays and the declaration takes the literal with the
`<!-- socket-patch:version ${x} -->` comment that rollback reads.
- `property-external-parent-warn` (new): no pom of the checkout defines
the property and nothing says what Maven selects, so nothing is written
(`redirect_maven_dep_unpinned`, `redirect_maven_selection_undetermined`).
- `profile-property-warn` (new): only a profile declares the artifact, so
the plan is refused whole (`redirect_maven_profile_dependency_unpatched`).
- `reactor-module-literal`, `reactor-root-property` (new): a reactor with
no selection to read; the declaration or the root's property is
rewritten, the repository goes in the root, no pin is placed, and the
run says so (`redirect_maven_selection_undetermined`).
- `parent-in-checkout` (new): a single pom whose parent is in the checkout
and holds the property; both edits land in the parent pom.
The five that write files also run through `maven_goldens_round_trip`
(discovery, then restore, byte for byte), and every side of every case has
its entry in the discovery golden, whose only other change is the renamed
key. The other nineteen `maven/pom` cases pass unchanged.
depscan reads the same fixtures (`golden.test.ts`); the PR description lists
the seven for its `TS_LAGGING`.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
[agent] PR shepherd: this PR needs an owner decision before it can go further, so I added Why it is blocked
State of the head Question for the owner: which of decisions 1–5 do you accept as written? Then the Bugbot finding above gets fixed and this PR gets its final review once #2100 lands. Generated by Claude Code |
#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>
The hosted engine, discovery and the restore each read a reactor's module and parent poms through a reader that dropped every read error, so a pom that exists but is not UTF-8 text looked like a module with no pom: - the scan reported the reactor as short of a pom it has (`redirect_maven_multimodule_unsupported`) instead of refusing the run for a file whose content it does not know; - discovery left the pom out without a word, and a pin was attested or withheld for the wrong reason; - a rollback restored the poms it could read and left the undecodable one naming a version whose repository was gone. Each now tells "there, but not UTF-8" from "not there": - the engine records such poms and its guard refuses the run for the first, by name, with `candidate_file_unreadable`, as it does for an undecodable root pom. They are judged by what read them, not by their file name: a module's pom may be called anything. A linked or unopenable module pom still only leaves the reactor alone; - discovery reports the file as unreadable and treats it as a pom of the reactor it could not read: the pins of the other poms stay refs and none is attested, for that reason; - the restore refuses every pin of the reactor, names the file, and writes nothing: a pin is restored in every pom that carries part of it or in none, and with a pom unread "every" cannot be kept. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main gained the rule that this repository names no private repository, and the rewording that goes with it, and conflicted here in one long line of CLI_CONTRACT.md: main changed its cargo clause, this branch its Maven clause. Both are kept. Nothing this branch adds over main names a private repository, a path in one, or one of its pull requests. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed at 3b8dd67. The plan is written whole or refused, each planned pom goes through the real restore before it is written, rollback restores only the exact suffixed version, and non-UTF-8 and symlinked poms are refused; the Bugbot thread is fixed in dc3ccc2. This approval covers the code and does not settle the five "Decisions for the owner" in the description, which still reads state: blocked. Non-blocking: (1) extract_hosted_reactor does not apply the single-pom check for a parent pom outside the checkout that declares the artifact with its own version, and a single pom with an in-checkout parent now takes this path too, so vex leans on the module selection read from the local Maven repository for that case (listed under Known gaps; worth a tracked follow-up since it bears on attestation); (2) seven redirect/maven/pom golden fixtures are new or changed, so the backend rewriter needs the matching change; (3) one branch commit message names the private backend repository, so reword it at squash time.
main now carries the fix for the Trusted Checksums line that stopped Maven 3.9.2 to 3.9.8 from starting with -f from outside the project, which moved the helpers this branch calls into formats::maven::declared_maven and changed how the checksums directory is spelled. Conflicts, and how they were settled: - redirect/mod.rs: this branch had factored the Trusted Checksums pin into pin_maven_checksums, shared by the literal, property and reactor paths; main had changed the inline copy. The factored function stays and takes main's rule: the settings are merged once per run through merge_mvn_config with the project's form and the Maven it declares, so every path that pins writes the directory one way. main's heal runs first, before the reactor planner, as it does before every other return. - redirect/upstream/maven.rs: both sides' tests kept; the import of a helper this branch's restore no longer calls is dropped. - CLI_CONTRACT.md: one long line, this branch's reactor and property clause with main's Trusted Checksums clause. The reactor extractor of discovery hands the root pom to the enforcement check, which main's signature now takes. This branch's own golden cases (property-version, property-shared-sibling, parent-in-checkout, reactor-root-property, reactor-module-literal) were regenerated from the rewriter: their .mvn/maven.config now names the checksums directory through the launcher's property, like main's. The discovery golden follows. Test only: the shared snapshot helper of the real-Maven suites leaves out Maven 4's own output directory (.mvn/target), which made the reactor rollback test fail on Maven 4.0.0-rc-7. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
#2114, which this branch was stacked on, landed on main as a squash (6014caf). Merged against its tip (7bdc058) as the base, so the reactor/property work is taken once and #2150 (f297a90) comes in unchanged. Two conflicts kept both sides: the MAVEN_ARGS and REPIN entries in the Bazel harness, and the mirror and declared_maven modules in formats/maven. CHANGELOG.md is main's. Assisted-by: Claude Code:claude-opus-5-5
…s too
After the merge with main, `rollback` of a Maven patch that a hosted run
pinned in `pom.xml` and in the block of a Bazel hub in `MODULE.bazel`
took the entry out of the block and left `pom.xml` and the two `.mvn`
files pinned. It exited 0 and reported the patch as rolled back
(`a_pinned_hub_gets_its_block_and_the_undo_takes_it_out` in
`e2e_bazel_maven_beside`).
What met what. A hosted pin is one patch of one package in every file
that wires it: discovery groups what it finds by purl and patch id, and
the restore hands the restorer of each format the pins that have a file
of that format, and those files. "Patch Maven reactors and ${property}
versions in hosted mode" (#2114) turned the Maven restorer from a loop
over its files into a loop over its pins, and took every file of a pin
for one of its poms. A pin with a file the restorer was not handed was
then passed over as one whose file could not be read, with no refusal;
the restorer of the other file claimed the pin, so the run called it
restored.
The block is such a second file, and not the only one. On main alone, a
checkout that sbt builds beside Maven holds the patch in
`socket-patch.sbt` as well as in `pom.xml`, and its rollback left the
pom pinned in the same way: the new unit test of the Maven restorer
shows that on the `sbt/redirect/pom-also-present` fixture, with no
Bazel file in it. The index of a hosted Gradle build beside a `pom.xml`
is a second file of the same kind (read, not run).
The fix is in the Maven restorer (`upstream/maven.rs`, one more
implementation line): the poms of a pin are those of its files that the
restorer was handed. Every other file of the pin is the restorer's of
its own format, as the dispatch of the restore already has it. A pin
that only poms hold is read as before, so the rules for a reactor stand
as they are: a pin is restored in every pom that carries part of it or
in none, and a pom that cannot be read refuses it. The existing tests of
the Maven undo pass unedited.
Tests:
- `upstream/maven.rs`: the sbt fixture, discovered and rolled back to
its input, byte for byte.
- `upstream/bazel_maven.rs`: discovery reads one pin from `pom.xml` and
the block, and the restore leaves both files as they were.
- `e2e_bazel_maven_beside`: beside a pinned hub, a hosted `get` in a
reactor, with a `${property}` version, and behind a mirror of the
machine's Maven settings that would take the Socket repository (the
pom then gets no pin and the run says so; the hub still gets its
block). `list` and `vex` show one pin, in the block and in every pom
that holds part of it, and `rollback` leaves the tree as it was.
- `vendor_jvm_cli`: `vendor` beside an entry whose patch a hosted run
also pinned in the poms of a reactor takes the poms' part of the pin
over and leaves the entry, as it leaves an entry that stands alone.
With the fix taken out, the two unit tests and the two tests of the
undo in `e2e_bazel_maven_beside` fail, and nothing else in the unit
suite of the core crate does.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Based on
main: #2100 has merged, andmainwas merged into this branch (2ce982c; the tree ismainplus this PR's own changes)./code-review highran once; its ten findings are answered below.What was wrong
scan --mode hosted(the default mode) read only the rootpom.xml. It refused a multi-module reactor whole (redirect_maven_multimodule_unsupported, exit 0, nothing patched) and refused any declaration whose version is a${property}(redirect_maven_dep_unpinned). Vendored mode patches both. With the Maven extension ruled out, pom edits have to cover them.What each shape does now
Hosted mode hands a reactor root, and a single pom with a
${property}version, to the reactor planner vendored mode uses (maven_reactor::plan_hosted), with the same selection model and the same placement. The invariant holds: every module resolves what it resolved before, except that a resolved base version with a patch becomes its patched build.<dependencyManagement>pin in the highest pom whose modules all select the base version (or do not resolve the artifact), down to that module's own pom${property}only the patched artifact reads${property}a sibling artifact reads too${property}a parent pom outside the checkout definesredirect_maven_multimodule_unsupportedwith the reason, nothing written, exit 0<profiles>redirect_maven_profile_dependency_unpatchedlist,vex,rollbackread both pomsThe
<repository>goes in the local root each wired pom inherits from (a module whose parent is not in the checkout gets its own). It is an absolute URL, so it resolves the same from the root, from a module directory and with-f. The Trusted Checksums stay in the project root's.mvn/, which Maven finds by walking up from the pom it is started on. A module with a.mvnof its own is reported (redirect_maven_trusted_checksums_unenforced): a Maven started there reads that directory, so the checksum pin is not enforced for that build (the version suffix still is). Vendored mode refuses such a reactor; hosted mode has no path under the root to protect, so it does not.The invariant, and how it is enforced
Once a plan is written, no pom names a
-socket.<hex8>version unless the repository that serves it is declared in that pom's local root, its checksum lines are in place, and a declaration Maven always reads resolves to it, so discovery finds the patch and every pom that carries part of it. A rollback returns every pom the plan first wired to its bytes. When no pom names the version any more, its repository and checksum lines go too; an earlier patch's go only once no pom of the reactor names it.It is enforced in one place,
HostedReactor::plan. The planner plans declarations, properties, pins and the<repository>together over a reactor it read once, then checks the result: discovery's own reading (sites) must find the patch in every pom that names it, each such pom's local root must declare the repository, and the rollback's own restore (restore_pom, a pure function now), run over each pom about to be written, must give back the text the pom has. The plan is returned whole, or as a refusal that leaves every pom as it was read. The rewriter only writes what a plan returns and derives the checksum edits from it.rollbackandremoveread the reactor themselves and restore a pin in every pom that carries part of it, or in none.reactor_wiring_keeps_the_invariant_through_its_lifeandsingle_pom_wiring_keeps_the_invariant_through_its_liferun eleven fixtures through scan, re-scan, a superseding patch, pins taken out and rollback, asserting the invariant on the tree after every step with the real discovery and restore.Restoring a
${property}version without a ledger (design question 1)In the order asked for:
.mvn/maven.configor model reference defines the name too, and every${name}in every pom of the reactor is the whole<version>of a declaration of the patched artifact, the value takes the suffixed version. Restore strips the suffix.<version>1.10.0-socket.6f708192</version><!-- socket-patch:version ${fixture.version} -->. Restore puts the recorded text back and removes the comment.Why restore is exact: no ledger records these edits, so each says what it replaced by its own text. The base version is the suffix's prefix; a pin is the entry vendored mode writes, with its
<!-- socket-patch <uuid>: g:a:v -->comment, removed by its lines together with the section it created; a recorded declaration carries its comment. The planner runs the restore over every pom it would change before returning (see the invariant above), so no edit is written that the pom alone cannot undo byte for byte. A pin in a<dependencyManagement>that holds no entry is the one case handled pom by pom: that pom is left alone (redirect_maven_edit_not_reversible) and the rest of the plan stands.VEX and restore (design questions 2 and 3)
socket-patch-<uuid>repository by the 8-hex suffix as before; a${property}version is read through the properties of the declaring pom's chain. Every pom that carries part of the wiring is a file of the ref. A reactor one of whose poms cannot be read is read for the pins of the others (listed, never attested).vex_maven_reactor_root). What Maven selects is read from the local Maven repository of the machine that runsvex.<repository>wherever it is declared, and the.mvnlines and files at the project root. A pom that still names the version and cannot be read refuses the pin with nothing changed. Removing the last hosted patch returns every file to its bytes and removes the files hosted mode created.Pins written by 5.1.0
They carry no comment. In a single pom nothing changes: found, kept, rolled back and removed as before. When such a pom has since come to head a reactor, the pin is kept as it is (the patch counts as wired, no pin is added),
vexweighs it module by module, androllbackrestores its version. An entry 5.1.0 added to<dependencyManagement>is then left at the base version instead of removed, because in a reactor it cannot be told from the project's own management, and removing the project's own entry would break the build. A 5.1.0 pin that holds a module at a version Maven would not select is not detected (the model reads it as the project's management).Reason codes
Added (all
warnings[], exit 0):redirect_maven_pin_would_move_module: a parent pom resolves the base version above a module that resolves another, so the parent takes no pin; also when a pin an earlier run wrote is taken out because a module it reaches now resolves another version.redirect_maven_edit_not_reversible: a pom is left alone because an edit there could not be undone exactly.redirect_maven_property(a property's value rewritten).redirect_maven_dep_versionnow carries the${...}text asoriginalfor a recorded declaration,redirect_maven_dep_managementgains the actionsrewrittenandremoved, andredirect_maven_repositorygainsremoved(the last pin of the patch went).Reused for a refused plan, same exit status:
redirect_maven_profile_dependency_unpatched(the only declaration is inside<profiles>),redirect_maven_pom_unreadable(the pom that must declare the repository cannot take it).Changed meaning, same code and exit status:
redirect_maven_multimodule_unsupported: no longer every reactor, only one that cannot be planned (a module pom missing or unreadable, a property or out-of-root<module>path, a same-GAV grant).redirect_maven_dep_unpinned: no longer every${property}version, only one whose value cannot be told.redirect_maven_selection_undetermined: in a reactor it names the first module that cannot be told and counts the rest; the dep may be counted as redirected beside it.vex_maven_reactor_root: no longer every pin in a reactor root, only a reactor with a module that may build the unpatched version (or that cannot be read).Removed: none. No exit status changes on purpose. Natural outcome changes: a hosted scan of a reactor or of a
${property}version now reportsappliedand writes module poms (they appear inrewrittenFiles);vexnow attests a hosted patch in a reactor when every module is wired.Tests
e2e_redirect_maven_build, each asserting the invariant on what Maven resolves (GAVs before == after with the suffix stripped, every other jar byte-identical):maven_hosted_patches_a_reactor_module_by_module_and_rolls_back_clean: the V3 reactor, a module-directory build,vexattested then withheld namingb/pom.xml, rollback byte for byte.maven_hosted_patches_a_property_version_and_rolls_back_clean: a property only the victim reads, one a sibling reads too, one a parent pom from the repository defines.maven_hosted_leaves_a_declaration_only_a_profile_holds(finding 2),maven_hosted_patches_through_a_parent_pom_of_the_checkout(finding 3),maven_hosted_keeps_an_earlier_patch_served_while_a_module_names_it(finding 6).redirect/maven/pomcases (listed below) pin the rewriter's output with no selection; the five that write files also round-trip through discovery and restore inmaven_goldens_round_trip, and each side of each case has its entry in the discovery golden.Golden fixtures that change
The cases under
crates/socket-patch-core/tests/fixtures/redirect/maven/pom/are a contract shared with the other implementation of the rewriter, which has to follow on its next update of this repository. Seven cases there are new or changed:property-versionproperty-version-warn; output changedpom.xmlgets the<repository>, the two.mvnfiles are written, warnings[]property-shared-sibling<!-- socket-patch:version ${slf4j.version} -->, the property staysproperty-external-parent-warnredirect_maven_dep_unpinned,redirect_maven_selection_undeterminedprofile-property-warnredirect_maven_profile_dependency_unpatchedreactor-module-literalapp/pom.xmldeclaration rewritten,<repository>in the rootpom.xml;redirect_maven_selection_undeterminedreactor-root-property<repository>in the root;redirect_maven_selection_undeterminedparent-in-checkoutbuild-parent/pom.xml<repository>both land inbuild-parent/pom.xml;pom.xmlis unchangedWhat the other implementation's test harness has to cope with: inputs and
expected/trees with poms below the root, edits whosepathis a module pom, the new edit kindredirect_maven_property, andexpected-warnings.jsonon all seven ([]where nothing warns). The goldens run the rewriter with no Maven selection, as the backend does, which is why the reactor cases write no pin. The other nineteenmaven/pomfixtures are unchanged.After
maintook themvn -ffix (#2145)mainwas merged in at7bdc0588a. #2145 changed how hosted mode names the Trusted Checksums directory in.mvn/maven.config(through${maven.multiModuleProjectDirectory}unless the project declares Maven 4), heals a line an earlier release wrote, and moved the helpers intoformats::maven::declared_maven. What that meant here:main's rule (the project's form, the Maven it declares, once per run), so a reactor and a${property}pin write and heal the directory exactly as a single pom does.main's heal runs first, before the reactor planner.property-version,property-shared-sibling,parent-in-checkout,reactor-root-propertyandreactor-module-literal, thesummaryFile.basedirline ofexpected/.mvn/maven.confignow reads${maven.multiModuleProjectDirectory}/.mvn/checksums. Nothing else in them changed (edits and warnings are the same). The discovery golden follows for those cases: their checksum is no longer taken as the pinned content, bymain's rule for a project that declares no Maven..mvn/target, its project-local repository).maven_hosted_patches_a_reactor_module_by_module_and_rolls_back_cleancompared it and failed on Maven 4.0.0-rc-7; it passes now.What I ran
On macOS, head
7bdc0588a(mainat83d2b95damerged in):cargo fmt --all -- --check: clean.cargo clippy --locked --workspace --all-features -- -D warnings: clean.cargo test -p socket-patch-core --tests --no-fail-fast: 8710 passed, 0 failed (after regenerating the discovery golden).e2e_redirect_maven_buildwith real Maven, required and not skipped (the capstone included): 7 passed on each of 3.6.3, 3.9.4, 3.9.16 and 4.0.0-rc-7.maven_hosted_jackson_databind_delivery,maven_vendored_jackson_databind_deliveryandmaven_agent_jackson_databind_deliveryall pass.Not run: Linux and Windows (CI), the rest of the CLI suites.
Review (
/code-review high) and what was doneAll ten findings were confirmed against the code.
read_reactorwalks the files itself. Each pom is fetched and parsed once; a pom's modules, parent and discovered subprojects are asked for together; a missing file stops nothing; there is no round cap. Tests:a_large_reactor_is_read_whole_and_each_file_once(221 poms, each path asked for once),a_reactor_of_hundreds_of_modules_is_read_and_planned_whole(200 modules through the engine).redirect_maven_profile_dependency_unpatched). Tests: planner, rewriter, real Maven.a_pin_is_restored_in_every_pom_that_carries_it_or_in_none,a_reactor_with_a_missing_module_is_still_rolled_back_whole.redirect_maven_pom_unreadable). I found no pom the two parsers read differently, so the planner test fails the repository step directly, and the rewriter test uses a<repositories/>a rollback could not put back..mvn/maven.configresolver lines and the then empty checksums file, because a hosted rewrite cannot delete a file; they hold no line of a patch..mvnwarning disappeared on re-scan. Fixed: judged on the poms as they stand. Test:maven_reactor_nested_mvn_is_reported_on_every_scan.read_reactor) for the engine, discovery and restore, and one reactor question (heads_reactor_in).HostedReactor) and a plan reparses only the poms it changes; discovery reads it once for all pins; no per-dep clone of the module poms.Review bot, after the review above. "Non-UTF-8 module poms look missing": confirmed and fixed in dc3ccc2. A reactor pom that is there but is not UTF-8 text was read as a missing module by the scan, by discovery and by the restore. The scan now refuses the run for it by name (
candidate_file_unreadable), discovery reports it as unreadable and attests no pin of that reactor, and rollback refuses every pin with nothing changed; a test covers each.Decisions for the owner
<!-- socket-patch:version ${x} -->). It is the only new visible mark; it follows thesocket-patch:comment family vendored mode already writes. Alternatives: skip those declarations with exit 0 andredirect_maven_dep_unpinned(they stay unpatched in hosted mode); or write${x}-socket.<hex8>as the version, which needs no comment but breaks the build as soon as the property is bumped and cannot be attributed when the property is defined outside the checkout.vexwithholding (the vendored behaviour). In a single pom hosted mode still refuses the dep with nothing written.Known gaps
.mvn/maven.configresolver lines and an empty.mvn/checksums/checksums.sha256(finding 7).vex_maven_parent_declares) is not applied per module in a reactor.<repositories/>is expanded in place, as before, which rollback does not collapse again.<mirrorOf>, running Maven to settle undetermined answers.Generated by Claude Code