@@ -413,10 +413,81 @@ select_glibc_payload_lib(const std::filesystem::path& glibcRoot,
413413 auto payload = glibcRoot / std::string (version);
414414 std::error_code ec;
415415 if (!std::filesystem::is_directory (payload, ec)) {
416- return std::unexpected (std::format (
417- " selected RuntimeBinding {} requires payload '{}', but it is not "
418- " installed; mcpp will not fall back to another directory entry" ,
419- runtimeId, payload.string ()));
416+ // ⭐⭐ THE VERSION THAT WAS ASKED FOR AND THE VERSION THAT WAS
417+ // INSTALLED ARE TWO VOCABULARIES FOR ONE FACT.
418+ //
419+ // A RuntimeBinding carries the DECLARED identity — what the subos state
420+ // says the provider is. xlings names the payload directory after what
421+ // the request RESOLVED to, and the two differ the moment the index
422+ // moves a package within a series: `xim:glibc@2.44` resolving to
423+ // `2.44.2` puts the payload in `xim-x-glibc/2.44.2` while the
424+ // declaration still reads `glibc@2.44`.
425+ //
426+ // ⚠️ Measured 2026-08-27, on every CI machine with a cold cache, on
427+ // `main` as readily as on any branch:
428+ //
429+ // error: selected RuntimeBinding glibc@2.44 requires payload
430+ // '…/xim-x-glibc/2.44', but it is not installed
431+ //
432+ // $ ls …/xim-x-glibc/ → 2.44.2
433+ //
434+ // `runtime_binding.cppm` already names this exact shape one version
435+ // earlier ("observed in CI as runtime=glibc@2.39 with libc.so.6
436+ // resolving to the managed 2.44 payload") and canonicalizes it —
437+ // but only once the SubOS view exists. This runs during the FIRST
438+ // toolchain install, before there is a view to read.
439+ //
440+ // ⭐ A REFINEMENT, NOT A DIRECTORY-ORDER PICK — and that distinction is
441+ // the whole of why the refusal below still stands. `2.44.2` is what the
442+ // request `2.44` resolved to: its version components BEGIN with the
443+ // requested ones. `2.4` does not match `2.44`, because the comparison
444+ // is per component and not per character. And if two payloads both
445+ // refine the request, nothing here chooses between them: the refusal is
446+ // reported exactly as before, because "the resolution of this request"
447+ // has to be one payload to be an answer at all.
448+ auto components = [](std::string_view v) {
449+ std::vector<std::string> parts;
450+ std::size_t start = 0 ;
451+ while (start <= v.size ()) {
452+ auto dot = v.find (' .' , start);
453+ if (dot == std::string_view::npos) {
454+ parts.emplace_back (v.substr (start));
455+ break ;
456+ }
457+ parts.emplace_back (v.substr (start, dot - start));
458+ start = dot + 1 ;
459+ }
460+ return parts;
461+ };
462+ const auto wanted = components (version);
463+
464+ std::vector<std::filesystem::path> refinements;
465+ std::error_code dec;
466+ for (auto it = std::filesystem::directory_iterator (glibcRoot, dec);
467+ !dec && it != std::filesystem::directory_iterator{};
468+ it.increment (dec)) {
469+ if (!it->is_directory (dec)) continue ;
470+ const auto have = components (it->path ().filename ().string ());
471+ if (have.size () <= wanted.size ()) continue ;
472+ if (!std::equal (wanted.begin (), wanted.end (), have.begin ())) continue ;
473+ refinements.push_back (it->path ());
474+ }
475+
476+ if (refinements.size () != 1 ) {
477+ return std::unexpected (std::format (
478+ " selected RuntimeBinding {} requires payload '{}', but it is not "
479+ " installed{}; mcpp will not fall back to another directory entry" ,
480+ runtimeId, payload.string (),
481+ refinements.empty ()
482+ ? std::string{}
483+ : std::format (" and {} installed payloads refine that "
484+ " version, so none of them is its resolution" ,
485+ refinements.size ())));
486+ }
487+ payload = refinements.front ();
488+ mcpp::log::verbose (" toolchain" , std::format (
489+ " RuntimeBinding {} resolved to installed payload '{}'" ,
490+ runtimeId, payload.filename ().string ()));
420491 }
421492 auto lib = payload_lib_dir_with_loader (payload);
422493 if (lib.empty ()) {
0 commit comments