Skip to content

fix(devserver): make the selected solution authoritative - #25613

Merged
13 commits merged into
masterfrom
dev/cdb/devserver-selection-authoritative
Oct 27, 2026
Merged

13 commits merged into
masterfrom
dev/cdb/devserver-selection-authoritative

Conversation

@carldebilly

Copy link
Copy Markdown
Member

GitHub Issue: closes #25524

PR Type:

🐞 Bugfix

What changed? 🚀

The DevServer MCP bridge (dnx uno.devserver --mcp-app) could resolve the right solution and then launch the host with another one. In a repo where a library solution sits within the depth-3 scan and the app solution sits deeper, the host got the library solution: no app registered, and the port was written into the library's .csproj.user. uno_app_select_solution refused any solution outside that scan, file changes (a dotnet restore is enough) re-ran auto-discovery over a selection, and MCP roots could degrade or redirect the session.

A chosen solution is now authoritative; discovery suggests candidates but never restricts the choice:

  • Launch what was resolved: the monitor launches the resolved solution even beyond its rescan, and never falls back to another one in place of an explicit selection that went missing.
  • Select any local solution: uno_app_select_solution accepts the absolute path of any .sln/.slnx on a local drive whose nearest global.json declares the Uno SDK, inside or outside the workspace. Network, device and NT-namespace paths (\\server\share, \\?\, \??\UNC\, ...) are refused before any file-system access; on Windows only drive-rooted paths are accepted.
  • Keep the selection: an explicit selection survives file changes (it is re-resolved, not rediscovered) and MCP roots, until another one is made. While it does not resolve, the session is degraded and uno_health says why (missing file, the nearest global.json without a usable Uno SDK, or no global.json) instead of advising to wait.
  • MCP roots are hints (deprecated by SEP-2577, MCP 2026-07-28): they decide where the DevServer starts when nothing runs yet, never replace an explicit selection or a workspace whose DevServer runs or failed, use the first local root, and ignore roots on a network share.
  • --solution <path> for the MCP bridge: selects the solution at startup, like the tool; consumed by the bridge in every spelling the host reads (--solution x, --solution=x, /solution x, solution=x) instead of being forwarded; an unusable value exits with code 2.
  • uno_app_initialize selects its solutionPath before applying workspaceDirectory as roots (suggestions come from workspaceDirectory), and reports the workspace and solution actually served.

Docs: dev-server.md, using-the-uno-mcps.md, health-diagnostics.md, the devserver skill and the spec appendices.

Agent-visible behavior changes worth noting:

  • uno_app_initialize's workspaceDirectory result field now reports the served workspace instead of echoing the argument; a solutionPath field was added.
  • A bare solution=x argument used to reach the host and override the bridge's solution; it is now validated and consumed.
  • WSL paths (\\wsl.localhost\...) are refused as selections and ignored as roots, like any other UNC path.

Out of scope: add-in discovery from the selected solution (#24311). #24764 (draft) touches the same files; I'll coordinate there.

Validation

  • Unit tests in Uno.UI.DevServer.Cli.Tests (513 passing) and Uno.UI.RemoteControl.DevServer.Tests (MCP subset, 137 passing), run on net10.0 locally.
  • End to end with the built CLI and a real DevServer host (Uno.Sdk 6.7.30) on the reported layout (global.json at the root, a/Lib/Lib.slnx, a/b/c/d/App.slnx): deep start, select-from-root, survives a restore-like write, and --solution all serve App.slnx (7/7 checks; master: 2/7).

PR Checklist ✅

The MCP bridge's monitor rescans the effective workspace directory (the folder of
the nearest Uno global.json) three levels deep on every cycle, and only used the
resolved solution when that rescan listed it. A solution deeper than the scan was
replaced by the first scanned solution in sorted order, and a workspace whose only
solution was deeper never launched (SolutionNotFound). A repository with the app
solution four levels below global.json and a library-only solution higher up got
the host started on the library solution, so no app ever connected.

DetermineSolutionToLaunch now returns the resolved solution whenever it exists on
disk, taking the scanned path when listed to keep its on-disk casing; the sorted
fallback applies only when no existing solution is resolved. The monitor decides
the solution before its no-solution gate, reports a resolved solution the scan
missed in DiscoveredSolutions, and logs a warning when a fallback overrides a
selection or picks among several unselected solutions.

Refs #25524
uno_app_select_solution rejected any solution outside a three-level scan of the
session's workspace, so the agent could not pick a solution deeper than the scan,
outside the directory the bridge started in, or one the scan never listed.
Discovery now helps choose instead of restricting: the candidate scan only feeds
the suggestions uno_health reports. A selection is rejected only when it cannot
work: a relative, invalid, network (UNC) or device path, a file that is not a
.sln or .slnx, a missing file, or a solution whose nearest global.json declares no
Uno SDK, since the DevServer cannot start for it. That last rejection names the
global.json that applies, or says there is none, and asks to select again rather
than restart the bridge.

Network and device paths are refused before any file-system access, here and for
uno_app_initialize's workspaceDirectory: probing one authenticates the user to the
remote server, and accepting it would load code from that share.

The tool descriptions and the WorkspaceAmbiguous remediation say selection is
free, and uno_app_initialize returns a rejected solutionPath, noting that the
workspace itself was applied, instead of discarding it.

Refs #25524
A file change in the workspace (global.json, a solution file, or the
project.assets.json any dotnet restore writes) re-ran auto-discovery on the
directory the session observes and ignored the selection: the session restarted
on whatever discovery picked, or stopped when it found several solutions.

A solution chosen explicitly now stays in place until another one is selected.
WorkspaceResolution gains IsExplicitSolutionSelection, set only when a solution
path is resolved (uno_app_select_solution), not by a directory override such as
--solution-dir. File changes re-resolve that solution: an SDK change in its
global.json restarts the same solution, and a solution that no longer resolves
(deleted, or its global.json lost the Uno SDK) degrades the session while staying
selected, so it starts again once it is back. A selected solution is watched in
its own workspace, or, while it does not resolve, from the folder of its nearest
global.json or nearest existing folder; candidate suggestions keep coming from the
directory the session observed when the solution was selected.

Refs #25524
MCP roots drove the session: roots naming another workspace while one ran
degraded it, and roots arriving after an explicit selection could replace it.
MCP roots are deprecated (SEP-2577, MCP 2026-07-28) and only hint at a
workspace.

WorkspaceTransitionDecisions returns a new Ignore action for roots that would
override an explicitly selected solution (even one that does not resolve right
now), or replace or degrade another workspace whose DevServer runs; the session
logs it and keeps its workspace. Before any DevServer starts (deferred roots
startup, uno_app_initialize), roots still decide where it starts: a resolved
roots workspace now starts instead of leaving the unused startup one in place,
which waited for a connection that never came.

Refs #25524
With MCP roots deprecated, an MCP server configuration needs another way to
name the solution to serve: `--mcp-app --solution <path>` (or
`mcp serve --solution <path>`) selects it explicitly at startup, as
uno_app_select_solution does, and it stays selected across file changes. It wins
over --solution-dir, and it does not wait for roots under --force-roots-fallback
since roots could not change it.

The option was previously forwarded as is to the DevServer host, after the
bridge's own --solution. The bridge now consumes every spelling the host's
command-line configuration reads as that key (--solution=path, /solution, any
casing), refuses it when given more than once, and applies the checks
uno_app_select_solution does, now shared in SolutionPathRules: a local path to an
existing .sln or .slnx. An unusable path exits with code 2.

An explicit selection that does not resolve now keeps its path in the
resolution, so it stays selected, watched and reported until its global.json
declares the Uno SDK.

Refs #25524
A change of the Uno SDK version in the global.json of an explicitly selected
solution restarts the DevServer on that same solution with the new SDK; this
pins it, as the workspace transition matrix of spec 001 states.

Refs #25524
uno_app_select_solution accepts any local .sln/.slnx whose nearest global.json
declares the Uno SDK, candidates are suggestions, an explicit selection (the
tool or --solution) stays in place across file changes and MCP roots, and MCP
roots, now deprecated, only hint where the DevServer starts. The health
diagnostics, the dev-server and MCP articles (which now list
uno_app_select_solution among the always-available tools), the devserver skill,
and the workspace resolution and transition matrices of spec 001 (including the
Ignore and Diagnose actions) say so; spec 002 and the CLI reference list
--solution.

Refs #25524
LocalPathGuard refused roots starting with two separators, which
\??\UNC\server\share bypassed: probing it authenticates the user to that
server. On Windows it now accepts only a drive-rooted path (X:\), so no
UNC, device or NT-namespace prefix gets through.

MCP roots are now guarded too, after normalization to a full path; a
refused or unresolvable root (including one containing NUL) falls
through to the next one. The workspaceDirectory of uno_app_initialize is
checked on its full path, so \repo on the current drive is accepted.
When an explicitly selected solution (uno_app_select_solution,
--solution, or the solutionPath of uno_app_initialize) no longer exists,
the monitor fell back to the first scanned solution, serving one the
user did not choose. It now launches nothing and reports the solution
missing until it exists again or another is selected; the warning is
logged once until then, not every rescan. Auto-discovered selections keep
the sorted fallback.
uno_app_initialize applied workspaceDirectory as the MCP roots before
selecting its optional solutionPath, so the roots could start another
solution first, and a rejected selection claimed the workspaceDirectory
was being served even when the roots were ignored.

The solution is now selected first, with candidate solutions suggested
from workspaceDirectory; the roots applied next are ignored once a
selection is explicit. The answer reports the workspace and solution
actually served (no workspace while an explicit selection does not
resolve), and a rejection points to uno_health instead of guessing.
uno_app_select_solution, the --solution warning and uno_health each
explained a selection that does not resolve differently, and health gave
none at all: it said to wait for a host that would not come. One issue
now names the cause (missing file, the nearest global.json without a
usable Uno SDK, or no global.json), keeps the WorkspaceNotResolved code,
and says whether fixing it is enough (a kept selection) or the solution
must be selected again (a rejected one).

uno_health raises it for an explicit selection that does not resolve or
whose file the monitor no longer finds, instead of the wait advice; the
monitor's flag is reset between runs so it cannot outlive its selection.
The DevServer host reads its configuration from the command line, where
a bare solution=path sets the same key as --solution. Forwarded by the
MCP bridge after its own --solution, it replaced the bridge's choice
without its checks; the bridge now consumes it like the other spellings.
A bare "solution" with no value stays a positional argument.

The docs state the limits of a selection: --solution must be a usable
local solution (exit code 2 otherwise), and MCP roots never replace an
explicit selection or a workspace whose DevServer runs or failed, use
the first local root, and ignore roots on a network share.
No behavior change. Tests call ProxyLifecycleManager's
GetWorkspaceObservationRoot and EnsureDevServerStartedFromSolutionDirectory
(now internal) instead of reflecting on them, and one more test reuses
the deep-layout and session helpers. ResolveSolutionAsync builds its
unresolved result in one place, SelectSolutionAsync's path rejections
share RejectPath, and IsSolutionFile reads the extension once.
@nventive-devops

Copy link
Copy Markdown
Contributor

The build 240541 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 174

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Buttons.png-dark
    • Buttons.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • DropDownButtonPage.png-dark
    • Examples.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • DynamicFont.png-dark
    • DynamicFont.png
    • ImageBrushInList.png-dark
  • skia-windows-screenshots: 174 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • Buttons.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • ImageBrush_Formats.png-dark
    • ImageBrush_Formats.png
    • Focus_FocusVisual_Properties.png-dark

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 240542 has failed on Uno.UI - docs.

var observationRoot =
suggestionsRoot
?? (GetSelectedSolution(_workspaceResolution) is not null
? _workspaceResolution?.RequestedWorkingDirectory
nextResolution.ResolutionKind,
_workspaceResolution?.EffectiveWorkspaceDirectory ?? _workspaceResolution?.SelectedSolutionPath);
LogTimeline("transition.complete", transitionStopwatch.ElapsedMilliseconds,
$"trigger={trigger};action={transitionAction};workspace={_workspaceResolution?.EffectiveWorkspaceDirectory}");
trigger,
nextResolution.EffectiveWorkspaceDirectory ?? nextResolution.RequestedWorkingDirectory,
nextResolution.ResolutionKind,
_workspaceResolution?.EffectiveWorkspaceDirectory ?? _workspaceResolution?.SelectedSolutionPath);
trigger,
nextResolution.EffectiveWorkspaceDirectory ?? nextResolution.RequestedWorkingDirectory,
nextResolution.ResolutionKind,
_workspaceResolution?.EffectiveWorkspaceDirectory ?? _workspaceResolution?.SelectedSolutionPath);

return string.IsNullOrWhiteSpace(_currentDirectory)
? null
: Path.GetFullPath(Path.Combine(_currentDirectory, rootUri));
{
var solutionPath = CreateSolutionFile(baseDirectory, "a", "App.slnx");

var result = CliManager.ParseMcpSolutionArgument(["--port", "0", "--solution", Path.Combine("a", "App.slnx")], baseDirectory);

try
{
var path = Path.Combine(baseDirectory, fileName);
var resolver = new ThrowingWorkspaceResolver();
var cliManager = CreateCliManager(resolver);

var exitCode = await cliManager.RunAsync(["mcp", "serve", "--solution", Path.Combine(Path.GetTempPath(), $"missing-{Guid.NewGuid():N}.slnx")]);

private static string CreateSolutionFile(string directory, params string[] segments)
{
var path = Path.Combine([directory, .. segments]);
try
{
var shallowSolution = CreateFile(root, "a", "Lib", "Lib.slnx");
var missingSolution = Path.Combine(root, "a", "b", "c", "d", "App.slnx");
@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 240541 has failed on Uno.UI - CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DevServer MCP launches another solution than the one selected (monitor rescan, candidate check, workspace watcher)

4 participants