Skip to content

feat(xvm): add provider-scoped binding group registration - #384

Merged
Sunrisepeak merged 13 commits into
release/0.4.70from
fix/xvm-binding-groups
Jul 26, 2026
Merged

Sunrisepeak merged 13 commits into
release/0.4.70from
fix/xvm-binding-groups

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Summary

This draft introduces the provider-scoped binding-group foundation required
for coherent multi-program toolchains such as GCC (gcc, g++, headers, and
libraries).

  • model a binding group as one provider release with exact member versions
  • resolve the same canonical group from its root or any bound member
  • reject malformed, partial, mixed-provider, and cross-version group metadata
  • translate xpkg effects into an immutable RegistrationBatch, validate the
    complete batch first, then apply it atomically
  • support controlled binding-root migration without silently adopting
    unrelated existing state
  • remove/uninstall members only through exact provider-owned version authority
  • preserve complete registration state when validation fails instead of
    leaving partial mutations
  • add detailed architecture and implementation-plan documents under
    .agents/docs

Why

XVM previously treated each target independently. Package hooks could therefore
register or remove members one at a time, and active/version metadata did not
carry a canonical provider-group identity. For coupled toolchains this allows
mixed releases and incomplete state—for example, selecting one GCC member
without proving that gcc, g++, runtime libraries, and headers belong to the
same provider release.

This change establishes a fail-closed group identity:

(provider, providerVersion, bindingGroup)
  -> exact root
  -> exact member target/version set

All member entry points resolve through that identity. Provider metadata is
validated before mutation, and legacy entries cannot borrow provider-owned
target metadata.

Architecture

Canonical selection

src/core/xvm/bindings.cppm centralizes group parsing, integrity checks,
canonical member/root resolution, and deterministic diagnostics. Complete
selections are provider-scoped and carry exact member versions.

Strict state validation

XVM DB/config loading validates binding metadata both at JSON boundaries and
when constructing in-memory state. Invalid group shapes,
duplicate/conflicting members, partial provider metadata, and illegal root
migration fail closed.

Two-phase registration

src/core/xvm/registration.cppm builds and validates an immutable registration
batch before applying any DB changes. The apply phase registers a complete
group in one operation and no longer exposes partially registered members when
a later effect fails.

Exact removal authority

src/core/xvm/removal.cppm derives removal plans from exact provider-owned
selections. Uninstall paths cannot fall back to target-only or bare-version
deletion and cannot remove versions belonging to another provider.

Validation

All valid build/test commands used isolated HOME, XLINGS_HOME, XDG
directories, temp directories, and a private MCPP_HOME; they did not
intentionally use the host xlings environment.

  • focused binding/registration suite: 61/61 passed
  • broad XVM suite: 173/173 passed
  • latest-resolution regression suite: 3/3 passed
  • deterministic direct test binaries: 503 passed, 17 optional fixture
    skips
    across 11 binaries
  • GCC 16.1 isolated no-cache build: passed (49.32 s)
  • git diff --check origin/main...HEAD: passed

One known network-dependent package fixture was excluded from the deterministic
direct-binary loop; no passing claim is made for that external-network case.

Draft boundary / follow-up

This PR currently contains the reviewed selection, validation, registration,
and exact-removal foundation. It does not yet claim the final end-to-end
xlings use gcc 15/16 switch behavior
. The locked filesystem
materialization transaction, version-scoped shim dispatch, self-switch safety,
diagnostics/E2E coverage, and version bump remain follow-up work before this
draft is ready to merge.

The branch deliberately excludes the current uncommitted switch-planner work
until it passes its own contract review and isolated verification.

@Sunrisepeak
Sunrisepeak changed the base branch from main to release/0.4.70 July 26, 2026 06:06
Sunrisepeak added a commit that referenced this pull request Jul 26, 2026
* docs(agents): xvm group transaction review, design and plan

Add the PR #384 review, the target architecture, and the staged
implementation plan for the 0.4.70 release train.

- review: verify the five root causes against origin/main, record two
  silent regressions (includedir no longer written, headers never
  carry a group), the removal-fallback coherence gap, and the
  before/after user-experience comparison
- design: three-layer state model (Catalog / Selection / Materialization),
  group promoted to a top-level table, commit-then-reconcile so the
  filesystem stops participating in the transaction, doctor as the
  reconciler
- plan: single release/0.4.70 integration branch, P0-P4 plus an R
  integration stage, 18 scenario-level acceptance assertions, and a
  seamless-upgrade contract (U1-U7) including downgrade safety

* docs(agents): record the CI prerequisites the plan had assumed

The plan assumed a PR landing on the integration branch would be gated
by CI. It was not: all six workflows only triggered on main/master, so a
PR based on release/0.4.70 got no checks at all. A second, pre-existing
problem surfaced next -- every workflow restored an ~800 MB mcpp cache
and then deleted the payload directory it had just restored.

Add P-1 covering both (fixed in #386) plus the unresolved upstream fetch
instability, and note that it gates R.3's three-platform-green
requirement without changing that requirement.

* docs(agents): bound the merge exception during the upstream outage

CI cannot go green while P-1.3 lasts, and review of intermediate PRs is
delegated. Both facts need a written boundary so 'upstream is broken'
does not become a general waiver.

Allow a PR to land on the integration branch only when the local build
and test suite are green AND the CI failure carries the known upstream
fetch signature, before any of this repo's code is compiled. Any other
failure signature still blocks. R.3 is unchanged: the branch has to be
re-run green on all three platforms before it is proposed to main, so
this defers verification rather than skipping it.
@Sunrisepeak
Sunrisepeak marked this pull request as ready for review July 26, 2026 06:50
@Sunrisepeak

Copy link
Copy Markdown
Member Author

合入集成分支 — 本地验证记录

依 #385 计划 §3.1.1(上游故障期的有界合入例外)合入 release/0.4.70。集成分支不面向用户;对外发布的门禁是 R.3,不受此例外影响。

本地验证(干净的 detached worktree,origin/fix/xvm-binding-groups @ e8b3849)

mcpp build   →  Finished release [optimized] in 43.16s
mcpp test    →  test result ok. 11 passed; 0 failed; finished in 33.64s

test_main --gtest_list_tests                                    →  362 tests
test_main --gtest_filter='*Binding*:*Registration*:*Removal*:*Xvm*'
                                                                →  173 passed

CI 状态(不声称通过)

CI 当前失败,签名为已知上游拉取故障,发生在编译本仓任何代码之前:

error: fetch '[email protected]' failed (exit 1)
error: fetch '[email protected]' failed (exit 1)
error: xlings install_packages failed (exit 1) for '[email protected]'

同一签名在纯 workflow 改动叠加 origin/main 时同样出现,即 main 当天也失败。详见 #386。符合 §3.1.1 第 2 条,无其它失败签名。

已知问题,作为后续 PR 处理(不阻塞本次合入)

评审(#385 的 2026-07-26-xvm-pr384-review.md)记录的两个静默回归留给 P0:

  • P0.1 installer.cppm:740 的 vdata.includedir = op.includedir; 被删除,而 commands.cppm:206-215 仍读它 → xlings use 的头文件/库切换失效;bindingHeaders 在提交态零消费者
  • P0.2 installer.cppm:202-205 的 header 从不携带 .group,而 registration.cppm:563-572 在 groups.size() != 1 时硬失败 → headers + ≥2 个无 binding add 的 recipe 装不上

另有 P0.3(removal.cppm:312-325 逐 target 取 installed[].rbegin(),无 group 一致性,可复现本 PR 要消灭的混合工具链状态)与 P0.4(失败只走 log::warn + return false,用户看不到原因)。

这四项在合入 main 之前必须完成 —— 它们是 R.3 的组成部分。

@Sunrisepeak
Sunrisepeak merged commit c553ecd into release/0.4.70 Jul 26, 2026
2 of 14 checks passed
Sunrisepeak added a commit that referenced this pull request Jul 26, 2026
The selection layer fails closed, so a malformed or dangling release
makes `xlings use` refuse. That is correct, but doctor only knew about
shims and payloads, so the refusal was a dead end: nothing in xlings
could name the offending entry and the user was left reading
versions.json by hand.

Add xvm::inspect_binding_state, a pure function over (db, workspace)
that checks the invariants the selection layer relies on:

  every active version is registered
  every release resolves, with all members present
  members of one release are active together, or not at all

Each finding carries the XvmUserError code, the entry, the JSON Pointer
when the problem is metadata-level, and a hint naming the command that
fixes it. A release short one member is reported once, not once per
member. Pre-0.4.70 databases carry no group metadata and are not flagged.

Pure by construction -- no Config, no filesystem, no network -- so every
case is reachable from a unit test and doctor stays a renderer.

Read-only. Repair lands separately: deactivating a group or dropping
metadata should be spelled out before it happens.

Not included, and worth recording why. The plan called for
bindingIntegrityIssues to stop being serialized, on the grounds that
derived data should not become stored state. Implementing it failed
seven tests from #384 that assert the opposite, and they are right: an
entry whose bindingGroup did not parse holds no group in memory, so
rewriting the record without the marker would drop the malformed value
entirely and silently launder a corrupt entry into a healthy
group-less one -- back to the mixed-toolchain risk, with nothing left to
show it happened. The real defect is that rewriting an unparsed record
loses information either way; fixing it means preserving the original
JSON for such entries, which is its own change.
Sunrisepeak added a commit that referenced this pull request Jul 26, 2026
…includedir (#406)

`bindingHeaders` records every header directory a release declares, on the
group root, and #384 serialized it, parsed it, validated it and round-tripped
it through the version database. Nothing ever read it.

Materialization went through `VData::includedir` instead -- a single string
the installer writes on the root with last-op-wins semantics. For a release
declaring one header directory the two agree. For one declaring two they do
not: install materializes both, because it walks the effect list, while
`xlings use` only ever remembers the last. Switching away left the other
directories' headers in the sysroot and switching in never brought the new
release's copies. The sysroot held a mix of two releases -- the exact state
the binding-group work exists to make unrepresentable, reached through the
header path instead of the member path.

`xvm::group_header_assets(db, target, version)` resolves any member of a
release to the group's declared list, falling back to `includedir` when there
is none -- 0.4.69 state has no `bindingHeaders`, and neither does a
registration outside a provider group. The switch planner, the removal
teardown and the removal fallback all go through it.

Header assets also move from MemberSwitch to UseSwitchPlan, because they
belong to the release rather than to any member of it. Per-member lists would
link the same directory once per member, and -- worse -- the loop applied them
one member at a time, so member B's removal of the outgoing release could
delete links member A had just installed for the incoming one, for every
header name the two versions share. Which, for two versions of one toolchain,
is all of them. The plan now carries the two lists deduplicated and disjoint,
and `cmd_use` applies all removals before any install.

`destinationPrefix` is honored too. No recipe can set it today -- libxpkg's
`xvm.setup` takes a bare `includedir` -- but it is part of the persisted model
and round-trips, and a serialized field materialization ignores is what this
change is removing, not adding.

`attach_legacy_header_dir` still writes `includedir`, now for one reason only:
0.4.69 switches headers by reading it and knows nothing about
`bindingHeaders`, so dropping it would make a downgrade silently stop moving
headers. The release notes promise the rollback is safe.

Reachability, stated plainly: no recipe in the official index declares header
directories at all, and `xvm.setup` can only declare one per call (a second
call is refused as a duplicate registration). So the multiplicity this fixes
is currently unreachable through the public recipe API. The E2E fixture pushes
the second op onto `_XVM_OPS` directly to exercise it.

Verified: 6 new unit cases (XvmGroupHeaders) + 2 for the destination prefix;
E2E-32 extended with a second header directory. Reverting the resolver fails
3 of the unit cases and E2E-32 scenario 2, which reports the sysroot holding
1.0.0's `include/` while the workspace and `include-fixed/` are on 2.0.0.
Sunrisepeak added a commit that referenced this pull request Jul 27, 2026
* fix(xvm): let doctor repair a dangling legacy binding edge

Found by finally running the real-toolchain check the plan had carried from
the start and never executed. On a real installation:

    0.4.68           xlings use gcc 15.1.0  ->  gcc -> 15.1.0
    2026.7.27.0      xlings use gcc 15.1.0  ->  refused,
                       "a member of this release is registered at no such
                        version"; nothing was changed

`[email protected]` carries a pairwise binding edge to `[email protected]`, an
anchor registered only at 16.1.0. The fail-closed resolution added in #384 is
right to refuse an unresolvable release -- what was missing is any way out.
`doctor` did not report it, because its INV-4 pass only inspects entries that
carry a `bindingGroup` and everything written before 0.4.70 does not. `--fix`
could not repair it. The hint said "reinstall the package", which works but
is a heavy answer to a stale edge, and nothing pointed the user at it. For an
upgrade sold as seamless, that is the opposite.

An edge whose destination version does not exist carries no information: it
cannot name a member anyone could switch to, it can only cause a refusal. So
dropping it is repair without guessing, which is exactly what separates it
from the incoherent-release case that `--fix` deliberately will not resolve.

doctor now reports these as `xvm-legacy-edge-dangling` and `--fix` drops
them, before the deactivation pass so that pass does not see this problem
wearing another shape.

Deliberately narrow: an edge recorded under a version that is *also* absent
is left alone. Resolution always starts from a real (target, version), so
such an edge is unreachable and cannot cause the refusal this fixes. On the
same real installation that is 12 of 32 -- inert, and touching them would be
cleanup rather than repair.

Measured on that installation: 20 edges dropped, `use gcc 15.1.0` works
again, and 16.1.0 still resolves as a two-member release rather than
collapsing into standalone entries.

Verified: 6 new cases (XvmDanglingEdge), one of which reproduces the refusal
before anything is repaired so the fix cannot pass vacuously. 458 tests, 11
binaries green.

* docs(release): document the dangling-edge repair path for upgraders

An upgrade from 0.4.68/0.4.69 can hit a `use` that is refused where it
previously worked: legacy pairwise edges may point at versions that are no
longer registered, and fail-closed resolution rejects the whole release.

The notes now say what to run. Without it the user's only visible option was
the reinstall the error hinted at, which is a heavy answer to a stale edge --
and doctor did not surface the finding in the first place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant